当前位置:网站首页>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
边栏推荐
- Raspberry Pie: two color LED lamp experiment
- Chapter 8 generative deep learning
- Device Tree 详解
- 面试总结之特征工程
- 美摄科技推出桌面端专业视频编辑解决方案——美映PC版
- 【点云系列】Pointfilter: Point Cloud Filtering via Encoder-Decoder Modeling
- MySQL installation and configuration - detailed tutorial
- Modifying a column with the 'identity' pattern is not supported
- 被 onnx.checker.check_model 检查出的常见错误
- Chapter 4 pytoch data processing toolbox
猜你喜欢

Systrace 解析

美摄助力百度“度咔剪辑”,让知识创作更容易

x509解析

关于短视频技术轮廓探讨

SPI NAND FLASH小结

机器学习——PCA与LDA

Modifying a column with the 'identity' pattern is not supported

【点云系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation

Chapter 5 fundamentals of machine learning

GIS实战应用案例100篇(五十二)-ArcGIS中用栅格裁剪栅格,如何保持行列数量一致并且对齐?
随机推荐
Warning "force fallback to CPU execution for node: gather_191" in onnxruntime GPU 1.7
PyTorch 10. 学习率
enforce fail at inline_ container. cc:222
Pep517 error during pycuda installation
【点云系列】 场景识别类导读
主流 RTOS 评估
Proteus 8.10安装问题(亲测稳定不闪退!)
“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
Machine learning III: classification prediction based on logistic regression
【点云系列】Relationship-based Point Cloud Completion
【点云系列】Unsupervised Multi-Task Feature Learning on Point Clouds
Chapter 4 pytoch data processing toolbox
imx6ull-qemu 裸机教程2:USDHC SD卡
armv8m(cortex m33) MPU实战
ARMCC/GCC下的stack protector
【点云系列】SO-Net:Self-Organizing Network for Point Cloud Analysis
Write a wechat double open gadget to your girlfriend
初探智能指针之std::shared_ptr、std::unique_ptr
FATFS FAT32学习小记
基于Labview上位机的51单片机步进电机控制系统(上位机代码+下位机源码+ad原理图+51完整开发环境)