简体   繁体   English

使用h5py在HDF5中部分写入数组

[英]partially write array in HDF5 with h5py

What I want to do is save thousands set of images. 我要做的是保存成千上万张图像。

Each image set has variable number of images. 每个图像集具有可变数量的图像。 I've seen that hdf5 format doesn't allocate disk until actual data is written. 我已经看到,在写入实际数据之前,hdf5格式不会分配磁盘。

I decided to write ( number of set, maximum set size, imgX,imgY ) shape array. 我决定编写( 集合数,最大集合大小,imgX,imgY )形状数组。

This array is really huge. 这个数组真的很大。 If I write every cell in the array, therefore, I can't write array at once. 因此,如果我写数组中的每个单元格,就无法一次写数组。 So, I made code to write each image at a time. 因此,我编写了代码来一次写入每个图像。 But, it seems like that writing one at a time, doesn't write anyting at all. 但是,一次写一个似乎根本不写任何内容。

Belows are my code and their output. 以下是我的代码及其输出。 It shows me that I write actual image, but once I read from hdf5 , it gives blank image. 它向我显示了我写的实际图像,但是一旦我从hdf5读取,它就会显示空白图像。

with h5py.File("D:\\data_icon\\flaticon\\test.hdf5",'w') as hf:
    flt = hf.create_dataset("flaticon", (2,500,128,128))
    for idx, icon_image in enumerate(pack_image_list[0][:5]):
        flt[0][idx]=icon_image
        plt.subplot(1,10,idx+1)
        plt.imshow(icon_image, cmap=plt.get_cmap('gray'))
        plt.axis('off')
    plt.show()

    for idx, icon_image in enumerate(pack_image_list[0][5:15]):
        flt[0][idx]=icon_image
        plt.subplot(1,10,idx+1)
        plt.imshow(icon_image, cmap=plt.get_cmap('gray'))
        plt.axis('off')
    plt.show()

    for i in range(1,11):
        plt.subplot(1,10,i)
        plt.imshow(flt[0][i], cmap=plt.get_cmap('gray'))
        plt.axis('off')
    plt.show()

output 输出 在此处输入图片说明

First, what is the reason for not writing separate datasets in groups? 首先,不按组编写单独的数据集的原因是什么? One of the strengths of HDF5 is the ability to store many arrays in a structure of named groups and datasets in a single file. HDF5的优势之一是能够在单个文件中以命名组和数据集的结构存储许多阵列。

Second, what exactly is the data in pack_image_list ? 其次, pack_image_list的数据到底是什么?

If you want further help, provide a copy of your input data :-) 如果您需要进一步的帮助,请提供输入数据的副本:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM