Fine-tuning resnet18 (transfer learning) - layer connections error
16 次查看(过去 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!