简体   繁体   English

如何将图像文件夹转换为h5文件?

[英]How to convert a folder of images to h5 file?

How do you convert a folder of images into h5 file?如何将图像文件夹转换为 h5 文件? or is there a different type of file format for inputting the dataset to the CNN model?或者是否有不同类型的文件格式用于将数据集输入到 CNN 模型?

Thank you in advance.先感谢您。

You could store each file (ie image) as an HDF5 dataset of datatype opaque .您可以将每个文件(即图像)存储为数据类型为opaque的 HDF5 数据集。 Additionally, for each dataset you could associate one or more attributes to describe the file (eg creation timestamp).此外,对于每个数据集,您可以关联一个或多个属性来描述文件(例如创建时间戳)。

Using HDFql in Python, this could be implemented as follows:在 Python 中使用HDFql ,这可以实现如下:

import HDFql

HDFql.execute("CREATE FILE images.h5") # create HDF5 file named 'images.h5'

HDFql.execute("USE FILE images.h5") # use (i.e. open) HDF5 file 'images.h5'

HDFql.execute("SHOW FILE my_directory/") # get files (i.e. images) stored in directory 'my_directory' and populate cursor with result

my_cursor = HDFql.Cursor()

i = 1
while HDFql.cursor_next() == HDFql.SUCCESS: # loop through cursor

   file_name = HDFql.cursor_get_char()

   HDFql.cursor_use(my_cursor)

   HDFql.execute("SHOW FILE SIZE my_directory/%s" % file_name)

   file_size = HDFql.cursor_get_bigint()

   HDFql.cursor_use_default()

   dataset_name = "dataset_%04d" % i

   HDFql.execute("CREATE DATASET %s AS OPAQUE(%d) VALUES FROM BINARY FILE %s" % (dataset_name, file_size, file_name)) # create HDF5 dataset and write data from file into it

   i = i + 1

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

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