使用OpenCVSharp Dnn部署FastestDet

FastestDet:轻量级目标检测 实时Anchor-free目标检测算法,虽然精度稍逊,但FastestDet在速度和参数量上有显著优势,适用于资源有限的设备。
FastDet项目链接:https://github.com/dog-qiuqiu/FastestDet

第一次写文章,不知道该写些什么,直接上代码吧,不足之处还望海涵

onnx模型直接使用作者给的模型 FastestDet-main/example/onnx-runtime/FastestDet.onnx,模型大小不到1MB大小,不得不说,这是真的轻量👍

模型信息
Inputs
-------------------------
name:input.1
tensor:Float[1, 3, 352, 352]
---------------------------------------------------------------

Outputs
-------------------------
name:758
tensor:Float[1, 85, 22, 22]
---------------------------------------------------------------

代码参考 FastestDet-main/example/ncnn/FastestDet.cpp

经多次测试,单次平均推理速度在15ms左右,速度是真的块

其中NMS(非极大值抑制)用的是作者给的函数,也可以使用OpenCV自带的CvDnn.NMSBoxes函数

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
using OpenCvSharp.Dnn;
using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size;


namespace OPENCV
{
    public partial class FastDetect : Form
    {
        public FastDetect()
        {
            InitializeComponent();
        }
        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        string[] class_names;
        // 阈值
        float thresh = 0.65f;
        // 模型输入宽高
        int input_width = 352;
        int input_height = 352;
        Net net;
        float Sigmoid(float x)
        {
            return (float)(1.0f / (1.0f + Math.Exp(-x)));
        }

        float Tanh(float x)
        {
            return (float)(2.0f / (1.0f + Math.Exp(-2 * x)) - 1);
        }
        private float IntersectionArea(TargetBox a, TargetBox b)
        {
            if (a.x1 > b.x2 || a.x2 < b.x1 || a.y1 > b.y2 || a.y2 < b.y1)
            {
                // no intersection
                return 0.0f;
      &n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值