subcenter arcface学习笔记

本文是关于ArcFace学习的笔记,探讨了在PyTorch中实现ArcFace时遇到的显存问题以及torch.bmm函数的使用。通过示例解释了torch.bmm函数计算两个3D张量矩阵乘法的规则,同时也展示了不正确维度输入导致的错误情况。
摘要由CSDN通过智能技术生成

目录

有注释和调用示例:

代码2:

torch.bmm函数示例


有注释和调用示例:

https://github.com/ditwoo/kaggle-lyft-motion-prediction-autonomous-vehicles/blob/ec8be5c55f61fcc8274607de582c576f58b0485d/src/batteries/layers/arcface.py

import math

import torch
import torch.nn as nn
import torch.nn.functional as F


class ArcFace(nn.Module):
    """Implementation of
    `ArcFace: Additive Angular Margin Loss for Deep Face Recognition`_.
    .. _ArcFace\: Additive Angular Margin Loss for Deep Face Recognition:
        https://arxiv.o
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个使用OpenCvSharp实现的找圆心的函数,其中包括了对Canny边缘检测算法的调用,并对找到的边缘进行亚像素级别的分块并行计算,最终找到圆心参数: ```csharp using System; using OpenCvSharp; public static class CircleDetector { public static CircleSegment[] FindCircles(Mat image, double cannyThreshold1 = 50, double cannyThreshold2 = 200, int minRadius = 0, int maxRadius = 0, double dp = 1, int minDistance = 10) { var gray = image.CvtColor(ColorConversionCodes.BGR2GRAY); // 边缘检测 var edges = gray.Canny(cannyThreshold1, cannyThreshold2); // 进行霍夫变换检测圆形 var circles = Cv2.HoughCircles(edges, HoughMethods.Gradient, dp, minDistance, param1: cannyThreshold1, param2: cannyThreshold2, minRadius, maxRadius); // 合并找到的点 var circleSegments = new CircleSegment[circles.Length]; for (int i = 0; i < circles.Length; i++) { var circle = circles[i]; var center = new Point(circle[0], circle[1]); var radius = circle[2]; var segment = new CircleSegment(center, radius); // 亚像素级别的分块并行计算 var subpixWinSize = new Size(3, 3); var criteria = new TermCriteria(CriteriaType.MaxIter | CriteriaType.Epsilon, 20, 0.01); Cv2.Subdiv2DInsert(segment.Subdiv, new[] { center }); Cv2.Subdiv2DGetEdgeList(segment.Subdiv, out var edgeList); var points = new Point2f[edgeList.Length]; for (int j = 0; j < edgeList.Length; j++) { points[j] = edgeList[j].Pt; } var subPoints = new Point2f[points.Length]; Cv2.CornerSubPix(gray, points, subpixWinSize, new Size(-1, -1), criteria, subPoints); // 更新圆心和半径 var subCenter = new Point2f(subPoints[0].X, subPoints[0].Y); var subRadius = 0d; for (int j = 0; j < subPoints.Length; j++) { var distance = Math.Sqrt(Math.Pow(center.X - subPoints[j].X, 2) + Math.Pow(center.Y - subPoints[j].Y, 2)); if (distance > subRadius) { subRadius = distance; subCenter = new Point2f(subPoints[j].X, subPoints[j].Y); } } segment.Center = new Point(subCenter.X, subCenter.Y); segment.Radius = subRadius; circleSegments[i] = segment; } return circleSegments; } } public class CircleSegment { public Point Center { get; set; } public double Radius { get; set; } public Subdiv2D Subdiv { get; set; } public CircleSegment(Point center, double radius) { Center = center; Radius = radius; Subdiv = new Subdiv2D(new Rect(0, 0, 1000, 1000)); } } ``` 使用示例: ```csharp var image = Cv2.ImRead("test.png", ImreadModes.Color); var circles = CircleDetector.FindCircles(image); foreach (var circle in circles) { Cv2.Circle(image, circle.Center, (int)circle.Radius, Scalar.Red, 2); } Cv2.ImShow("result", image); Cv2.WaitKey(0); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值