Error while running importKerasNetwork
6 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a Matlab script (version 2020b) in which I import a neural network from Python using the next command:
importKerasNetwork(modelName)
Before the script was working well. After reinstalling my Matlab (same version, 2020b), I get the following error:
SWITCH expression must be a scalar or a character vector.
Error in nnet.internal.cnn.keras.LayerSpec>DAGOutputLayer (line 166)
switch Loss
Error in nnet.internal.cnn.keras.LayerSpec/maybeAppendOutputLayer (line 148)
NNTLayers{end+1} = DAGOutputLayer(OutputTensors{pos}, TrainingConfig, isRNN);
Error in nnet.internal.cnn.keras.LayerSpec/translateDAGLayer (line 64)
NNTLayers = maybeAppendOutputLayer(this, NNTLayers, OutputTensors, TrainingConfig, isRNN);
Error in
nnet.internal.cnn.keras.AssembledModel>@(LSpec)translateDAGLayer(LSpec,AM.OutputTensors,AM.TrainingConfig,TranslateWeights,TranslateTrainingParams,UserImageInputSize,isRNN(AM))
(line 226)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, AM.OutputTensors, AM.TrainingConfig, TranslateWeights,...
Error in nnet.internal.cnn.keras.AssembledModel/translateDAGModel (line 226)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, AM.OutputTensors, AM.TrainingConfig, TranslateWeights,...
Error in nnet.internal.cnn.keras.AssembledModel/translateAssembledModel (line 57)
Layers = translateDAGModel(this, TranslateWeights, TranslateTrainingParams, UserImageInputSize);
Error in nnet.internal.cnn.keras.importKerasNetwork (line 30)
LayersOrGraph = translateAssembledModel(AM, TrainingConfig, ImportWeights, TrainOptionsRequested, UserImageInputSize);
Error in importKerasNetwork (line 91)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
The error is given in a line of a scrpit that I haven't programmed. Could anyone help me?
Thank you!
0 件のコメント
回答 (1 件)
David Willingham
2021 年 11 月 5 日
Hi,
This has been observed before. I don't believe it's due to reinstalling MATLAB.
Please check if the following work around will work:
==
If one provides the loss value using a Python list (shown below), this issue will occur:
model.compile(loss=['categorical_crossentropy'],
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
Although Keras accepts a list for the loss input, this type is not mentioned as one of the accepted type in Keras documentation https://keras.io/losses/.
If the loss is specified this way the problem should go away:
model.compile(loss='mean_squared_error')
==
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!