How do I solve the "Referene to non-existent field" error when importing a Tensorflow model?

1 view (last 30 days)
Hello everyone,
this is my first question on this forum.
I worked for a while in python (Tensorflow) on a simple classification network from my research (I'm a PhD student) and now I'd like to import it in Matlab (I need it in both the frameworks). I did some research and I found the
importKerasNetwork
importKerasLayers
functions in the Deep Learning Toolbox which should solve my problem. Sadly, I was using Keras 2.3.0 in my model (Tensorflow 2.2.0) and I kept getting this warning:
Warning: File '2020_06_19_11_49_10.h5' was saved in Keras version '2.3.0-tf'. Import of Keras versions newer than
'2.2.4' is not supported. The imported model may not exactly match the model saved in the Keras file.
together with the following error:
Reference to non-existent field 'dense_2'.
The first question is: can I do something to still use this model in Matlab?
I decided to go back to Keras 2.2.4 (with Tensorflow 2.1.0) and to re-train my network. Before doing this I decided to try and convert a simple non-trained network (some conv2d, max pooling, dense) but I still got the same error (not the warning, of course):
Reference to non-existent field 'dense_1'.
What am I doing wrong?
Thank in advance for the help,
Diego
UPDATE
This is not only a problem of the dense layer, it also happens when I remove the dense layers from my model, the error simply goes to another kind of layer.

Answers (1)

Sivylla Paraskevopoulou
Sivylla Paraskevopoulou on 27 Apr 2022
Edited: Sivylla Paraskevopoulou on 27 Apr 2022
You can try to use the importTensorFlowNetwork function, which was introduced in R2021a. importTensorFlowNetwork supports newer TensorFlow versions, imports TensorFlow models in savedModel format, and tries to generate a custom layer when the software cannot convert a TensorFlow layer into an equivalent built-in MATLAB layer.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!