Answers.Body: <p>This can be thought of as a <strong>loss function design problem</strong>. If you optimize your network weights for something like multi-class classification, then expect your network to learn weights for this task (You will use cross entropy loss for this task). If you optimize your network to output a single value at the last layer and treat it as a regression problem for age prediction, then your network can learn weights for this particular task (You may use something like Mean Square Error loss here).</p>
  
  <p>Let me give you a weak guidline on how to do this. Suppose say your input is images of chairs and you want to predict their age using a pretrained resnet, this is how you may do it in pytorch.</p>
  
  <p><strong>Definition</strong><br>
  X: Input pictures<br>
  Y: List of ground truth values which is age here. i.e. : [1.4, 2.5, 2.2, ....]  </p>
  
  <p><strong>Modify your neural network to give one output at the last layer</strong><br>
  model = torchvision.models.resnet18(pretrained=True)<br>
  num_ftrs = model.fc.in_features<br>
  model.fc = torch.nn.Linear(num_ftrs, 1)  </p>
  
  <p><strong>Design your loss function appropriately. You can treat age prediction as a standard regression problem. Of course, there are better loss designs here.</strong><br>
  criterion =  torch.nn.MSELoss()</p>
  
  <p><strong>So use this loss during training</strong><br>
  loss = criterion(output, target) where output is your neural network prediction and target is your ground truth values.</p>
  
  <p>This is how you can modify an existing architecture for your task. Hope it helps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-30T17:21:52.853Z
Answers.LastActivityDate: 2019-08-30T17:21:52.853Z
Answers.UserDisplayName: keshik
Answers.Body: <p>You generally use SoftMax Layer as the output layer for a neural network that is used as a Classifier. </p>
  
  <p>Now, if you want your neural network to predict the age of a chair, predicting price of a chair like in linear regression (output is continuous), you have to remove the SoftMax Layer and add one or multiple layers such that the output of the final layer gives only one value at the output. (which is the prediction for you age or price). And, instead of logit loss you can use MSE for back propagation. </p>
  
  <p>So, like keshik mentioned in another answer, it's all about the final layer used and the loss function used. Based on what you use, your weights get trained.</p>
  
  <p>This is what is done in <strong>transfer learning</strong> also. Based on the task you want to achieve you change the last layers and retrain your network. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-31T05:46:03.580Z
Answers.LastActivityDate: 2019-08-31T05:46:03.580Z
Answers.UserDisplayName: Kartik Podugu
Body: <p>How do I program a neural network such that, when an image is inputted, the output is a numerical value that is not the probability of the image being a certain class? In other words, a CNN that doesn't classify. For example, when an input of an image of a chair is given, the model should not give the chance that the image is a chair but rather give the predicted age of the chair, the predicted price of the chair, etc. I'm currently not sure how to program a neural net like this.</p>
  
Tags: <machine-learning><deep-learning><convolutional-neural-networks>
Title: How does one create a non-classifying CNN in order to gain information from images?
UserDisplayName: Tariq S.
ThreadText: # How does one create a non-classifying CNN in order to gain information from images?
  
  (Asked by: username_0 on 2019-08-30)
  
  How do I program a neural network such that, when an image is inputted, the output is a numerical value that is not the probability of the image being a certain class? In other words, a CNN that doesn't classify. For example, when an input of an image of a chair is given, the model should not give the chance that the image is a chair but rather give the predicted age of the chair, the predicted price of the chair, etc. I'm currently not sure how to program a neural net like this.
  
  **Tags:** machine-learning, deep-learning, convolutional-neural-networks
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-08-30. Score: 2
  
  This can be thought of as a **loss function design problem**. If you optimize your network weights for something like multi-class classification, then expect your network to learn weights for this task (You will use cross entropy loss for this task). If you optimize your network to output a single value at the last layer and treat it as a regression problem for age prediction, then your network can learn weights for this particular task (You may use something like Mean Square Error loss here).
  
  Let me give you a weak guidline on how to do this. Suppose say your input is images of chairs and you want to predict their age using a pretrained resnet, this is how you may do it in pytorch.
  
  **Definition**  
  X: Input pictures  
  Y: List of ground truth values which is age here. i.e. : [1.4, 2.5, 2.2, ....]
  
  **Modify your neural network to give one output at the last layer**  
  model = torchvision.models.resnet18(pretrained=True)  
  num\_ftrs = model.fc.in\_features  
  model.fc = torch.nn.Linear(num\_ftrs, 1)
  
  **Design your loss function appropriately. You can treat age prediction as a standard regression problem. Of course, there are better loss designs here.**  
  criterion = torch.nn.MSELoss()
  
  **So use this loss during training**  
  loss = criterion(output, target) where output is your neural network prediction and target is your ground truth values.
  
  This is how you can modify an existing architecture for your task. Hope it helps.
  
  
  ---
  
  ### Answer by username_2 on 2019-08-31. Score: 1
  
  You generally use SoftMax Layer as the output layer for a neural network that is used as a Classifier.
  
  Now, if you want your neural network to predict the age of a chair, predicting price of a chair like in linear regression (output is continuous), you have to remove the SoftMax Layer and add one or multiple layers such that the output of the final layer gives only one value at the output. (which is the prediction for you age or price). And, instead of logit loss you can use MSE for back propagation.
  
  So, like username_1 mentioned in another answer, it's all about the final layer used and the loss function used. Based on what you use, your weights get trained.
  
  This is what is done in **transfer learning** also. Based on the task you want to achieve you change the last layers and retrain your network.
  
  
  ---
  
  