Error while running importKerasNetwork
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
David Willingham
am 5 Nov. 2021
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')
==
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!