When I try to load a keras model using importKerasNetwork I get the following error (R2020A)

2 visualizaciones (últimos 30 días)
When I try to load a keras model using importKerasNetwork I get the following error (this is in R2020A).
Brace indexing is not supported for variables of this type.
Error in nnet.internal.cnn.keras.readModelAndTrainingConfigs>iVerifyKerasBackend
(line 71)
if ~isequal(BackendCell{1}, 'tensorflow')
Error in nnet.internal.cnn.keras.readModelAndTrainingConfigs (line 8)
iVerifyKerasBackend(ConfigFile);
Error in nnet.internal.cnn.keras.importKerasNetwork (line 21)
[ModelConfig, TrainingConfig, KerasVersion] =
nnet.internal.cnn.keras.readModelAndTrainingConfigs(ConfigFile, Format);
Error in importKerasNetwork (line 91)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
Error in LoadingEyetoneIntoMatlab (line 4)
net=importKerasNetwork(sprintf('%s%s', modelpath,networkname));

Respuestas (1)

Sourabh Kondapaka
Sourabh Kondapaka el 17 de Nov. de 2020
In the below line:
net=importKerasNetwork(sprintf('%s%s', modelpath,networkname));
Between the '%s' and '%s' , you'll need to add a '/' .
Although this is not an ideal approach, you can do something like this:
modelPath = fileparts(which(modelName));
net = importKerasnetwork([modelPath filesep modelName '.h5']); %Assuming your model has .h5 extension
To learn more about the functions used above, refer the following links:
  1 comentario
Alexander Berardino
Alexander Berardino el 17 de Nov. de 2020
Editada: Alexander Berardino el 17 de Nov. de 2020
Hi Sourabh,
Thanks for your response. The error is not actually in the file path (the pathname variables in the error I copied above have '/' in the correct place.)
I tried your version, and I get the same error. It appears there is an error in nnet.internal.cnn.keras.readModelAndTrainingConfigs>iVerifyKerasBackend here if ~isequal(BackendCell{1}, 'tensorflow'), but when inspecting BackendCell, it appears that BackendCell is not a cell array, but rather a character array that says 'tensorflow'.
It seems as though there is a mismatch between the way that character array is being loaded in and what the matlab function is expecting.

Iniciar sesión para comentar.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by