Missing layers in Deep Learning Toolboox results in failing to run EfficientNetV2S
古いコメントを表示
I saved EfficientNetV2S in Python as follows
import tensorflow as tf
model = tf.keras.applications.efficientnet_v2.EfficientNetV2S(
include_top =True,
weights =None,
input_tensor=None,
input_shape =None,
pooling =None,
classes =2,
classifier_activation='softmax',
include_preprocessing=True
)
model.save('EfficientNetV2S')
model.save('EfficientNetV2S_.h5')
Then I also converted the created above folder EfficientNetV2S to ONNX format as follows
python -m tf2onnx.convert --saved-model ./EfficientNetV2S --output EfficientNetV2S.onnx
Now I have three ways to import this model to Matlab
First:
net = importTensorFlowNetwork('EfficientNetV2S');
Warning: The SavedModel 'EfficientNetV2S' was saved in TensorFlow version '2.8.0'. Import of SavedModel versions newer than '2.6.0' is not supported. The imported model may not
exactly match the model saved in the SavedModel.
Error using nnet.internal.cnn.tensorflow.savedmodel.TFSavedModel (line 35)
'OutputLayerType' is missing. Please specify an output layer type or set the 'TargetNetwork' to be 'dlnetwork'.
Error in nnet.internal.cnn.tensorflow.importTensorFlowNetwork (line 20)
sm = savedmodel.TFSavedModel(path, options, true);
Error in importTensorFlowNetwork (line 107)
Network = nnet.internal.cnn.tensorflow.importTensorFlowNetwork(modelFolder, varargin{:});
"'OutputLayerType' is missing" not sure what I should do about this.
Second:
net = importKerasNetwork('EfficientNetV2S_.h5');
Warning: File 'EfficientNetV2S_.h5' was saved in Keras version '2.8.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 nnet.internal.cnn.keras.importKerasNetwork (line 21)
Keras network does not include loss information specifying the output layer type. Specify the type using the 'OutputLayerType' argument.
Error in importKerasNetwork (line 76)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
"Keras network does not include loss information specifying the output layer type. Specify the type using the 'OutputLayerType' argument." will it help? How should I do that?
Thrid:
net = importONNXNetwork('EfficientNetV2S.onnx')
This one doesn't generate the errors! But, then I attempt training the model, it returns NaNs. Based on the deepNetworkDesigner, I believe this is caused by the missing layers:
- ElementWiseAffineLayer
- IdentityLayer
- FlattenInto2DLayer
- ReshapeLayer
Am I doing something wrong? Any suggestions are welcome.
---------------------------------------------------------------------------------
UPDATE
---------------------------------------------------------------------------------
I've tried computing each layer separately one by one. The model fails on
activations(trainedNet,imgs,'StatefulPartiti_1327')
that returns NaN. I believe this due to missing implementation of nnet.onnx.layer.IdentityLayer
The list of the first layers is as follows
573×1 Layer array with layers:
1 'input_1' Image Input 384×384×3 images
2 'StatefulPartiti_1324' Elementwise Affine Applies an elementwise scaling followed by an addition to the input.
3 'StatefulPartiti_1323' Elementwise Affine Applies an elementwise scaling followed by an addition to the input.
4 'StatefulPartiti_1328' nnet.onnx.layer.IdentityLayer nnet.onnx.layer.IdentityLayer
5 'StatefulPartiti_1327' Convolution 24 3×3×3 convolutions with stride [2 2] and padding [0 1 0 1]
...
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!