效果如下:

 代码如下:

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 = sself.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) * marginself.easy_margin = Falsedef 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_logitlogits = logits * self.scalereturn 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()

参考:

1、讨论 easy margin

2、plot画图

3、线的风格

画 ArcFace 中的 margin 曲线相关推荐

  1. 如何用lisp画蔓叶线_用Autolisp 在AutoCAD中实现多种曲线的绘制

    用 Autolisp 在 AutoCAD 中实现多种曲线的绘制 一.引言: AutoCAD 自 1982 年由 Autodesk 公司推出以来, 经历了 20 年的发展更 新,目前,已深入到包括机械. ...

  2. ArcFace: Additive Angular Margin Loss for Deep Face Recognition 论文学习

    论文地址:https://arxiv.org/pdf/1801.07698.pdf Abstract 使用 DCNN 进行大规模人脸识别的一个主要挑战就是设计损失函数来增强判别能力.Center lo ...

  3. arcface:additive angular margin loss for deep face recognition

    技术详解:人脸识别算法的训练之路(下)-InfoQ摘要:我们从人脸识别技术的技术细节讲起,带你初步了解人脸识别技术的发展过程.通过平台实例的操作,带你看看如何利用公有云的计算资源,快速训练一个可用的人 ...

  4. 【百度论文复现赛】ArcFace: Additive Angular Margin Loss for Deep Face Recognition

    文章目录 摘要 Introduction Proposed Approach ArcFace SphereFace与CosFace的比较 与其它损失函数比较 实验 Implementation Det ...

  5. 人脸识别中的margin损失函数

    用于人脸识别的损失函数,有Softmax,Contrastive Loss,Triplet Loss,Center Loss,Norm Face,Large-Margin Loss,A-Softmax ...

  6. ai钢笔工具怎么描线_AI钢笔工具技巧,怎么画出完美的贝塞尔曲线

    AI钢笔工具技巧,怎么画出完美的贝塞尔曲线 我们在刚开始学习UI的时候,通常会临摹很多作品,一般临摹都分为两个步骤,第一步是使用钢笔工具把物体勾勒出来,但是很多人在勾轮廓的时候往往都不流畅,其实这是钢 ...

  7. android 坐标图绘制曲线,Android艺术之画一条平滑的曲线

    前言 说的是曲线,其实想法是来自一个曲线图的需求.图表这种东西,项目开发中也不少见,大多情况找个通用的开源框架改改就得了(老板们别打我),然而通用赶不上脑洞,要做交互和视觉比较特别的图表时,还是自己造 ...

  8. pline加点lisp_用Autolisp 在AutoCAD中实现多种曲线的绘制

    用Autolisp 在AutoCAD中实现多种曲线的绘制 一.引言: AutoCAD自1982年由Autodesk公司推出以来,经历了20年的发展更新,目前,已深入到包括机械.建筑.服装.航天航空.地 ...

  9. Arcface中的IR_SE模块

    Arcface论文v1:ArcFace: Additive Angular Margin Loss for Deep Face Recognition Arcface中的IR_SE模块

  10. matlab画平行x轴的图,【MATLAB】画平行于坐标轴的曲线

    用MATLAB画函数的曲线 用MATLAB画函数曲线 2013年8月11日 命令funtool 这是单变量函数分析的交互界面,比较方便,特别适用于y=f(x)型,即y与x分开的函数形式.见下图 mat ...

最新文章

  1. 深入理解PHP原理之变量(Variables inside PHP)
  2. python数据接口设计_python之接口与归一化设计
  3. ASP.NET Core 动作结果 - ASP.NET Core 基础教程 - 简单教程,简单编程
  4. python 中locals() 和 globals()的区别
  5. 牛客练习赛39 B 选点(dfs序+LIS)
  6. 在鼠标右键菜单栏添加notepad++打开方式
  7. 实现了某一个接口的匿名类的例子_“全栈2019”Java多线程第三章:创建多线程之实现Runnable接口...
  8. rpc调用过程原理分析以及Dubbo、Feign调用过程
  9. python结课总结_Python课程学习总结
  10. SAP 信息记录条件 无法维护多个条件
  11. 磁阻随机存储器(MRAM)市场现状研究分析与发展前景预测报告
  12. 接口测试-post常见数据提交方式
  13. 电商数据分析指标体系
  14. 利用Python+opencv模块的dnn实现Faster R-CNN(一)
  15. python在线课程价格-python课程价格
  16. 记一次服务器被入侵,没想到我轻松搞定了它~
  17. S5PV210Kernel移植6之什么是进程,线程?
  18. 中文字符串的编码转换 UTF-8//GBK
  19. SiWave安装问题
  20. Python 实现八个概率分布公式及可视化

热门文章

  1. 无需支付688苹果开发者账号,xcode打包导出ipa,提供他人进行内测
  2. “驱动程序在 \Device\Harddisk0\D 上检测到控制器错误”的根本解决办法!
  3. f和摄氏度怎么换算_华氏度和摄氏度的换算
  4. AI 算法工程师面试高频 100 题(附答案详解)
  5. Win10安装注册机出错?
  6. 微信小程序服务通知开发
  7. html 鼠标右击事件,鼠标右击事件(练习)
  8. 测试鼠标手速的软件,APMTrainer
  9. 阿诺德图像加密c语言,三维arnold变换图像加密算法
  10. Windows便签数据恢复