MATLAB Answers

Error using importKerasLayers() for Squeezenet using ".json" file.

4 views (last 30 days)
I am trying to use the new Neural Network Toolbox function named "importKerasLayers" to import Squeezenet model. But it gives me below error:
*Error using importKerasLayers
Invalid layer name 'fire2/squeeze1x1'. Layer names must not contain the character '/'.*
Please, let me know about it.
I have also tried importing ".h5" file for Squeezenet. But it gives me below error:
*Error using importKerasLayers
Unable to import layers from file 'squeezenet_weights.h5' because it contains no 'model_config' attribute.*
Can you provide a ".json" or ".h5" file for Squeezenet which supports MATLAB.
Looking forward to solve this problem as soon as possible.
Thank you.


Sign in to comment.

Accepted Answer

Mickaël Tits
Mickaël Tits on 14 Nov 2017
I had the same problem, so I modified a python script to change layer names (tu use "_" instead of "/"). You can find the corrected model here : You can use this line of code to import it :
squeezenet = importKerasNetwork('squeezenet.json','WeightFile','squeezenet.h5','OutputLayerType','classification');
Best regards, Mickaël Tits


Hello Mickaël,
Thank you for your help.
It is working for me.
I was wondering if you could provide me exact model representation of Squeezenet in Keras as it is in original Squeezenet in Caffe.
The first convolution is above link has dimension 3x3x64 but original implementation has 7x7x96.
Every help will be appreciated.
Thank you.
Mickaël Tits
Mickaël Tits on 19 Nov 2017
It is actually the version v1.1, which apparently has similar results than v1.0, with much less computations:
I don't have the v1.0 version unfortunately. If you really need the version 1.0, you can try to modify the python script and use the weights of the v1.0.
Regards, Mickaël Tits
Marco Francini
Marco Francini on 30 Nov 2017
Hello, it is working also for me.
Now that I uploaded the Squeezenet to Matlab I used it with transfer learning techninque so it can handle just 3 classes. It is working fine.
Now that I have my network trained, how can I export it to .h5 and .json file? I see that an "exportKerasNetwork" function does not exists...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by