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

4 ビュー (過去 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 Center および File ExchangeSequence 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