Convert Image Classification Network into Regression Network using ResNet18
5 次查看(过去 30 天)
显示 更早的评论
I will appreciate it if anyone can help, and thanks in advance. The images are in augmented image datastore
My code:
net = resnet18;
layers = net.Layers;
numResponses = 1;
layers = [
layers(1:68)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('sgdm',...
'InitialLearnRate',0.001, ...
'ValidationData',{augimdsImagesP11Test,P11Test_betaRepBSN8},...
'Plots','training-progress',...
'Verbose',false);
net2 = trainNetwork(augimdsImagesP11Train,P11Train2_beta,layers,options);
ERROR =
Error using trainNetwork (line 170)
Layers argument must be an array of layers or a layer graph.
0 个评论
采纳的回答
Madhav Thakker
2020-9-8
Hi Kenneth,
I understand that you want to convert the pretrained resent-18 to regression network.
While training the network, we must pass the Layer graph or an array of layers to our network. I am attaching a code snippet that does the same with resnet-18 network and modifies the network to be used as a regression network.
net = resnet18;
lgraph = layerGraph(net);
numClasses = 1;
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
regress = regressionLayer('Name', 'new_reg');
lgraph = replaceLayer(lgraph,"fc1000",newLearnableLayer);
lgraph = removeLayers(lgraph, "ClassificationLayer_predictions");
lgraph = replaceLayer(lgraph,"prob",regress);
Note that, the input to the network is same as the pretrained resnet-18, i.e., images with shape (224, 224, 3).
For more information, see https://www.mathworks.com/help/deeplearning/ug/convert-classification-network-into-regression-network.html
Hope this helps.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!