Using importTensorFlowNetwork does not load the model correctly

조회 수: 9 (최근 30일)
琛龙 汪
琛龙 汪 2022년 5월 29일
편집: 琛龙 汪 2022년 6월 2일
I need to import the trained model for presentation in matlab APP,My tensorflow version is 2.3.1.Models are stored via saved_model
My code and error are as follows.
modelFolder='.\G_epoch40';
net = importTensorFlowNetwork(modelFolder,'OutputLayerType','regression')
Importing the saved model...
The function or variable 'Timesteps' is not recognized.
ERROR nnet.internal.cnn.keras.TranslatorForDAGInputLayer/translate (第 102 行)
if (LSpec.Has1DLayers && ~isnan(Timesteps))
ERROR nnet.internal.cnn.keras.LayerSpec/translateLayer (第 56 行)
NNTLayers = translate(this.Translator, this, TranslateWeights, TranslateTrainingParams, UserImageInputSize);
ERROR nnet.internal.cnn.keras.LayerSpec/translateDAGLayer (第 64 行)
NNTLayers = translateLayer(this, TranslateWeights, TranslateTrainingParams, UserImageInputSize);
ERROR nnet.internal.cnn.keras.AssembledModel>@(LSpec)translateDAGLayer(LSpec,AM.OutputTensors,AM.TrainingConfig,TranslateWeights,TranslateTrainingParams,UserImageInputSize,isRNN(AM)) (第 287 行)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, AM.OutputTensors, AM.TrainingConfig, TranslateWeights,...
ERROR nnet.internal.cnn.keras.AssembledModel/translateDAGModel (第 287 行)
NNTLayerGroups = cellfun(@(LSpec)translateDAGLayer(LSpec, AM.OutputTensors, AM.TrainingConfig, TranslateWeights,...
ERROR nnet.internal.cnn.keras.AssembledModel/translateAssembledModel (第 64 行)
Layers = translateDAGModel(this, TranslateWeights, TranslateTrainingParams, UserImageInputSize);
ERROR nnet.internal.cnn.tensorflow.savedmodel.TFKerasManager (第 100 行)
LayersOrGraph = translateAssembledModel(obj.AM, obj.TrainingConfig, obj.AM.WeightsImported, false, ImageInputSize);
ERROR nnet.internal.cnn.tensorflow.savedmodel.TFSavedModel (第 35 行)
obj.KerasManager = savedmodel.TFKerasManager(smstruct.meta_graphs.object_graph_def, obj.SavedModelPath, kerasImporterOptions, importNetwork);
ERROR nnet.internal.cnn.tensorflow.importTensorFlowNetwork (第 19 行)
sm = savedmodel.TFSavedModel(path, options, true);
ERROR importTensorFlowNetwork (第 107 行)
Network = nnet.internal.cnn.tensorflow.importTensorFlowNetwork(modelFolder, varargin{:});
When I look at the translate function, the problem seems to be caused by 1Dcov with timestep. as follows.
Attached is the architecture of the model. This model is a generator in GAN, the input is noise of length 128 and the output is data of length 200 and number of channels 2.
Could anyone help me?
Thank you!

답변 (1개)

Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 5월 31일
You can try to use the importTensorFlowLayers function. The importTensorFlowLayers function inserts placeholder layers in place of TensorFlow layers when the software cannot convert the TensorFlow layers to built-in MATLAB layers and cannot generate custom layers in place of the unsupported TensorFlow layers.
To find the names and indices of the placeholder layers in the layer graph, use the findPlaceholderLayers function. You can then replace a placeholder layer with a built-in MATLAB layer, custom layer or functionLayer. To replace a layer, use replaceLayer.
  댓글 수: 3
Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 6월 1일
Can you try to replace the variable Timesteps in your TensorFlow model with the actual value (for example, 2 or 10)? I think the issue might be that the import function doesn't know what Timesteps is, because you have defined it as a variable in your Python code.
琛龙 汪
琛龙 汪 2022년 6월 2일
편집: 琛龙 汪 2022년 6월 2일
Timesteps is not defined in my tensorflow model, it is referenced in the m-file in the matlab deep learning tool.
If the corresponding package is installed, you can find it under this relative path.
.\MATLAB\SupportPackages\R2022a\toolbox\nnet\supportpackages\keras_importer\+nnet\+internal\+cnn\+keras\TranslatorForDAGInputLayer.m
You can refer to this image I posted earlier, which is the m-file corresponding to the above path.
Thanks~

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by