当前位置:网站首页>画 ArcFace 中的 margin 曲线
画 ArcFace 中的 margin 曲线
2022-04-23 06:12:00 【wujpbb7】
效果如下:

代码如下:
from math import cos, sin, pi
import numpy as np
import matplotlib.pyplot as plt
'''
# https://github.com/deepinsight/insightface/blob/master/recognition/arcface_torch/losses.py
class ArcFace(torch.nn.Module):
""" ArcFace (https://arxiv.org/pdf/1801.07698v1.pdf):
"""
def __init__(self, s=64.0, margin=0.5):
super(ArcFace, self).__init__()
self.scale = s
self.cos_m = math.cos(margin)
self.sin_m = math.sin(margin)
self.theta = math.cos(math.pi - margin)
self.sinmm = math.sin(math.pi - margin) * margin
self.easy_margin = False
def forward(self, logits: torch.Tensor, labels: torch.Tensor):
index = torch.where(labels != -1)[0]
target_logit = logits[index, labels[index].view(-1)]
sin_theta = torch.sqrt(1.0 - torch.pow(target_logit, 2))
cos_theta_m = target_logit * self.cos_m - sin_theta * self.sin_m # cos(target+margin)
if self.easy_margin:
final_target_logit = torch.where(
target_logit > 0, cos_theta_m, target_logit)
else:
final_target_logit = torch.where(
target_logit > self.theta, cos_theta_m, target_logit - self.sinmm)
logits[index, labels[index].view(-1)] = final_target_logit
logits = logits * self.scale
return logits
'''
margin = 0.5
x = np.linspace(0, pi, 100)
y1 = [(cos(i+margin) if cos(i) > 0 else cos(i)) for i in x]
y2 = [(cos(i+margin) if cos(i) > cos(pi-margin) else cos(i)-sin(pi-margin)*margin) for i in x]
l1, = plt.plot(x, y1, label='easy margin', color='red', linestyle='dashed')
l2, = plt.plot(x, y2, label='hard margin', color='green', linestyle='dotted')
plt.legend(handles=[l1,l2])
plt.show()
plt.close()
参考:
2、plot画图
3、线的风格
版权声明
本文为[wujpbb7]所创,转载请带上原文链接,感谢
https://blog.csdn.net/blueblood7/article/details/123559203
边栏推荐
- .net加载字体时遇到 Failed to decode downloaded font:
- 【点云系列】Learning Representations and Generative Models for 3D pointclouds
- Summary of image classification white box anti attack technology
- 【2021年新书推荐】Effortless App Development with Oracle Visual Builder
- MySQL notes 4_ Primary key auto_increment
- [dynamic programming] different binary search trees
- torch.mm() torch.sparse.mm() torch.bmm() torch.mul() torch.matmul()的区别
- [3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion
- 扫雷小游戏
- Use originpro express for free
猜你喜欢
![[2021 book recommendation] kubernetes in production best practices](/img/78/2b5bf03adad5da9a109ea5d4e56b18.png)
[2021 book recommendation] kubernetes in production best practices

1.1 PyTorch和神经网络

微信小程序 使用wxml2canvas插件生成图片部分问题记录

Chapter 2 pytoch foundation 2

【点云系列】Unsupervised Multi-Task Feature Learning on Point Clouds

第2章 Pytorch基础2
![[2021 book recommendation] learn winui 3.0](/img/1c/ca7e05946613e9eb2b8c24d121c2e1.png)
[2021 book recommendation] learn winui 3.0

第2章 Pytorch基础1
Raspberry Pie: two color LED lamp experiment
![[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200](/img/5a/387baa0f59e5a8a502bb157184d968.png)
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
随机推荐
Gee configuring local development environment
【点云系列】Unsupervised Multi-Task Feature Learning on Point Clouds
Chapter 1 numpy Foundation
What did you do during the internship
MySQL installation and configuration - detailed tutorial
扫雷小游戏
【点云系列】DeepMapping: Unsupervised Map Estimation From Multiple Point Clouds
树莓派:双色LED灯实验
Gephi tutorial [1] installation
torch.mm() torch.sparse.mm() torch.bmm() torch.mul() torch.matmul()的区别
c语言编写一个猜数字游戏编写
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
Pytorch model pruning example tutorial III. multi parameter and global pruning
Chapter 8 generative deep learning
【2021年新书推荐】Kubernetes in Production Best Practices
Summary of image classification white box anti attack technology
Compression and acceleration technology of deep learning model (I): parameter pruning
Visual studio 2019 installation and use
1.2 preliminary pytorch neural network
【点云系列】Fully-Convolutional geometric features