最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# Onnx實現(xiàn)DIS高精度圖像二類分割

 更新時間:2023年11月21日 09:05:33   作者:天天代碼碼天天  
這篇文章主要為大家詳細介紹了C# Onnx實現(xiàn)DIS高精度圖像二類分割的相關(guān)知識,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

介紹

github地址:https://github.com/xuebinqin/DIS

This is the repo for our new project Highly Accurate Dichotomous Image Segmentation

對應(yīng)的paper是ECCV2022的一篇文章《Highly Accurate Dichotomous Image Segmentation》, 跟BASNet和U2-Net都是出自同一個作者寫的。 

效果

模型信息

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

Outputs
-------------------------
name:output
tensor:Float[1, 1, 480, 640]
---------------------------------------------------------------

項目

VS2022

.net framework 4.8

OpenCvSharp 4.8

Microsoft.ML.OnnxRuntime 1.16.2

代碼

using Microsoft.ML.OnnxRuntime.Tensors;
using Microsoft.ML.OnnxRuntime;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.Drawing;
using static System.Net.Mime.MediaTypeNames;
 
namespace Onnx_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
 
        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
 
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
 
        int inpWidth;
        int inpHeight;
 
        int outHeight, outWidth;
 
        Mat image;
 
        string model_path = "";
 
        SessionOptions options;
        InferenceSession onnx_session;
        Tensor<float> input_tensor;
        Tensor<float> mask_tensor;
        List<NamedOnnxValue> input_ontainer;
 
        IDisposableReadOnlyCollection<DisposableNamedOnnxValue> result_infer;
        DisposableNamedOnnxValue[] results_onnxvalue;
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
 
            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";
 
            image_path = ofd.FileName;
            pictureBox1.Image = new System.Drawing.Bitmap(image_path);
            image = new Mat(image_path);
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // 創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();
 
            // 創(chuàng)建輸出會話
            options = new SessionOptions();
            options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;
            options.AppendExecutionProvider_CPU(0);// 設(shè)置為CPU上運行
 
            // 創(chuàng)建推理模型類,讀取本地模型文件
            model_path = "model/isnet_general_use_480x640.onnx";
 
            inpHeight = 480;
            inpWidth = 640;
 
            outHeight = 480;
            outWidth = 640;
 
            onnx_session = new InferenceSession(model_path, options);
 
            // 創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();
 
            image_path = "test_img/bike.jpg";
            pictureBox1.Image = new Bitmap(image_path);
 
        }
 
        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "檢測中,請稍等……";
            pictureBox2.Image = null;
            System.Windows.Forms.Application.DoEvents();
 
            image = new Mat(image_path);
 
            Mat resize_image = new Mat();
            Cv2.Resize(image, resize_image, new OpenCvSharp.Size(inpWidth, inpHeight));
 
            float[] input_tensor_data = new float[1 * 3 * inpWidth * inpHeight];
 
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < inpHeight; i++)
                {
                    for (int j = 0; j < inpWidth; j++)
                    {
                        float pix = ((byte*)(resize_image.Ptr(i).ToPointer()))[j * 3 + 2 - c];
                        input_tensor_data[c * inpHeight * inpWidth + i * inpWidth + j] = (float)(pix / 255.0 - 0.5);
                    }
                }
            }
 
            input_tensor = new DenseTensor<float>(input_tensor_data, new[] { 1, 3, inpHeight, inpWidth });
 
            //將 input_tensor 放入一個輸入?yún)?shù)的容器,并指定名稱
            input_ontainer.Add(NamedOnnxValue.CreateFromTensor("input", input_tensor));
 
            dt1 = DateTime.Now;
            //運行 Inference 并獲取結(jié)果
            result_infer = onnx_session.Run(input_ontainer);
            dt2 = DateTime.Now;
 
            //將輸出結(jié)果轉(zhuǎn)為DisposableNamedOnnxValue數(shù)組
            results_onnxvalue = result_infer.ToArray();
 
            float[] pred = results_onnxvalue[0].AsTensor<float>().ToArray();
 
            Mat mask = new Mat(outHeight, outWidth, MatType.CV_32FC1, pred);
            double min_value, max_value;
            Cv2.MinMaxLoc(mask, out min_value, out max_value);
 
            mask = (mask - min_value) / (max_value - min_value);
 
            mask *= 255;
            mask.ConvertTo(mask, MatType.CV_8UC1);
 
            Cv2.Resize(mask, mask, new OpenCvSharp.Size(image.Cols, image.Rows));
 
            Mat result_image = mask.Clone();
 
            if (pictureBox2.Image != null)
            {
                pictureBox2.Image.Dispose();
            }
 
            pictureBox2.Image = new System.Drawing.Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗時:" + (dt2 - dt1).TotalMilliseconds + "ms";
 
            mask.Dispose();
            image.Dispose();
            resize_image.Dispose();
            result_image.Dispose();
        }
 
        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }
 
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}

到此這篇關(guān)于C# Onnx實現(xiàn)DIS高精度圖像二類分割的文章就介紹到這了,更多相關(guān)C# Onnx圖像二類分割內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#如何給word文檔添加水印

    C#如何給word文檔添加水印

    這篇文章主要為大家詳細介紹了C#如何給word文檔添加水印的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • C#調(diào)用OpenXml合并word文檔中的表格單元格

    C#調(diào)用OpenXml合并word文檔中的表格單元格

    這篇文章主要為大家詳細介紹了C#如何調(diào)用OpenXml合并word文檔中的表格單元格,文中的示例代碼講解詳細,有需要的小伙伴可以參考一下
    2025-10-10
  • Unity實現(xiàn)游戲存檔框架

    Unity實現(xiàn)游戲存檔框架

    這篇文章主要為大家詳細介紹了Unity實現(xiàn)游戲存檔框架,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-01-01
  • 一則C#簡潔瀑布流代碼

    一則C#簡潔瀑布流代碼

    最近想實現(xiàn)數(shù)據(jù)的延遲加載,網(wǎng)上找一下有很多例子,看了Masonry的例子啟發(fā),自己寫了一個很簡潔的代碼。分享給大家
    2014-06-06
  • C#獲取所有進程的方法

    C#獲取所有進程的方法

    在本篇文章里小編給大家分享了關(guān)于C#獲取所有進程的方法和步驟,有需要的朋友們跟著學(xué)習(xí)參考下。
    2018-12-12
  • 基于C#實現(xiàn)的敏感字檢測示例

    基于C#實現(xiàn)的敏感字檢測示例

    這篇文章主要介紹了基于C#實現(xiàn)的敏感字檢測示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • 詳解LINQ入門(下篇)

    詳解LINQ入門(下篇)

    這篇文章主要介紹了詳解LINQ入門(下篇),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • C#中的位操作小結(jié)

    C#中的位操作小結(jié)

    在C#中位操作同C的位操作沒有什么區(qū)別,位操作的速度相對較快,而且如果熟練的話,處理起來也相對方便,特別是在一些權(quán)限等相關(guān)的設(shè)置中
    2014-01-01
  • c#分頁顯示服務(wù)器上指定目錄下的所有圖片示例

    c#分頁顯示服務(wù)器上指定目錄下的所有圖片示例

    這篇文章主要介紹了c#分頁顯示服務(wù)器上指定目錄下的所有圖片示例,需要的朋友可以參考下
    2014-05-05
  • C#中foreach實現(xiàn)原理詳解

    C#中foreach實現(xiàn)原理詳解

    這篇文章主要為大家詳細介紹了C#中foreach實現(xiàn)原理,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09

最新評論

呼和浩特市| 平湖市| 泗阳县| 荃湾区| 永修县| 荔浦县| 武陟县| 比如县| 余姚市| 漳平市| 晋宁县| 克东县| 当阳市| 怀柔区| 大厂| 桃源县| 商水县| 当涂县| 泽库县| 兖州市| 嘉黎县| 托里县| 滕州市| 台湾省| 义马市| 遂宁市| 洪湖市| 大渡口区| 新和县| 阿拉尔市| 广昌县| 长岭县| 泸溪县| 安图县| 民勤县| 衢州市| 景泰县| 时尚| 三江| 庐江县| 恩平市|