简体   繁体   中英

How to convert a folder of images to h5 file?

How do you convert a folder of images into h5 file? or is there a different type of file format for inputting the dataset to the CNN model?

Thank you in advance.

You could store each file (ie image) as an HDF5 dataset of datatype opaque . 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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