Skip to content
Advertisement

Reading files with .h5 format and using it in dataset

I have two folders( one for train and one for test) and each one has around 10 files in h5 format. I want to read them and use them in a dataset. I have a function to read them, but I don’t know how I can use it to read the file in my class.

JavaScript

Do you have a suggestion? Thank you in advance

Advertisement

Answer

This might be a start for what you want to do. I implemented the __init__(), but not __len__() or __get_item__(). User provides the path, and the init function calls the class method read_h5() to get the arrays of image and label data. There is a short main to create a class objects from 2 different H5 files. Modify the paths list with folder and filenames for all of your training and testing data.

JavaScript

IMHO, creating a class with the array data is overkill (and could lead to memory problems if you have really large datasets). It is more memory efficient to create h5py dataset objects, and access the data when you need it. Example below does the same as code above, without creating a class object with numpy arrays.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement