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

1 回表示 (過去 30 日間)
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));

回答 (1 件)

Sourabh Kondapaka
Sourabh Kondapaka 2020 年 11 月 17 日
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 件のコメント
Alexander Berardino
Alexander Berardino 2020 年 11 月 17 日
編集済み: Alexander Berardino 2020 年 11 月 17 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by