How to call a second key in a dictionary using HDF5Matrix?

0

I'm trying to load a .h5 file using this documentation HDF5Matrix :

test_images = HDF5Matrix(train_path+train_file,'images')

But I'm getting this error:

  

KeyError: "Unable to open object (object 'images' does not exist)"

I know you need to use this syntax to call a second key in a ['train'] ['images'] dictionary.

I usually use this statement to open files .h5 :

with h5py.File(train_path+train_file, 'r') as hf:
      train_images = hf['train']['images'][:]

My question is: Is it possible to access the second key to use the HDF5Matrix syntax?

Thank you!

    
asked by anonymous 13.04.2018 / 16:32

1 answer

0

I finally got it!

It's very easy, files of type h5 have this structure:

file
  Group
    Dataset

So if we want to access Dataset using HDF5Matrix('path/file','dataset') . We just have to call Group first. This will look like this:

from keras.utils import HDF5Matrix

x_data = HDF5Matrix('path/file', 'group/dataset')
    
20.04.2018 / 20:39