importKerasNetwork does not work: provide support for importing keras (with tensorflow backend) models with custom layers / custom activation functions

조회 수: 2 (최근 30일)
I have a trained prediction model in keras (with tensorflow backend) using custom layers on Ubuntu 18.04 LTS,
and want to import this model in MATLAB using importKerasNetwork for further prediction (On Windows 10).
So, this is a cross-platform requirement.
when tried to import in MATLAB R2018a (also tried in later versions as well).
model = importKerasNetwork('model_file.h5'); % model_file.h5 is the model saved in keras (with tensorflow backend) using 'save' method
Error using importKerasNetwork (line 86)
Unable to import network because some network layers are not yet supported. To import layers and weights, call importKerasLayers with 'ImportWeights' set to true.
So, tried:
layers = importKerasLayers('model_file.h5', 'ImportWeights' , true);
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.
> In nnet.internal.cnn.keras.importKerasLayers (line 29)
In importKerasLayers (line 102)
In test_import_keras_model (line 4)
I cannot replace or remove my custom layers, because prediction will not be correct.
I also tried using assembleNetwork but it did'nt work.
Another, last option that I see is trying to train the prediction model using a custom activation function (required for my implementation).
Before, trying this, important question is whether there is any support in MATLAB to import keras models
with custom activation functions?
I request Mathworks, to kindly expedite the process of providing support for importing keras (tensorflow) models with:
A) Custom Layers and/or
B) Custom activation functions
Thank you.

답변 (1개)

David Willingham
David Willingham 2021년 10월 7일
@Sandy Kumar, R2018a is too earlier of a version to try importing. Do you have access to the latest version R2021b or R2021a? In it we had upgraded support, with a generic tensorflow importer over just a keras specific one:
David
  댓글 수: 3
David Willingham
David Willingham 2021년 10월 13일
Hi Sandy, I'd recommend upgrading to the latest release. If you could email me your files, I can test if they will work. My email is dwilling@mathworks.com
Sandy Kumar
Sandy Kumar 2021년 10월 19일
Dear David, I've mailed you the model file, please let me know whether you are able to import the model successfully. More details are in the mail. Please reply. Thank you.

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

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by