Keras TensorFlow importer: can't upload weights from .h5 file using importKerasNetwork.
Show older comments
Hi, I have a .h5 file with a Keras TensorFlow model that was built using Sequential API. The model is carrying weights, and though Layers are being succesfully uploaded through importKerasNetwork() function, I can't seem to upload the weights with it.
What could I be doing wrong? Is there a way to debug this issue?
I tried this:
test_1=importKerasNetwork('myFile.h5')
And
test_2=importKerasNetwork('myFile.h5', 'WeightFile', 'myFile.h5')
No success whatsover.
Would it be recommendable to have the layers in an JSON file and the weights in a .h5 file?
Thanks in advance for all the help.
5 Comments
Don Mathis
on 8 Feb 2019
What you're doing should work if the file has weights in it. If you post the file here I can investigate.
Ajpaezm
on 8 Feb 2019
darci taylor
on 25 Feb 2019
Don, I am having the same problem - I can't import my weights. If I use use importKerasNetwork, I get:
"Error using importKerasNetwork (line 93) Unable to import network because some network layers are not yet supported. To import layers and weights, call importKerasLayers with 'ImportWeights' set to true."
If I use "importKerasLayers(modelfile, 'ImportWeights', true)", I am able to see some of my layers, however there are a fair deal of layers that are "placeholder" layers, and I am not able to see the weghts at all. I get the message:
"Warning: Keras network takes vector inputs. Pass images with height=1 and channels=1. Warning: Loss function 'binary_crossentropy' is not yet supported. Warning: Unable to import some Keras layers, because they are not yet supported by the Deep Learning Toolbox. They have been replaced by placeholder layers. To find these layers, call the function findPlaceholderLayers on the returned object. "
Are the weights not importing because it's unable to identify the layers? (I have 12 layers, 8 of them have been returned as placeholders since Matlab doesn't suport 1dCNN , max, or average pooling...)
Don Mathis
on 26 Feb 2019
Darci, if you're using R2018b, you can download the latest version of the keras importer. There was an update in the last month or so. 'binary_crossentropy' is supported now. The placeholder layers should contain the weights, inside the KerasConfiguration field. Unfortunately, Conv1D is not yet supported by the importer.
José Luis Sandoval
on 24 May 2020
I have a similar problem:
>> detetor
Warning: File 'resnet50_pascal_cards_inference.h5' was saved in Keras version '2.3.1'. Import of Keras versions newer than
'2.2.4' is not yet supported. The imported model may not exactly match the model saved in the Keras file.
Error using importKerasNetwork (line 94)
Unable to import network. Weight sharing is not yet supported.
Error in detetor (line 65)
net = importKerasNetwork(modelfile,'OutputLayerType','classification','ClassNames',classNames);
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!