当前位置:网站首页>Draw margin curve in arcface
Draw margin curve in arcface
2022-04-23 07:28:00 【wujpbb7】
The effect is as follows :
The code is as follows :
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()
Reference resources :
3、 Line style
版权声明
本文为[wujpbb7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230611550106.html
边栏推荐
- Warning "force fallback to CPU execution for node: gather_191" in onnxruntime GPU 1.7
- 带您遨游太空,美摄科技为航天创意小程序提供全面技术支持
- Detailed explanation of device tree
- AUTOSAR从入门到精通100讲(五十)-AUTOSAR 内存管理系列- ECU 抽象层和 MCAL 层
- 【点云系列】Multi-view Neural Human Rendering (NHR)
- How keras saves and loads the keras model
- 直观理解 torch.nn.Unfold
- pth 转 onnx 时出现的 gather、unsqueeze 等算子
- “泉”力以赴·同“州”共济|北峰人一直在行动
- 【點雲系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation
猜你喜欢
STM32多路测温无线传输报警系统设计(工业定时测温/机舱温度定时检测等)
【点云系列】Relationship-based Point Cloud Completion
画 ArcFace 中的 margin 曲线
使用 trt 的int8 量化和推断 onnx 模型
美摄科技云剪辑,助力哔哩哔哩使用体验再升级
SPI NAND FLASH小结
【无标题】制作一个0-99的计数器,P1.7接按键,P2接数码管段,共阳极数码管,P3.0,P3.1接数码管位码,每按一次键,数码管显示加一。请写出单片机的C51代码
Machine learning III: classification prediction based on logistic regression
x509解析
Face_ Recognition face detection
随机推荐
How keras saves and loads the keras model
torch.where能否传递梯度
Systrace 解析
By onnx checker. check_ Common errors detected by model
PyTorch 17. GPU并发
x509解析
Proteus 8.10安装问题(亲测稳定不闪退!)
Chapter 2 pytoch foundation 1
unhandled system error, NCCL version 2.7.8
Pytoch model saving and loading (example)
美摄科技受邀LVSon2020大会 分享《AI合成虚拟人物的技术框架与挑战》
初探智能指针之std::shared_ptr、std::unique_ptr
Cmder Chinese garbled code problem
Int8 quantification and inference of onnx model using TRT
AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
Detailed explanation of unwind stack backtracking
公专融合对讲机是如何实现多模式通信下的协同工作?
带低压报警的51单片机太阳能充电宝设计与制作(完整代码资料)
【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
【点云系列】Relationship-based Point Cloud Completion