How to use removeLayers without layerNames (How to remove layers if the layers don't have names)?
9 次查看(过去 30 天)
显示 更早的评论
When I am using transfer learning with ResNet50 I am removing the last 3 layers of ResNet as follows:
net = resnet50;
lgraph = layerGraph(net);
lgraph = removeLayers(lgraph, {'fc1000','fc1000_softmax','ClassificationLayer_fc1000'});
However, syntax for removeLayers is
newlgraph = removeLayers(lgraph,layerNames)
Right now I am trying to use transfer learning with MobileNetv2, but the last 3 layers are not named and doesn't have layerNames specified after checking the layers with the following code:
net = mobilenetv2;
lgraph = layerGraph(net);
alllayers = lgraph.Layers
How can I remove the last 3 layers or n number of layers of MobileNetv2 in order to use transfer learning with my own classifier?
2 个评论
回答(1 个)
Jalaj Gambhir
2019-10-18
Hi,
I cannot reproduce the issue at my end. The same snippet of code that you mentioned, gives the layer details including the Layer Names of all 155 Layers of MobileNetv2. And, I am able to remove layers with the procedure you mentioned with resnet50.
Another method of creating a new layer graph with the required layer is to use addLayers as mentioned below:
newlgraph = layerGraph;
net = mobilenetv2;
lgraph = layerGraph(net);
alllayers = lgraph.Layers;
newlgraph = addLayers(newlgraph, alllayers(1:end-3))
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!