Answers.Body: <p>The authors use so-called embeddings, it's a form to represent the images in some meaningful vector form.</p>
  <p>The procedure to get embedding as follows. First, keep in mind most of the popular convolutional net architectures starts with convolutional layers and then have few fully connected layers. Then do the following.</p>
  <ol>
  <li>Train the full network with one-hot encoded labels as usual</li>
  <li>Take away the last fully connected layer and use the values on the previous layer as a representation.</li>
  </ol>
  <p>In the case of resnet50, you will get a 2048-value float vector. The property of a neural network is that semantically close images usually have close representation on the last layers and you could use euclidian distance to measure the similarity of images in some sense (not really, but it's another long discussion)</p>
  <p>I don't know the paper, but I glimpsed through it. You could see in formula 4 the <span class="math-container">$x$</span> is embedding representation. Loss at formula 5 is cross-entropy after applying the last linear layer (<span class="math-container">$Wx + b$</span>) and then softmax.</p>
  <p>As a side note, you could skip the first step completely and use pretrained weights as a starting point. I.e. in pytorch you could take pretrained on ImageNet classification weights as follows</p>
  <pre><code>import torchvision.models as models
  resnet = models.resnet50(pretrained=True)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-13T14:15:49.903Z
Answers.LastActivityDate: 2021-04-13T14:15:49.903Z
Answers.UserDisplayName: Kirill Fedyanin
Body: <p>I'm trying to implement the vehicle re-identification model described in <a href="https://arxiv.org/pdf/2004.06271.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/2004.06271.pdf</a>.</p>
  <p>My question focuses on Section 3.2 of the paper, which uses a <strong>ResNet-50 for deep feature extraction</strong> in order to generate <strong>discriminative features</strong> which can be used to compare images of vehicles by Euclidean distance for re-identification. It takes a 256x256x3 image as input.</p>
  <p>My understanding of ResNet-50 is that its output is of the shape <strong>N</strong>, where <strong>N</strong> is the number of classes which an input image could be, and ground truth labels take the form of a one-hot encoding where the '1' value represents the node in the output layer which is associated with the given class.</p>
  <p>I am therefore confused by the usage of ResNet-50 in a re-identification task in which the goal is to generate an array of discriminative features which can be compared by Euclidean distance. There is no discrete set of <strong>N</strong> classes, as the model should work on any of the infinite number of vehicles in the world.</p>
  <p><strong>What is the ground truth label in a ResNet-50 in the context of a re-identification task?</strong></p>
  
Tags: <deep-learning><convolutional-neural-networks><feature-extraction>
Title: How is a ResNet-50 used for deep feature extraction?
UserDisplayName: magmacollaris
ThreadText: # How is a ResNet-50 used for deep feature extraction?
  
  (Asked by: username_0 on 2021-04-13)
  
  I'm trying to implement the vehicle re-identification model described in <https://arxiv.org/pdf/2004.06271.pdf>.
  
  My question focuses on Section 3.2 of the paper, which uses a **ResNet-50 for deep feature extraction** in order to generate **discriminative features** which can be used to compare images of vehicles by Euclidean distance for re-identification. It takes a 256x256x3 image as input.
  
  My understanding of ResNet-50 is that its output is of the shape **N**, where **N** is the number of classes which an input image could be, and ground truth labels take the form of a one-hot encoding where the '1' value represents the node in the output layer which is associated with the given class.
  
  I am therefore confused by the usage of ResNet-50 in a re-identification task in which the goal is to generate an array of discriminative features which can be compared by Euclidean distance. There is no discrete set of **N** classes, as the model should work on any of the infinite number of vehicles in the world.
  
  **What is the ground truth label in a ResNet-50 in the context of a re-identification task?**
  
  **Tags:** deep-learning, convolutional-neural-networks, feature-extraction
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-13. Score: 1 | Accepted answer
  
  The authors use so-called embeddings, it's a form to represent the images in some meaningful vector form.
  
  The procedure to get embedding as follows. First, keep in mind most of the popular convolutional net architectures starts with convolutional layers and then have few fully connected layers. Then do the following.
  
  1. Train the full network with one-hot encoded labels as usual
  2. Take away the last fully connected layer and use the values on the previous layer as a representation.
  
  In the case of resnet50, you will get a 2048-value float vector. The property of a neural network is that semantically close images usually have close representation on the last layers and you could use euclidian distance to measure the similarity of images in some sense (not really, but it's another long discussion)
  
  I don't know the paper, but I glimpsed through it. You could see in formula 4 the $x$ is embedding representation. Loss at formula 5 is cross-entropy after applying the last linear layer ($Wx + b$) and then softmax.
  
  As a side note, you could skip the first step completely and use pretrained weights as a starting point. I.e. in pytorch you could take pretrained on ImageNet classification weights as follows
  
  ```
  import torchvision.models as models
  resnet = models.resnet50(pretrained=True)
  
  ```
  
  
  ---
  
  