Pytorch CNN for Regression

Does anyone know of any Pytorch CNN examples for regression? I can’t seem to find any regression examples (everything I’ve seen is for classification).


I think the tasks related to images are mostly classification tasks. However, there are some applications for regression but more specifically ordinal-regression, such as age estimation. You can see this paper for an example of ordinal-regression with CNN:

@vmirly1 I’ve definitely seen papers implementing CNNs for regression. I was actually trying to see if there are any Pytorch examples using CNNs on regression problems. I suspect that the only thing I need to do different in a regression problem in Pytorch is change the cost function to MSE.

Basically yes. Probably you would also change the last layer to give the desired number of outputs as well as remove some non-linearity on the last layer such as F.log_softmax (if used before).

1 Like

What if it was nonlinear regression, would you still want to remove non-linearity?
Also, are the activation functions in the layers before the output layer typically the same for regression and classification?

I just meant the last non-linearity. The activation functions between the layers should still be used. I would try to use pretty much the same architecture besides the small changes necessary for regression.

1 Like

Got it, thanks! I suspected the same, however, I do find it somewhat ironic and intriguing that pretty much the same architecture can be used for both regression and classification except for the loss function and some minor details in the output layer.

Would be nice to see an example of a pytorch module that someone recommends or a basic MWE.