How Can I change the Layer Names of my Network So I can Import It?
12 次查看(过去 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!