Fine-tuning resnet18 (transfer learning) - layer connections error
조회 수: 12 (최근 30일)
이전 댓글 표시
I want to fine-tune the pretrained resnet18 model, but when I follow the steps on the website: https://www.mathworks.com/help/deeplearning/ug/transfer-learning-using-alexnet.html
I get an error about the layer connections in the netwrok and I can not retrain it. How can I preserve all the layer connections and not just the layers from resnet18?
the error:
Error using trainNetwork (line 170)
Invalid network.
Error in fine_tune (line 67)
netTransfer = trainNetwork(imdsTrain,lgraph,options);
Caused by:
Layer 'res2a': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res2b': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res3a': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res3b': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res4a': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res4b': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res5a': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
Layer 'res5b': Unconnected input. Each layer input must be connected to the output of another layer.
Detected unconnected inputs:
input 'in2'
댓글 수: 0
답변 (1개)
Mahesh Taparia
2021년 1월 28일
Hi
It seems that the network input layer is not connected to the next layer or the lgraph is having some unconnected layers. Use analyzeNetwork to check the network connection, it will show the unconnected layers. Use connectLayers to connect two layers.
If it does n't work then, can you share your code? It will give more clarity.
Hope it will help!
댓글 수: 2
Mahesh Taparia
2021년 2월 4일
Hi
It seems you want to remove last few layers of the dlnetwork. Taking only the layer part of the network will lose the layerGraph property. For example, in your case you want to remove last 3 layers and want to add some layer. You can remove these layers by using removeLayers as given below:
net=resnet18;
lgraph=layerGraph(net);
lgraph = removeLayers(lgraph,{'ClassificationLayer_predictions','prob','fc1000'});
analyzeNetwork(lgraph)
After this you use connectLayers to connect the other layers to the layergraph. You can also check the documentation of replaceLayer here. Hope it will help!
참고 항목
카테고리
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!