首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

C# OnnxRuntime Gaze-LLE 凝视目标估计,通过利用冻结的DINOv2编码器的特征来简化注视目标估计,预测一个人在场景中看的位置。

  • 25-02-19 03:42
  • 3760
  • 5248
blog.csdn.net

目录

说明

效果

​编辑模型信息

det_face.onnx

gazelle_dinov2_vitl14_inout_1x3x448x448_1xNx4.onnx

项目

代码

下载

参考


说明

github地址:https://github.com/fkryan/gazelle

This is the official implementation for Gaze-LLE, a transformer approach for estimating gaze targets that leverages the power of pretrained visual foundation models. Gaze-LLE provides a streamlined gaze architecture that learns only a lightweight gaze decoder on top of a frozen, pretrained visual encoder (DINOv2). Gaze-LLE learns 1-2 orders of magnitude fewer parameters than prior works and doesn't require any extra input modalities like depth and pose!

效果

模型信息

det_face.onnx

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

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

Outputs
-------------------------
name:448
tensor:Float[12800, 1]
name:471
tensor:Float[3200, 1]
name:494
tensor:Float[800, 1]
name:451
tensor:Float[12800, 4]
name:474
tensor:Float[3200, 4]
name:497
tensor:Float[800, 4]
name:454
tensor:Float[12800, 10]
name:477
tensor:Float[3200, 10]
name:500
tensor:Float[800, 10]
---------------------------------------------------------------

gazelle_dinov2_vitl14_inout_1x3x448x448_1xNx4.onnx

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

Inputs
-------------------------
name:image_bgr
tensor:Float[1, 3, 448, 448]
name:bboxes_x1y1x2y2
tensor:Float[1, -1, 4]
---------------------------------------------------------------

Outputs
-------------------------
name:heatmap
tensor:Float[-1, 64, 64]
name:inout
tensor:Float[-1]
---------------------------------------------------------------

项目

代码

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace Onnx_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;

        Mat image;
        Mat result_image;

        FaceDet face_det;
        GazeLLE gazelle;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
            image = new Mat(image_path);
            pictureBox2.Image = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            button2.Enabled = false;
            Application.DoEvents();

            image = new Mat(image_path);
            result_image = image.Clone();

            dt1 = DateTime.Now;
            List head_boxes = face_det.Detect(image);

            foreach (var item in head_boxes)
            {
                Rect rect = Rect.FromLTRB((int)item.xmin, (int)item.ymin, (int)item.xmax, (int)item.ymax);
                Cv2.Rectangle(result_image, rect, Scalar.Red);
            }

            List resized_heatmaps = gazelle.Predict(image, head_boxes);
            dt2 = DateTime.Now;

            DrawGaze(result_image, head_boxes, resized_heatmaps);

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";

            button2.Enabled = true;
        }

        void DrawGaze(Mat frame, List head_boxes, List heatmaps, float thr = 0.0f)
        {
            int num_box = head_boxes.Count;
            for (int i = 0; i < num_box; i++)
            {
                double max_score;
                OpenCvSharp.Point classIdPoint;
                double minVal;
                OpenCvSharp.Point minLoc;
                Cv2.MinMaxLoc(heatmaps[i], out minVal, out max_score, out minLoc, out classIdPoint);
                int cx = classIdPoint.X;
                int cy = classIdPoint.Y;
                if (max_score >= thr)
                {
                    int head_cx = (int)((head_boxes[i].xmin + head_boxes[i].xmax) * 0.5);
                    int head_cy = (int)((head_boxes[i].ymin + head_boxes[i].ymax) * 0.5);
                   
                    Cv2.ArrowedLine(frame, new OpenCvSharp.Point(head_cx, head_cy), new OpenCvSharp.Point(cx, cy), new Scalar(0, 255, 0), 2, LineTypes.AntiAlias);
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            face_det = new FaceDet("model\\det_face.onnx");
            gazelle = new GazeLLE("model\\gazelle_dinov2_vitl14_inout_1x3x448x448_1xNx4.onnx");

            image_path = "test_img\\1.jpg";
            pictureBox1.Image = new Bitmap(image_path);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (pictureBox2.Image == null)
            {
                return;
            }
            Bitmap output = new Bitmap(pictureBox2.Image);
            SaveFileDialog sdf = new SaveFileDialog();
            sdf.Title = "保存";
            sdf.Filter = "Images (*.jpg)|*.jpg|Images (*.png)|*.png|Images (*.bmp)|*.bmp|Images (*.emf)|*.emf|Images (*.exif)|*.exif|Images (*.gif)|*.gif|Images (*.ico)|*.ico|Images (*.tiff)|*.tiff|Images (*.wmf)|*.wmf";
            if (sdf.ShowDialog() == DialogResult.OK)
            {
                switch (sdf.FilterIndex)
                {
                    case 1:
                        {
                            output.Save(sdf.FileName, ImageFormat.Jpeg);
                            break;
                        }
                    case 2:
                        {
                            output.Save(sdf.FileName, ImageFormat.Png);
                            break;
                        }
                    case 3:
                        {
                            output.Save(sdf.FileName, ImageFormat.Bmp);
                            break;
                        }
                    case 4:
                        {
                            output.Save(sdf.FileName, ImageFormat.Emf);
                            break;
                        }
                    case 5:
                        {
                            output.Save(sdf.FileName, ImageFormat.Exif);
                            break;
                        }
                    case 6:
                        {
                            output.Save(sdf.FileName, ImageFormat.Gif);
                            break;
                        }
                    case 7:
                        {
                            output.Save(sdf.FileName, ImageFormat.Icon);
                            break;
                        }

                    case 8:
                        {
                            output.Save(sdf.FileName, ImageFormat.Tiff);
                            break;
                        }
                    case 9:
                        {
                            output.Save(sdf.FileName, ImageFormat.Wmf);
                            break;
                        }
                }
                MessageBox.Show("保存成功,位置:" + sdf.FileName);
            }
        }
    }
}

  1. using OpenCvSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Windows.Forms;
  7. namespace Onnx_Demo
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1()
  12. {
  13. InitializeComponent();
  14. }
  15. string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
  16. string image_path = "";
  17. DateTime dt1 = DateTime.Now;
  18. DateTime dt2 = DateTime.Now;
  19. Mat image;
  20. Mat result_image;
  21. FaceDet face_det;
  22. GazeLLE gazelle;
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. OpenFileDialog ofd = new OpenFileDialog();
  26. ofd.Filter = fileFilter;
  27. if (ofd.ShowDialog() != DialogResult.OK) return;
  28. pictureBox1.Image = null;
  29. image_path = ofd.FileName;
  30. pictureBox1.Image = new Bitmap(image_path);
  31. textBox1.Text = "";
  32. image = new Mat(image_path);
  33. pictureBox2.Image = null;
  34. }
  35. private void button2_Click(object sender, EventArgs e)
  36. {
  37. if (image_path == "")
  38. {
  39. return;
  40. }
  41. button2.Enabled = false;
  42. Application.DoEvents();
  43. image = new Mat(image_path);
  44. result_image = image.Clone();
  45. dt1 = DateTime.Now;
  46. List<Bbox> head_boxes = face_det.Detect(image);
  47. foreach (var item in head_boxes)
  48. {
  49. Rect rect = Rect.FromLTRB((int)item.xmin, (int)item.ymin, (int)item.xmax, (int)item.ymax);
  50. Cv2.Rectangle(result_image, rect, Scalar.Red);
  51. }
  52. List<Mat> resized_heatmaps = gazelle.Predict(image, head_boxes);
  53. dt2 = DateTime.Now;
  54. DrawGaze(result_image, head_boxes, resized_heatmaps);
  55. pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
  56. textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
  57. button2.Enabled = true;
  58. }
  59. void DrawGaze(Mat frame, List<Bbox> head_boxes, List<Mat> heatmaps, float thr = 0.0f)
  60. {
  61. int num_box = head_boxes.Count;
  62. for (int i = 0; i < num_box; i++)
  63. {
  64. double max_score;
  65. OpenCvSharp.Point classIdPoint;
  66. double minVal;
  67. OpenCvSharp.Point minLoc;
  68. Cv2.MinMaxLoc(heatmaps[i], out minVal, out max_score, out minLoc, out classIdPoint);
  69. int cx = classIdPoint.X;
  70. int cy = classIdPoint.Y;
  71. if (max_score >= thr)
  72. {
  73. int head_cx = (int)((head_boxes[i].xmin + head_boxes[i].xmax) * 0.5);
  74. int head_cy = (int)((head_boxes[i].ymin + head_boxes[i].ymax) * 0.5);
  75. Cv2.ArrowedLine(frame, new OpenCvSharp.Point(head_cx, head_cy), new OpenCvSharp.Point(cx, cy), new Scalar(0, 255, 0), 2, LineTypes.AntiAlias);
  76. }
  77. }
  78. }
  79. private void Form1_Load(object sender, EventArgs e)
  80. {
  81. face_det = new FaceDet("model\\det_face.onnx");
  82. gazelle = new GazeLLE("model\\gazelle_dinov2_vitl14_inout_1x3x448x448_1xNx4.onnx");
  83. image_path = "test_img\\1.jpg";
  84. pictureBox1.Image = new Bitmap(image_path);
  85. }
  86. private void button3_Click(object sender, EventArgs e)
  87. {
  88. if (pictureBox2.Image == null)
  89. {
  90. return;
  91. }
  92. Bitmap output = new Bitmap(pictureBox2.Image);
  93. SaveFileDialog sdf = new SaveFileDialog();
  94. sdf.Title = "保存";
  95. sdf.Filter = "Images (*.jpg)|*.jpg|Images (*.png)|*.png|Images (*.bmp)|*.bmp|Images (*.emf)|*.emf|Images (*.exif)|*.exif|Images (*.gif)|*.gif|Images (*.ico)|*.ico|Images (*.tiff)|*.tiff|Images (*.wmf)|*.wmf";
  96. if (sdf.ShowDialog() == DialogResult.OK)
  97. {
  98. switch (sdf.FilterIndex)
  99. {
  100. case 1:
  101. {
  102. output.Save(sdf.FileName, ImageFormat.Jpeg);
  103. break;
  104. }
  105. case 2:
  106. {
  107. output.Save(sdf.FileName, ImageFormat.Png);
  108. break;
  109. }
  110. case 3:
  111. {
  112. output.Save(sdf.FileName, ImageFormat.Bmp);
  113. break;
  114. }
  115. case 4:
  116. {
  117. output.Save(sdf.FileName, ImageFormat.Emf);
  118. break;
  119. }
  120. case 5:
  121. {
  122. output.Save(sdf.FileName, ImageFormat.Exif);
  123. break;
  124. }
  125. case 6:
  126. {
  127. output.Save(sdf.FileName, ImageFormat.Gif);
  128. break;
  129. }
  130. case 7:
  131. {
  132. output.Save(sdf.FileName, ImageFormat.Icon);
  133. break;
  134. }
  135. case 8:
  136. {
  137. output.Save(sdf.FileName, ImageFormat.Tiff);
  138. break;
  139. }
  140. case 9:
  141. {
  142. output.Save(sdf.FileName, ImageFormat.Wmf);
  143. break;
  144. }
  145. }
  146. MessageBox.Show("保存成功,位置:" + sdf.FileName);
  147. }
  148. }
  149. }
  150. }

下载

源码下载

参考

https://github.com/hpc203/Gaze-LLE-onnxrun

天天代码码天天
微信公众号
.NET 人工智能实践
注:本文转载自blog.csdn.net的天天代码码天天的文章"https://lw112190.blog.csdn.net/article/details/144559165"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top