Using importTensorFlowNetwork does not load the model correctly
조회 수: 9 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!