当前位置:网站首页>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
边栏推荐
- 基于Labview上位机的51单片机步进电机控制系统(上位机代码+下位机源码+ad原理图+51完整开发环境)
- ARMCC/GCC下的stack protector
- 基于51单片机的温湿度监测+定时报警系统(c51源码)
- 机器视觉系列(02)---TensorFlow2.3 + win10 + GPU安装
- PyTorch 17. GPU并发
- Are realrange and einsum really elegant
- AUTOSAR从入门到精通100讲(八十三)-BootLoader自我刷新
- Detailed explanation of device tree
- PyTorch 13. 嵌套函数和闭包(狗头)
- ECDSA 签名验证原理及C语言实现
猜你喜欢

机器学习——PCA与LDA

Face_ Recognition face detection

【51单片机交通灯仿真】

关于短视频平台框架搭建与技术选型探讨

GIS实战应用案例100篇(五十三)-制作三维影像图用以作为城市空间格局分析的底图

【点云系列】Learning Representations and Generative Models for 3D pointclouds

CMSIS CM3源码注解

Visual studio 2019 installation and use

基于openmv的无人机Apriltag动态追踪降落完整项目资料(labview+openmv+apriltag+正点原子四轴)

美摄科技云剪辑,助力哔哩哔哩使用体验再升级
随机推荐
GIS实战应用案例100篇(五十一)-ArcGIS中根据指定的范围计算nc文件逐时次空间平均值的方法
pth 转 onnx 时出现的 gather、unsqueeze 等算子
Chapter 3 pytoch neural network toolbox
[point cloud series] pnp-3d: a plug and play for 3D point clouds
CMSIS CM3源码注解
Common regular expressions
AUTOSAR从入门到精通100讲(五十一)-AUTOSAR网络管理
PyTorch 20. PyTorch技巧(持续更新)
【点云系列】 场景识别类导读
使用 trt 的int8 量化和推断 onnx 模型
[3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion
传输层重要知识(面试,复试,期末)
armv8m(cortex m33) MPU实战
美摄科技推出桌面端专业视频编辑解决方案——美映PC版
ECDSA 签名验证原理及C语言实现
Chapter 1 numpy Foundation
Proteus 8.10安装问题(亲测稳定不闪退!)
ARMCC/GCC下的stack protector
AUTOSAR从入门到精通100讲(五十)-AUTOSAR 内存管理系列- ECU 抽象层和 MCAL 层
【技术规范】:如何写好技术文档?