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

3 views (last 30 days)
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));

Answers (1)

Sourabh Kondapaka
Sourabh Kondapaka on 17 Nov 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 Comment
Alexander Berardino
Alexander Berardino on 17 Nov 2020
Edited: Alexander Berardino on 17 Nov 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.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!