MATLAB Answers

Reading H5 Groups and Attributes

조회 수: 28(최근 30일)
Karl Haebler
Karl Haebler 22 Oct 2019
Someone has ostensibly provided me with an h5 file (generated in python) that contains the weights of a neural network. These I need to open in matlab.
However, when I used the h5info and h5disp functions in MATLAB, the datasets part of the h5 file info is empty. However, there seems to be dataset information within the group category of the file, as you can see below.
How should I properly be accessing the weights with this h5 file?
Using data = hdf5read(filename,datasetname) seems to not work for no matter what I provide as the datasetname. I cannot provide the .h5 file since it is an unsupported file type with this forum.
Thank you very much
hinfo =
Filename: '/home/sem19h2/Documents/Karl/Semester_Thesis/Scripts/New_matlab_model/matlab_karl_v2/_weights.h5'
Name: '/'
Groups: [3x1 struct]
Datasets: []
Datatypes: []
Links: []
Attributes: [3x1 struct]
HDF5 _weights.h5
Group '/'
Attributes:
'layer_names': 'lstm_55 ', 'dense_29', 'lstm_56 '
'backend': 'tensorflow'
'keras_version': '2.2.4'
Group '/dense_29'
Attributes:
'weight_names': 'dense_29/kernel:0', 'dense_29/bias:0 '
Group '/dense_29/dense_29'
Dataset 'bias:0'
Size: 70
MaxSize: 70
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Dataset 'kernel:0'
Size: 70x70
MaxSize: 70x70
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Group '/lstm_55'
Attributes:
'weight_names': 'lstm_55/kernel:0 ', 'lstm_55/recurrent_kernel:0', 'lstm_55/bias:0 '
Group '/lstm_55/lstm_55'
Dataset 'bias:0'
Size: 280
MaxSize: 280
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Dataset 'kernel:0'
Size: 280x10
MaxSize: 280x10
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Dataset 'recurrent_kernel:0'
Size: 280x70
MaxSize: 280x70
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Group '/lstm_56'
Attributes:
'weight_names': 'lstm_56/kernel:0 ', 'lstm_56/recurrent_kernel:0', 'lstm_56/bias:0 '
Group '/lstm_56/lstm_56'
Dataset 'bias:0'
Size: 16
MaxSize: 16
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Dataset 'kernel:0'
Size: 16x70
MaxSize: 16x70
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
Dataset 'recurrent_kernel:0'
Size: 16x4
MaxSize: 16x4
Datatype: H5T_IEEE_F32LE (single)
ChunkSize: []
Filters: none
FillValue: 0.000000
  댓글 수: 4
Said Murtaza Jallali
hey i have the same problem, have you solved it yet???

댓글을 달려면 로그인하십시오.

답변(1개)

Sivylla Paraskevopoulou
You might find useful the following two examples on how to import weights from a separate file.
1. Import Keras Network and Weights

범주

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by