Is there any way to make importKerasNetwork support CRelu function?

1 view (last 30 days)
Hi I have trained a network in keras and I am trying to use importKerasNetwork function in matlab... but matlab gives me an error like this:
Warning: File 'drowiness-CReLU150.h5' was saved in Keras version '2.7.0'. 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.
Error using horzcat
The following error occurred converting from char to struct:
Conversion to struct from char is not possible.
Error in nnet.internal.cnn.keras.LayerSpec/maybeAppendActivationLayer (line 83)
LayerCell{1}.Name = [LayerCell{1}.Name '_' kerasField(this, 'activation')];
Error in nnet.internal.cnn.keras.TranslatorForConv2DLayer/translate (line 72)
NNTLayers = maybeAppendActivationLayer(LSpec, NNTLayers);
Error in nnet.internal.cnn.keras.LayerSpec/translateLayer (line 61)
NNTLayers = translate(this.Translator, this, TranslateWeights, TranslateTrainingParams,
UserImageInputSize);
Error in nnet.internal.cnn.keras.LayerSpec/translateDAGLayer (line 72)
NNTLayers = translateLayer(this, TranslateWeights, TranslateTrainingParams, UserImageInputSize);
Error in
nnet.internal.cnn.keras.AssembledModel>@(LSpec)translateDAGLayer(LSpec,this.OutputTensors,TrainingConfig,TranslateWeights,TranslateTrainingParams,UserImageInputSize,isRNN(this))
(line 147)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, this.OutputTensors, TrainingConfig,
TranslateWeights,...
Error in nnet.internal.cnn.keras.AssembledModel/translateSequentialModel (line 147)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, this.OutputTensors, TrainingConfig,
TranslateWeights,...
Error in nnet.internal.cnn.keras.AssembledModel/translateAssembledModel (line 58)
Layers = translateSequentialModel(this, TrainingConfig, TranslateWeights,
TranslateTrainingParams, UserImageInputSize);
Error in nnet.internal.cnn.keras.importKerasNetwork (line 30)
LayersOrGraph = translateAssembledModel(AM, TrainingConfig, ImportWeights, TrainOptionsRequested,
UserImageInputSize);
Error in importKerasNetwork (line 76)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
My keras network has CRelu as activation (Concatination Relu) so my guess is matlab does not support this function (since I couldnt find this function in deep network designer app as well)... However is there any way to fix this problem? like defining this layer in matlab or ...? Can anyone help?

Answers (1)

Sivylla Paraskevopoulou
Sivylla Paraskevopoulou on 9 May 2022
Edited: Sivylla Paraskevopoulou on 11 May 2022
This example shows how to replace an unsupported activation with a functionLayer: Replace Unsupported Keras Layer with Function Layer.
Also it is recommended to use the importTensorFlowNetwork and importTensorFlowLayers functions instead of importKerasNetwork and importKerasLayers.

Community Treasure Hunt

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

Start Hunting!