【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'])  # 创建以h5中rgb这一group数据为内容的numpy类型array矩阵;
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

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
社会演员多的头像社会演员多普通用户
上一篇 2022年5月21日
下一篇 2022年5月21日

相关推荐