How to add regression layer to DAG network like resnet50 for image regression problem?

Illustration
transert_0 - 2021-05-17T15:38:42+00:00
Question: How to add regression layer to DAG network like resnet50 for image regression problem?

Can anyone suggest me how to add regression layer to DAG network like Resnet50 at the end, for Iamge regression problem. I could able to understand how to add regression layer to series network architecure like Alexnet. How to do with DAG network architecture like Resnet50?

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

Hi,
To remove the classification layer and use regression layer instread you can use the add/remove/replace APIs.
The following code should resolve your issue.
 
 
net=resnet50;
net.SortedLayers;
lgraph = layerGraph(net);
newlgraph = removeLayers(lgraph,'ClassificationLayer_fc1000');
newlgraph = removeLayers(newlgraph,'fc1000_softmax');
lgraph = addLayers(newlgraph,regressionLayer('Name','out'));
lgraph = connectLayers(lgraph,'fc1000','out');
snet = assembleNetwork(lgraph);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!