【h5文件读取】h5文件读取——深度学习数据集常用

数据集的常用格式:h5

  • 深度学习搞了很长时间,其中开源的代码中经常用到大型数据集,里面的数据类型是h5格式,这个格式困扰我挺长时间,因为隔离还拿不到实验室的程序,只好硬着头皮再琢磨一遍。

关于h5文件的基本信息

  • h5这个格式可以把不同模态的数据类型,打包放在一起(有点像压缩),方便传递、下载,可能也方便读取吧,具体它的结构参见其他博客吧,我表述不清楚,其实也没有深入追究,没有必要,只要拿到了里面的内容就可以了;
  • 这个博客写的还行,想知道具体是干嘛的,或者追究h5 的数据结构,可以看看:

https://blog.csdn.net/YYY_77/article/details/118269666

实例

  • 我用的数据集KITTI和NYUDepthV2是两个模态的数据打包在一起的,具体来说:一个深度图,一个RGB图。
  • 最终的代码是这样的:
import h5py
import numpy as np

fileName = '00017.h5'
filePath = 'D:\\01-Python_In_One\\PycharmProjects\\mycode\\h5\\'
h5f = h5py.File(filePath + fileName, 'r')

print([key for key in h5f.keys()])

rgb = np.array(h5f['rgb'])
rgb = np.transpose(rgb, (1, 2, 0))
print('np.array type:', type(rgb))
print('np.array dtype:', rgb.dtype)
rgb = np.asfarray(rgb)
print('np.asfarray type:', type(rgb))
print('np.asfarray dtype:', rgb.dtype)

其他参考内容

https://guotong1988.blog.csdn.net/article/details/54093301?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-1-54093301-blog-103499388.pc_relevant_paycolumn_v3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-1-54093301-blog-103499388.pc_relevant_paycolumn_v3&utm_relevant_index=2
https://stackoverflow.com/questions/41627147/how-can-i-visualise-an-image-in-h5-format-data?answertab=scoredesc#tab-top
https://blog.csdn.net/rootkiss/article/details/103499388

Original: https://blog.csdn.net/weixin_42306148/article/details/124860788
Author: nemo_0410
Title: 【h5文件读取】h5文件读取——深度学习数据集常用

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/717233/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球