How Can I change the Layer Names of my Network So I can Import It?
조회 수: 20 (최근 30일)
이전 댓글 표시
I'm trying to import a network that I trained myself using this code. This code is run twice. It fails on the second attempt:
classes = ["Parasitized" "Uninfected"];
malaria_alexnet = 'C:\<directory>\malaria_alexnet_step2_accuracy_0.95952.onnx';
malaria_alexnet = importONNXNetwork(malaria_alexnet,'OutputLayerType','classification','Classes',classes);
lgraph = layerGraph(malaria_alexnet.Layers);
malaria_alexnet = trainNetwork(augimdsTrain,lgraph,options);
The reason that I use **lgraph = layerGraph(malaria_alexnet.Layers);** is because I don't want to drop my weights.
However, when I import this network the second time, I get this error:
Error using nnet.internal.cnn.util.validateLayersForLayerGraph>iAssertUniqueAndNonEmptyLayerNames (line 56)
Layer names in layer array must be different from the names of layers in layer graph.
Error in nnet.internal.cnn.util.validateLayersForLayerGraph (line 33)
iAssertUniqueAndNonEmptyLayerNames(larray, existingLayers);
Error in nnet.cnn.LayerGraph>iValidateLayers (line 551)
larray = nnet.internal.cnn.util.validateLayersForLayerGraph(larray, existingLayers);
Error in nnet.cnn.LayerGraph/addLayers (line 190)
larray = iValidateLayers(larray, existingLayers);
Error in nnet.internal.cnn.onnx.translateONNX>makeConnections (line 301)
NNTLayerGraph = addLayers(NNTLayerGraph, NNTLayers{L});
Error in nnet.internal.cnn.onnx.translateONNX (line 131)
NNTLayerGraphOrArray = makeConnections(NNTLayers, thisGraph, initializerNames);
Error in nnet.internal.cnn.onnx.importONNXNetwork (line 8)
LayersOrGraph = nnet.internal.cnn.onnx.translateONNX(modelProto, OutputLayerType, UserImageInputSize, true);
Error in importONNXNetwork (line 52)
Network = nnet.internal.cnn.onnx.importONNXNetwork(modelfile, varargin{:});
Error in sgd_with_restarts_imported_network (line 17)
malaria_alexnet = importONNXNetwork(malaria_alexnet,'OutputLayerType','classification','Classes',classes);
How can I import my .onnx file or change the layer names to something different than what is found in layer graph?
댓글 수: 0
채택된 답변
Sai Bhargav Avula
2020년 3월 26일
Hi,
For the above mentioned purpose you can try using the importONNXLayers. Set the 'ImportWeights' name-value argument to true to retain the weights. This way you can play around with the layers, instead of importing it twice.
Hope this helps!
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
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!