Feature Extraction

username: Angelina_Robert
cooked: <p>Hi,<br>
just wondering, if anyone can guide about finding the angles between extracted features and their corresponding class centers.</p>

username: Usama_Hasan
cooked: <p>Hy <a class="mention" href="/u/angelina_robert">@Angelina_Robert</a>.<br>
I don’t think so if there’s a proper guide for this specific topic but you can look at distance metrics which employ different techniques to find the similarities between feature. You can use cosine similarity which measure the angle between two vector project in a higher dimensional space.<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <a href="https://pytorch.org/docs/stable/generated/torch.nn.CosineSimilarity.html" target="_blank" rel="noopener nofollow ugc">pytorch.org</a>
  </header>
  <article class="onebox-body">
    <img src="" class="thumbnail" width="" height="">

<h3><a href="https://pytorch.org/docs/stable/generated/torch.nn.CosineSimilarity.html" target="_blank" rel="noopener nofollow ugc">CosineSimilarity — PyTorch 1.6.0 documentation</a></h3>



  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
It’s already available in pytorch
<p>Also read this article too.<br>
<aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://aiaspirant.com/wp-content/uploads/2019/05/cropped-favicon-32x32.png" class="site-icon" width="32" height="32">
      <a href="https://aiaspirant.com/distance-similarity-measures-in-machine-learning/" target="_blank" rel="noopener nofollow ugc" title="12:15PM - 13 May 2019">AI ASPIRANT – 13 May 19</a>
  </header>
  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:272/90;"><img src="https://aiaspirant.com/wp-content/uploads/2019/05/Capture-1.png" class="thumbnail" width="272" height="90"></div>

<h3><a href="https://aiaspirant.com/distance-similarity-measures-in-machine-learning/" target="_blank" rel="noopener nofollow ugc">7 Important Distance Measures in Machine Learning - AI ASPIRANT</a></h3>

<p>For algorithms like the k-nearest neighbor and k-means it is essential to measure the distance between the data points. Distance measures in machine learning a</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>

username: Angelina_Robert
cooked: <p>Thanks, Usama_Hasan for your reply. I want to measure the angles between the features and their corresponding classes to find the spatial span. The idea has been motivated by " Deep Representation Learning on Long-tailed Data_ A Learnable Embedding Augmentation Perspective" paper but I could not find its code. Any help in this regard would be highly appreciated.<br>
Cheers</p>

username: Usama_Hasan
cooked: <p>Hy <a class="mention" href="/u/angelina_robert">@Angelina_Robert</a>, I will look to it, for now do you know the idea of L-Softmax or Angular Softmax, which adds a angle between classes in softmax.<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://static.arxiv.org/static/browse/0.3.2.6/images/icons/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://arxiv.org/abs/1801.05599" target="_blank" rel="noopener nofollow ugc">arXiv.org</a>
  </header>
  <article class="onebox-body">
    <img src="" class="thumbnail" width="16" height="16">

<h3><a href="https://arxiv.org/abs/1801.05599" target="_blank" rel="noopener nofollow ugc">Additive Margin Softmax for Face Verification</a></h3>

<p>In this paper, we propose a conceptually simple and geometrically
interpretable objective function, i.e. additive margin Softmax (AM-Softmax),
for deep face verification. In general, the face verification task can be
viewed as a metric learning...</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="16" height="16">
      <a href="https://github.com/Leethony/Additive-Margin-Softmax-Loss-Pytorch" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars0.githubusercontent.com/u/37405758?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/Leethony/Additive-Margin-Softmax-Loss-Pytorch" target="_blank" rel="noopener nofollow ugc">Leethony/Additive-Margin-Softmax-Loss-Pytorch</a></h3>

<p>Additive margin softmax loss in pytorch. Contribute to Leethony/Additive-Margin-Softmax-Loss-Pytorch development by creating an account on GitHub.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: Angelina_Robert
cooked: <p>Thanks a lot, Usama_Hassan. I read this article long ago but again will have a look. Thanks again.</p>
<p>Cheers</p>

username: Angelina_Robert
cooked: <p>Hi Usama_Hassan, Just wondering where is the calculation of angles in " <a href="https://github.com/Leethony/Additive-Margin-Softmax-Loss-Pytorch" rel="noopener nofollow ugc">Leethony/Additive-Margin-Softmax-Loss-Pytorch </a>". Could you please point me out that?<br>
Cheers</p>

username: Usama_Hasan
cooked: <p>My Bad, I mentioned the forked repo link. Check the loss_function.py in this repo.<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="16" height="16">
      <a href="https://github.com/cvqluu/Angular-Penalty-Softmax-Losses-Pytorch" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars3.githubusercontent.com/u/32367480?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/cvqluu/Angular-Penalty-Softmax-Losses-Pytorch" target="_blank" rel="noopener nofollow ugc">cvqluu/Angular-Penalty-Softmax-Losses-Pytorch</a></h3>

<p>Angular penalty loss functions in Pytorch (ArcFace, SphereFace, Additive Margin, CosFace)  - cvqluu/Angular-Penalty-Softmax-Losses-Pytorch</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
The calculation looks like this.
<pre><code class="lang-auto">numerator = self.s * torch.cos(torch.acos(torch.clamp(torch.diagonal(wf.transpose(0, 1)[labels]), -1.+self.eps, 1-self.eps)) + self.m)
</code></pre>

username: Angelina_Robert
cooked: <p>Heaps of thanks. I m going to check that.</p>
<p>Cheers.</p>