C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!

这篇具有很好参考价值的文章主要介绍了C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!,C#人工智能实践,c#,音视频,YOWOv2,人工智能,opencv,机器学习,目标检测

C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!

目录

介绍

效果

模型信息

项目

代码

Form1.cs

YOWOv2.cs

下载


介绍

YOWOv2: A Stronger yet Efficient Multi-level Detection Framework for Real-time Spatio-temporal Action

代码实现参考

https://github.com/hpc203/YOWOv2-video-action-detect-onnxrun

训练源码

GitHub - yjh0410/YOWOv2: The second generation of YOWO action detector.

YOWOv2介绍

https://blog.csdn.net/weixin_46687145/article/details/136488363

效果

C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!,C#人工智能实践,c#,音视频,YOWOv2,人工智能,opencv,机器学习,目标检测

C# Onnx YOWOv2 视频动作检测

模型信息

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:input
tensor:Float[1, 3, 16, 224, 224]
---------------------------------------------------------------

Outputs
-------------------------
name:conf_preds0
tensor:Float[1, 784, 1]
name:conf_preds1
tensor:Float[1, 196, 1]
name:conf_preds2
tensor:Float[1, 49, 1]
name:cls_preds0
tensor:Float[1, 784, 80]
name:cls_preds1
tensor:Float[1, 196, 80]
name:cls_preds2
tensor:Float[1, 49, 80]
name:reg_preds0
tensor:Float[1, 784, 4]
name:reg_preds1
tensor:Float[1, 196, 4]
name:erg_preds2
tensor:Float[1, 49, 4]
---------------------------------------------------------------

项目

C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!,C#人工智能实践,c#,音视频,YOWOv2,人工智能,opencv,机器学习,目标检测

代码

Form1.cs

using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace C__Onnx_YOWOv2视频动作检测
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        YOWOv2 mynet = new YOWOv2("model/yowo_v2_nano_ava.onnx", "ava");
        string videopath = "";
        Mat currentFrame = new Mat();
        VideoCapture capture;

        private void button1_Click(object sender, EventArgs e)
        {

            if (videopath == "")
            {
                return;
            }

            int len_clip = mynet.len_clip;
            float vis_thresh = 0.2f;

            textBox1.Text = "正在检测,请稍后……";

            //videopath = "dataset/ucf24_demo/v_Basketball_g01_c02.mp4";
            string savepath = "result.mp4";
            VideoCapture vcapture = new VideoCapture(videopath);
            if (!vcapture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }

            VideoWriter vwriter = new VideoWriter(savepath, FourCC.X264, vcapture.Fps, new OpenCvSharp.Size(vcapture.FrameWidth, vcapture.FrameHeight));

            Mat frame = new Mat();
            List<Mat> video_clip = new List<Mat>();
            int index = 0;
            while (vcapture.Read(frame))
            {
                if (frame.Empty())
                {
                    MessageBox.Show("打开视频文件失败");
                    return;
                }

                if (video_clip.Count <= 0)
                {
                    for (int i = 0; i < len_clip; i++)
                    {
                        video_clip.Add(frame);
                    }
                }
                video_clip.Add(frame);
                video_clip.RemoveAt(0);

                if (mynet.multi_hot)
                {
                    List<Bbox> boxes = new List<Bbox>();
                    List<float> det_conf = new List<float>();
                    List<List<float>> cls_conf = new List<List<float>>();
                    List<int> keep_inds = mynet.detect_multi_hot(video_clip, boxes, det_conf, cls_conf); //keep_inds记录vector里面的有效检测框的序号

                    Mat dstimg = Common.vis_multi_hot(frame, boxes, det_conf, cls_conf, keep_inds, vis_thresh);

                    //Cv2.ImWrite("img/" + (index++).ToString() + ".jpg", dstimg);

                    vwriter.Write(dstimg);

                    dstimg.Dispose();
                }
                else
                {
                    List<Bbox> boxes = new List<Bbox>();
                    List<float> det_conf = new List<float>();
                    List<int> cls_id = new List<int>();
                    List<int> keep_inds = mynet.detect_one_hot(video_clip, boxes, det_conf, cls_id); //keep_inds记录vector里面的有效检测框的序号
                    Mat dstimg = Common.vis_one_hot(frame, boxes, det_conf, cls_id, keep_inds, vis_thresh, 0.4f);
                    vwriter.Write(dstimg);
                    dstimg.Dispose();
                }
            }
            vcapture.Release();
            vwriter.Release();
            MessageBox.Show("检测完成,点击确认后播放检测后效果!");

            textBox1.Text = "播放result.mp4";
            videopath = "result.mp4";
            capture = new VideoCapture(videopath);
            if (!capture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }
            capture.Read(currentFrame);
            if (!currentFrame.Empty())
            {
                pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                timer1.Interval = (int)(1000.0 / capture.Fps);
                timer1.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Video files MP4 files (*.mp4)|*.mp4";
            ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                videopath = ofd.FileName;
                capture = new VideoCapture(videopath);
                if (!capture.IsOpened())
                {
                    MessageBox.Show("打开视频文件失败");
                    return;
                }
                capture.Read(currentFrame);
                if (!currentFrame.Empty())
                {
                    pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                    timer1.Interval = (int)(1000.0 / capture.Fps);
                    timer1.Enabled = true;
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            capture.Read(currentFrame);
            if (currentFrame.Empty())
            {
                //pictureBox1.Image = null;
                timer1.Enabled = false;
                capture.Release();
                textBox1.Text = "播放完毕。";
                return;
            }
            pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            videopath = "dataset/ucf24_demo/v_Basketball_g01_c02.mp4";
            capture = new VideoCapture(videopath);
            if (!capture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }
            textBox1.Text = "播放v_Basketball_g01_c02.mp4";
            capture.Read(currentFrame);
            if (!currentFrame.Empty())
            {
                pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                timer1.Interval = (int)(1000.0 / capture.Fps);
                timer1.Enabled = true;
            }
        }
    }
}

using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace C__Onnx_YOWOv2视频动作检测
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        YOWOv2 mynet = new YOWOv2("model/yowo_v2_nano_ava.onnx", "ava");
        string videopath = "";
        Mat currentFrame = new Mat();
        VideoCapture capture;

        private void button1_Click(object sender, EventArgs e)
        {

            if (videopath == "")
            {
                return;
            }

            int len_clip = mynet.len_clip;
            float vis_thresh = 0.2f;

            textBox1.Text = "正在检测,请稍后……";

            //videopath = "dataset/ucf24_demo/v_Basketball_g01_c02.mp4";
            string savepath = "result.mp4";
            VideoCapture vcapture = new VideoCapture(videopath);
            if (!vcapture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }

            VideoWriter vwriter = new VideoWriter(savepath, FourCC.X264, vcapture.Fps, new OpenCvSharp.Size(vcapture.FrameWidth, vcapture.FrameHeight));

            Mat frame = new Mat();
            List<Mat> video_clip = new List<Mat>();
            int index = 0;
            while (vcapture.Read(frame))
            {
                if (frame.Empty())
                {
                    MessageBox.Show("打开视频文件失败");
                    return;
                }

                if (video_clip.Count <= 0)
                {
                    for (int i = 0; i < len_clip; i++)
                    {
                        video_clip.Add(frame);
                    }
                }
                video_clip.Add(frame);
                video_clip.RemoveAt(0);

                if (mynet.multi_hot)
                {
                    List<Bbox> boxes = new List<Bbox>();
                    List<float> det_conf = new List<float>();
                    List<List<float>> cls_conf = new List<List<float>>();
                    List<int> keep_inds = mynet.detect_multi_hot(video_clip, boxes, det_conf, cls_conf); //keep_inds记录vector里面的有效检测框的序号

                    Mat dstimg = Common.vis_multi_hot(frame, boxes, det_conf, cls_conf, keep_inds, vis_thresh);

                    //Cv2.ImWrite("img/" + (index++).ToString() + ".jpg", dstimg);

                    vwriter.Write(dstimg);

                    dstimg.Dispose();
                }
                else
                {
                    List<Bbox> boxes = new List<Bbox>();
                    List<float> det_conf = new List<float>();
                    List<int> cls_id = new List<int>();
                    List<int> keep_inds = mynet.detect_one_hot(video_clip, boxes, det_conf, cls_id); //keep_inds记录vector里面的有效检测框的序号
                    Mat dstimg = Common.vis_one_hot(frame, boxes, det_conf, cls_id, keep_inds, vis_thresh, 0.4f);
                    vwriter.Write(dstimg);
                    dstimg.Dispose();
                }
            }
            vcapture.Release();
            vwriter.Release();
            MessageBox.Show("检测完成,点击确认后播放检测后效果!");

            textBox1.Text = "播放result.mp4";
            videopath = "result.mp4";
            capture = new VideoCapture(videopath);
            if (!capture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }
            capture.Read(currentFrame);
            if (!currentFrame.Empty())
            {
                pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                timer1.Interval = (int)(1000.0 / capture.Fps);
                timer1.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Video files MP4 files (*.mp4)|*.mp4";
            ofd.InitialDirectory = Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                videopath = ofd.FileName;
                capture = new VideoCapture(videopath);
                if (!capture.IsOpened())
                {
                    MessageBox.Show("打开视频文件失败");
                    return;
                }
                capture.Read(currentFrame);
                if (!currentFrame.Empty())
                {
                    pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                    timer1.Interval = (int)(1000.0 / capture.Fps);
                    timer1.Enabled = true;
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            capture.Read(currentFrame);
            if (currentFrame.Empty())
            {
                //pictureBox1.Image = null;
                timer1.Enabled = false;
                capture.Release();
                textBox1.Text = "播放完毕。";
                return;
            }
            pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            videopath = "dataset/ucf24_demo/v_Basketball_g01_c02.mp4";
            capture = new VideoCapture(videopath);
            if (!capture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                return;
            }
            textBox1.Text = "播放v_Basketball_g01_c02.mp4";
            capture.Read(currentFrame);
            if (!currentFrame.Empty())
            {
                pictureBox1.Image = BitmapConverter.ToBitmap(currentFrame);
                timer1.Interval = (int)(1000.0 / capture.Fps);
                timer1.Enabled = true;
            }
        }
    }
}

YOWOv2.cs

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace C__Onnx_YOWOv2视频动作检测
{
    public class YOWOv2
    {
        public int len_clip;
        public bool multi_hot;

        List<float> input_tensor_data = new List<float>();

        int inpWidth;
        int inpHeight;
        float nms_thresh;
        float conf_thresh;

        int num_class;
        int topk = 40;
        int[] strides = new int[] { 8, 16, 32 };
        bool act_pose;

        SessionOptions options;
        InferenceSession onnx_session;

        public YOWOv2(string modelpath, string dataset = "ava_v2.2", float nms_thresh_ = 0.5f, float conf_thresh_ = 0.1f, bool act_pose_ = false)
        {
            // 创建输出会话,用于输出模型读取信息
            options = new SessionOptions();
            options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;
            options.AppendExecutionProvider_CPU(0);// 设置为CPU上运行

            // 创建推理模型类,读取本地模型文件
            onnx_session = new InferenceSession(modelpath, options);//model_path 为onnx模型文件的路径

            this.len_clip = 16;
            this.inpHeight = 224;
            this.inpWidth = 224;
            if (dataset == "ava_v2.2" || dataset == "ava")
            {
                this.num_class = 80;
                this.multi_hot = true;
            }
            else
            {
                this.num_class = 24;
                this.multi_hot = false;
            }
            this.conf_thresh = conf_thresh_;
            this.nms_thresh = nms_thresh_;
            this.act_pose = act_pose_;

        }

        float[] ExtractMat(Mat src)
        {
            OpenCvSharp.Size size = src.Size();
            int channels = src.Channels();
            float[] result = new float[size.Width * size.Height * channels];
            GCHandle resultHandle = default;
            try
            {
                resultHandle = GCHandle.Alloc(result, GCHandleType.Pinned);
                IntPtr resultPtr = resultHandle.AddrOfPinnedObject();
                for (int i = 0; i < channels; ++i)
                {
                    Mat cmat = new Mat(
                       src.Height, src.Width,
                       MatType.CV_32FC1,
                       resultPtr + i * size.Width * size.Height * sizeof(float));

                    Cv2.ExtractChannel(src, cmat, i);

                    cmat.Dispose();

                }
            }
            finally
            {
                resultHandle.Free();
            }

            return result;
        }

        void preprocess(List<Mat> video_clip)
        {
            input_tensor_data.Clear();

            for (int i = 0; i < this.len_clip; i++)
            {
                Mat resizeimg = new Mat();
                Cv2.Resize(video_clip[i], resizeimg, new Size(this.inpWidth, this.inpHeight));
                resizeimg.ConvertTo(resizeimg, MatType.CV_32FC3);

                var data = ExtractMat(resizeimg);

                resizeimg.Dispose();

                input_tensor_data.AddRange(data.ToList());
            }
        }

        void generate_proposal_multi_hot(int stride, float[] conf_pred, float[] cls_pred, float[] reg_pred, List<Bbox> boxes, List<float> det_conf, List<List<float>> cls_conf)
        {
            int feat_h = (int)Math.Ceiling((float)this.inpHeight / stride);
            int feat_w = (int)Math.Ceiling((float)this.inpWidth / stride);
            int area = feat_h * feat_w;
            float[] conf_pred_i = new float[area];
            for (int i = 0; i < area; i++)
            {
                conf_pred_i[i] = Common.sigmoid(conf_pred[i]);
            }
            List<int> topk_inds = Common.TopKIndex(conf_pred_i.ToList(), this.topk);
            int length = this.num_class;
            if (this.act_pose)
            {
                length = 14;
            }

            for (int i = 0; i < topk_inds.Count; i++)
            {
                int ind = topk_inds[i];
                if (conf_pred_i[ind] > this.conf_thresh)
                {
                    int row = 0, col = 0;
                    Common.ind2sub(ind, feat_w, feat_h, ref row, ref col);

                    float cx = (col + 0.5f + reg_pred[ind * 4]) * stride;
                    float cy = (row + 0.5f + reg_pred[ind * 4 + 1]) * stride;
                    float w = (float)(Math.Exp(reg_pred[ind * 4 + 2]) * stride);
                    float h = (float)(Math.Exp(reg_pred[ind * 4 + 3]) * stride);
                    boxes.Add(new Bbox((int)(cx - 0.5 * w), (int)(cy - 0.5 * h), (int)(cx + 0.5 * w), (int)(cy + 0.5 * h)));

                    det_conf.Add(conf_pred_i[ind]);

                    float[] cls_conf_i = new float[length];
                    for (int j = 0; j < length; j++)
                    {
                        cls_conf_i[j] = Common.sigmoid(cls_pred[ind * this.num_class + j]);
                    }
                    cls_conf.Add(cls_conf_i.ToList());
                }
            }
        }

        void generate_proposal_one_hot(int stride, float[] conf_pred, float[] cls_pred, float[] reg_pred, List<Bbox> boxes, List<float> det_conf, List<int> cls_id)
        {
            int feat_h = (int)Math.Ceiling((float)inpHeight / stride);
            int feat_w = (int)Math.Ceiling((float)inpWidth / stride);
            int area = feat_h * feat_w;
            float[] det_scores_i = new float[area * this.num_class];
            for (int i = 0; i < area; i++)
            {
                for (int j = 0; j < this.num_class; j++)
                {
                    det_scores_i[i * this.num_class + j] = (float)Math.Sqrt(Common.sigmoid(conf_pred[i]) * Common.sigmoid(cls_pred[i * this.num_class + j]));
                }
            }
            int num_topk = Math.Min(this.topk, area);
            List<int> topk_inds = Common.TopKIndex(det_scores_i.ToList(), num_topk);
            for (int i = 0; i < topk_inds.Count; i++)
            {
                int ind = topk_inds[i];
                if (det_scores_i[ind] > this.conf_thresh)
                {
                    det_conf.Add(det_scores_i[ind]);
                    int idx = ind % this.num_class;
                    cls_id.Add(idx);

                    int row_ind = ind / this.num_class;
                    int row = 0, col = 0;
                    Common.ind2sub(row_ind, feat_w, feat_h, ref row, ref col);
                    float cx = (col + 0.5f + reg_pred[row_ind * 4]) * stride;
                    float cy = (row + 0.5f + reg_pred[row_ind * 4 + 1]) * stride;
                    float w = (float)(Math.Exp(reg_pred[row_ind * 4 + 2]) * stride);
                    float h = (float)(Math.Exp(reg_pred[row_ind * 4 + 3]) * stride);
                    boxes.Add(new Bbox((int)(cx - 0.5 * w), (int)(cy - 0.5 * h), (int)(cx + 0.5 * w), (int)(cy + 0.5 * h)));
                }
            }
        }

        public List<int> detect_multi_hot(List<Mat> video_clip, List<Bbox> boxes, List<float> det_conf, List<List<float>> cls_conf)
        {
            if (video_clip.Count != this.len_clip)
            {
                Console.WriteLine("input frame number is not " + this.len_clip);
                throw new Exception("input frame number is not " + this.len_clip);
            }

            int origin_h = video_clip[0].Rows;
            int origin_w = video_clip[0].Cols;

            this.preprocess(video_clip);

            Tensor<float> input_tensor = new DenseTensor<float>(input_tensor_data.ToArray(), new[] { 1, 3, this.len_clip, this.inpHeight, this.inpWidth });
            List<NamedOnnxValue> input_container = new List<NamedOnnxValue>
            {
                NamedOnnxValue.CreateFromTensor("input", input_tensor)
            };

            var ort_outputs = onnx_session.Run(input_container).ToArray();

            float[] conf_preds0 = ort_outputs[0].AsTensor<float>().ToArray();
            float[] conf_preds1 = ort_outputs[1].AsTensor<float>().ToArray();
            float[] conf_preds2 = ort_outputs[2].AsTensor<float>().ToArray();
            float[] cls_preds0 = ort_outputs[3].AsTensor<float>().ToArray();
            float[] cls_preds1 = ort_outputs[4].AsTensor<float>().ToArray();
            float[] cls_preds2 = ort_outputs[5].AsTensor<float>().ToArray();
            float[] reg_preds0 = ort_outputs[6].AsTensor<float>().ToArray();
            float[] reg_preds1 = ort_outputs[7].AsTensor<float>().ToArray();
            float[] reg_preds2 = ort_outputs[8].AsTensor<float>().ToArray();

            this.generate_proposal_multi_hot(this.strides[0], conf_preds0, cls_preds0, reg_preds0, boxes, det_conf, cls_conf);
            this.generate_proposal_multi_hot(this.strides[1], conf_preds1, cls_preds1, reg_preds1, boxes, det_conf, cls_conf);
            this.generate_proposal_multi_hot(this.strides[2], conf_preds2, cls_preds2, reg_preds2, boxes, det_conf, cls_conf);

            List<int> keep_inds = Common.multiclass_nms_class_agnostic(boxes, det_conf, this.nms_thresh);

            int max_hw = Math.Max(this.inpHeight, this.inpWidth);
            float ratio_h = (float)((float)origin_h / max_hw);
            float ratio_w = (float)((float)origin_w / max_hw);
            for (int i = 0; i < keep_inds.Count; i++)
            {
                int ind = keep_inds[i];
                boxes[ind].xmin = (int)(boxes[ind].xmin * ratio_w);
                boxes[ind].ymin = (int)(boxes[ind].ymin * ratio_h);
                boxes[ind].xmax = (int)(boxes[ind].xmax * ratio_w);
                boxes[ind].ymax = (int)(boxes[ind].ymax * ratio_h);
            }
            return keep_inds;
        }

        public List<int> detect_one_hot(List<Mat> video_clip, List<Bbox> boxes, List<float> det_conf, List<int> cls_id)
        {
            if (video_clip.Count != this.len_clip)
            {
                Console.WriteLine("input frame number is not " + this.len_clip);
                throw new Exception("input frame number is not " + this.len_clip);
            }

            int origin_h = video_clip[0].Rows;
            int origin_w = video_clip[0].Cols;
            this.preprocess(video_clip);

            // 输入Tensor
            Tensor<float> input_tensor = new DenseTensor<float>(input_tensor_data.ToArray(), new[] { 1, 3, this.len_clip, this.inpHeight, this.inpWidth });
            List<NamedOnnxValue> input_container = new List<NamedOnnxValue>
            {
                //将 input_tensor 放入一个输入参数的容器,并指定名称
                NamedOnnxValue.CreateFromTensor("input", input_tensor)
            };

            var ort_outputs = onnx_session.Run(input_container).ToArray();

            float[] conf_preds0 = ort_outputs[0].AsTensor<float>().ToArray();
            float[] conf_preds1 = ort_outputs[1].AsTensor<float>().ToArray();
            float[] conf_preds2 = ort_outputs[2].AsTensor<float>().ToArray();
            float[] cls_preds0 = ort_outputs[3].AsTensor<float>().ToArray();
            float[] cls_preds1 = ort_outputs[4].AsTensor<float>().ToArray();
            float[] cls_preds2 = ort_outputs[5].AsTensor<float>().ToArray();
            float[] reg_preds0 = ort_outputs[6].AsTensor<float>().ToArray();
            float[] reg_preds1 = ort_outputs[7].AsTensor<float>().ToArray();
            float[] reg_preds2 = ort_outputs[8].AsTensor<float>().ToArray();

            this.generate_proposal_one_hot(this.strides[0], conf_preds0, cls_preds0, reg_preds0, boxes, det_conf, cls_id);
            this.generate_proposal_one_hot(this.strides[1], conf_preds1, cls_preds1, reg_preds1, boxes, det_conf, cls_id);
            this.generate_proposal_one_hot(this.strides[2], conf_preds2, cls_preds2, reg_preds2, boxes, det_conf, cls_id);

            List<int> keep_inds = Common.multiclass_nms_class_aware(boxes, det_conf, cls_id,this.nms_thresh, 24);

            int max_hw = Math.Max(this.inpHeight, this.inpWidth);
            float ratio_h = (float)((float)origin_h / max_hw);
            float ratio_w = (float)((float)origin_w / max_hw);

            for (int i = 0; i < keep_inds.Count; i++)
            {
                int ind = keep_inds[i];
                boxes[ind].xmin = (int)(boxes[ind].xmin * ratio_w);
                boxes[ind].ymin = (int)(boxes[ind].ymin * ratio_h);
                boxes[ind].xmax = (int)(boxes[ind].xmax * ratio_w);
                boxes[ind].ymax = (int)(boxes[ind].ymax * ratio_h);
            }
            return keep_inds;
        }

    }
}

下载

源码下载文章来源地址https://www.toymoban.com/news/detail-845526.html

到了这里,关于C#开发者必备!快速掌握onnxruntime实现YOWOv2视频动作检测技术!的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 猿创征文|GISER开发者必备高能武器库

           不知道现在技术全力,GISER的比例大概是多少?GIS这个领域在IT中占比比较小,从业者估计更少。但随着现在国家大力推广国家新基建,比如实景中国的建设,智慧城市的建立等等。许多的目光又聚集到了GIS这个领域,面对新需求的提出,还有物联网、大数据、人工智

    2024年02月02日
    浏览(54)
  • 独立开发者必备的29个开源React后台管理模板

    React Web应用程序开发管理后台可能非常耗时,这和设计所有前端页面一样重要。 以下是收集的近几年顶级React.js管理模板列表。 这些模板确实很有价值,使开发人员更容易构建应用程序后端的用户界面。 此外,它们将帮助您完善网站的管理后台,并克服自己制作所有UI部分的

    2024年02月07日
    浏览(77)
  • Java开发者必备:支付宝沙箱环境支付远程调试指南

    🔥 博客主页 : 小羊失眠啦. 🔖 系列专栏 : C语言 、 Linux 、 Cpolar ❤️ 感谢大家点赞👍收藏⭐评论✍️ 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。 在沙箱环境调试支付SDK的时候,往往沙箱环境部署在本地

    2024年02月08日
    浏览(44)
  • 重要!每个开发者都应该掌握的9个核心算法

    许多开发者似乎都有一个很大的误解,认为算法在编程工作中没什么用处,只是工作面试中的加分项。其实并不是这样的,成为一名有秀的开发者,极其重要的是具备算法思维能力。不仅能够复制和修改标准算法,还能够使用代码运用算法解决遇到的任何问题。 这里介绍9种

    2024年02月11日
    浏览(31)
  • 掌握 JavaScript:从初学者到高级开发者的完整指南(三)

    BOM的全称是Browser Object Model,翻译过来是浏览器对象模型。也就是JavaScript将浏览器的各个组成部分封装成了对象。我们要操作浏览器的部分功能,可以通过操作BOM对象的相关属性或者函数来完成。例如:我们想要将浏览器的地址改为 http://www.baidu.com ,我们就可以通过BOM中提供的

    2024年02月06日
    浏览(52)
  • 掌握 JavaScript:从初学者到高级开发者的完整指南(一)

    html完成了架子,css做了美化,但是网页是死的,我们需要给他注入灵魂,所以我们需要学习JavaScript,这门语言会让我们的页面能够和用户进行交互。 同样,js代码也是书写在html中的,那么html中如何引入js代码呢?主要通过下面的2种引入方式: 第一种方式 :内部脚本,将

    2024年02月07日
    浏览(52)
  • 前端开发调式必备技能F12开发者工具之Elements(元素)面板,详细图解带流程【第一部分】

    目录 一、进入浏览器开发工具的几种方式 二、Elements(元素)面板  左侧区域 右侧区域  计算样式 事件监听器 大家好!我是爷爷的茶七里香,这个名字有没有让你想起周董的歌捏?好了,废话不多说,开始今天咱们的内容:         相必是个老手都知道按键盘上的f12就

    2023年04月13日
    浏览(69)
  • Java必备技能之环境搭建篇 (linux ab压力测试),致Java开发者

    详情说明: -n在测试会话中所执行的请求个数。默认时,仅执行一个请求。请求的总数量 -c一次产生的请求个数。默认是一次一个。请求的用户量 -t测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限

    2024年04月27日
    浏览(33)
  • Three.js--》前端开发者掌握3d技术不再是梦,初识threejs

            这十年来 web 得到了快速的发展,随着 webgl 的普及,网页的表现能力越来越强大,网页上已经开始可以做出很多复杂的动画和精美的效果,还可以通过 webgl 在网页中绘制高性能的3d图形,别的不说,凡是入门程序员都离不开github这个网站,细心的人都会发现,gi

    2024年02月01日
    浏览(52)
  • 2020最新统计,年薪50万+的Android开发者所必备的知识体系架构,你都会吗?

    JVM JavaIO 注解 序列化 这块知识是现今使用者最多的,我们称之为Android2013~2016年的技术,但是,即使是这样的技术,Android开发者也往往因为网上Copy代码习惯了而导致对这块经常“使用”的代码熟悉而又陌生。 职业生涯规划 面向Android中的一切实体(高级UI+FrameWork源码) 实体

    2023年04月19日
    浏览(48)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包