国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

一秒變身藝術(shù)家!U2Net 跨界肖像畫,讓你的頭像瞬間細(xì)節(jié)完美復(fù)刻,打造個(gè)性化頭像新風(fēng)潮!

這篇具有很好參考價(jià)值的文章主要介紹了一秒變身藝術(shù)家!U2Net 跨界肖像畫,讓你的頭像瞬間細(xì)節(jié)完美復(fù)刻,打造個(gè)性化頭像新風(fēng)潮!。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

效果

測(cè)試圖片來(lái)自網(wǎng)絡(luò),如有侵權(quán),聯(lián)系刪除。

一秒變身藝術(shù)家!U2Net 跨界肖像畫,讓你的頭像瞬間細(xì)節(jié)完美復(fù)刻,打造個(gè)性化頭像新風(fēng)潮!

項(xiàng)目

一秒變身藝術(shù)家!U2Net 跨界肖像畫,讓你的頭像瞬間細(xì)節(jié)完美復(fù)刻,打造個(gè)性化頭像新風(fēng)潮!

關(guān)注微信公眾號(hào),回復(fù)關(guān)鍵字:“一秒變身藝術(shù)家”,獲取程序!

模型信息

Inputs
-------------------------
name:input_image
tensor:Float[1, 3, 512, 512]
---------------------------------------------------------------

Outputs
-------------------------
name:output_image
tensor:Float[1, 1, 512, 512]
name:2016
tensor:Float[1, 1, 512, 512]
name:2017
tensor:Float[1, 1, 512, 512]
name:2018
tensor:Float[1, 1, 512, 512]
name:2019
tensor:Float[1, 1, 512, 512]
name:2020
tensor:Float[1, 1, 512, 512]
name:2021
tensor:Float[1, 1, 512, 512]
---------------------------------------------------------------

代碼

using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Windows.Forms;

namespace U2Net_Portrait
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        string startupPath;
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
        string model_path;
        Mat image;
        int modelSize = 512;

        SessionOptions options;
        InferenceSession onnx_session;
        Tensor<float> input_tensor;
        List<NamedOnnxValue> input_ontainer;
        IDisposableReadOnlyCollection<DisposableNamedOnnxValue> result_infer;
        DisposableNamedOnnxValue[] results_onnxvalue;

        Tensor<float> result_tensors;
        float[] result_array;

        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;
            }

            textBox1.Text = "";
            pictureBox2.Image = null;

            int oldwidth = image.Cols;
            int oldheight = image.Rows;

            //縮放圖片大小
            int maxEdge = Math.Max(image.Rows, image.Cols);
            float ratio = 1.0f * modelSize / maxEdge;
            int newHeight = (int)(image.Rows * ratio);
            int newWidth = (int)(image.Cols * ratio);
            Mat resize_image = image.Resize(new OpenCvSharp.Size(newWidth, newHeight));
            int width = resize_image.Cols;
            int height = resize_image.Rows;
            if (width != modelSize || height != modelSize)
            {
                resize_image = resize_image.CopyMakeBorder(0, modelSize - newHeight, 0, modelSize - newWidth, BorderTypes.Constant, new Scalar(255, 255, 255));
            }

            Cv2.CvtColor(resize_image, resize_image, ColorConversionCodes.BGR2RGB);

            for (int y = 0; y < resize_image.Height; y++)
            {
                for (int x = 0; x < resize_image.Width; x++)
                {
                    input_tensor[0, 0, y, x] = (resize_image.At<Vec3b>(y, x)[0] / 255f - 0.485f) / 0.229f;
                    input_tensor[0, 1, y, x] = (resize_image.At<Vec3b>(y, x)[1] / 255f - 0.456f) / 0.224f;
                    input_tensor[0, 2, y, x] = (resize_image.At<Vec3b>(y, x)[2] / 255f - 0.406f) / 0.225f;
                }
            }

            //將 input_tensor 放入一個(gè)輸入?yún)?shù)的容器,并指定名稱
            input_ontainer.Add(NamedOnnxValue.CreateFromTensor("input_image", input_tensor));

            dt1 = DateTime.Now;
            //運(yùn)行 Inference 并獲取結(jié)果
            result_infer = onnx_session.Run(input_ontainer);
            dt2 = DateTime.Now;

            //將輸出結(jié)果轉(zhuǎn)為DisposableNamedOnnxValue數(shù)組
            results_onnxvalue = result_infer.ToArray();

            //讀取第一個(gè)節(jié)點(diǎn)輸出并轉(zhuǎn)為Tensor數(shù)據(jù)
            result_tensors = results_onnxvalue[0].AsTensor<float>();

            result_array = result_tensors.ToArray();

            for (int i = 0; i < result_array.Length; i++)
            {
                result_array[i] = 1 - result_array[i];
            }

            float maxVal = result_array.Max();
            float minVal = result_array.Min();

            for (int i = 0; i < result_array.Length; i++)
            {
                result_array[i] = (result_array[i] - minVal) / (maxVal - minVal) * 255;
            }

            Mat result_image = new Mat(512, 512, MatType.CV_32F, result_array);

            //還原圖像大小
            if (width != modelSize || height != modelSize)
            {
                Rect rect = new Rect(0, 0, width, height);
                result_image = result_image.Clone(rect);
            }
            result_image = result_image.Resize(new OpenCvSharp.Size(oldwidth, oldheight));

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

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            startupPath = Application.StartupPath;

            model_path = startupPath + "\\model\\u2net_portrait.onnx";

            modelSize = 512;

            //創(chuàng)建輸出會(huì)話,用于輸出模型讀取信息
            options = new SessionOptions();
            options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO;

            //設(shè)置為CPU上運(yùn)行
            options.AppendExecutionProvider_CPU(0);

            //創(chuàng)建推理模型類,讀取本地模型文件
            onnx_session = new InferenceSession(model_path, options);

            //創(chuàng)建輸入容器
            input_ontainer = new List<NamedOnnxValue>();

            //輸入Tensor
            input_tensor = new DenseTensor<float>(new[] { 1, 3, 512, 512 });

        }

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

            }
        }
    }
}

參考

https://github.com/xuebinqin/U-2-Net

?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-843737.html

到了這里,關(guān)于一秒變身藝術(shù)家!U2Net 跨界肖像畫,讓你的頭像瞬間細(xì)節(jié)完美復(fù)刻,打造個(gè)性化頭像新風(fēng)潮!的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Midjourney藝術(shù)家分享|By Moebius

    Midjourney藝術(shù)家分享|By Moebius

    Moebius,本名讓·吉拉德(Jean Giraud),是一位極具影響力的法國(guó)漫畫家和插畫師,以其獨(dú)特的科幻和幻想風(fēng)格而聞名于世。他的藝術(shù)作品不僅在漫畫領(lǐng)域內(nèi)受到高度評(píng)價(jià),也為電影、時(shí)尚和廣告等多個(gè)領(lǐng)域提供了靈感。Moebius以其對(duì)細(xì)節(jié)的精細(xì)描繪和對(duì)未來(lái)世界的奇異想象而著

    2024年04月09日
    瀏覽(19)
  • AI繪畫能否超越藝術(shù)家的創(chuàng)造力?

    AI繪畫能否超越藝術(shù)家的創(chuàng)造力?

    歐盟人工智能法案對(duì) 你有什么影響?這篇文章告訴你真相 歐盟人工智能法案是什么? 歐盟人工智能法案是歐盟委員會(huì)在2021年4月發(fā)布的一份提案,旨在建立一個(gè)統(tǒng)一的人工智能監(jiān)管框架,保護(hù)人類的利益和安全,同時(shí)促進(jìn)人工智能技術(shù)的創(chuàng)新和發(fā)展。這個(gè)法案涵蓋了人工智

    2024年02月09日
    瀏覽(93)
  • 代碼生成 NFT 后,藝術(shù)家能否躺著賺錢?# Art Block 生成藝術(shù)

    代碼生成 NFT 后,藝術(shù)家能否躺著賺錢?# Art Block 生成藝術(shù)

    Mixlab NFT 藏品與藝術(shù)品有什么 區(qū)別 ?NFT 藏品/產(chǎn)品的 形式 由哪些因素影響? 小杜 NFT?藏品需要 “ 上鏈 ” 來(lái)進(jìn)行確權(quán)擔(dān)保與交易流通。“ 真品擔(dān)保 ” 是NFT 藏品與藝術(shù)品都必需的要素。而 流通性 卻是NFT 藏品區(qū)別于藝術(shù)品的 “生命性”。 知識(shí)庫(kù) 現(xiàn)實(shí)世界的藝術(shù)品自有一

    2024年02月10日
    瀏覽(21)
  • 什么是視覺特效師,我如何才能成為一名藝術(shù)家?

    什么是視覺特效師,我如何才能成為一名藝術(shù)家?

    視覺特效藝術(shù)家,也稱視覺特效師,在視覺特效流程中扮演著至關(guān)重要的角色。他們的工作是創(chuàng)造核心的視覺特效資產(chǎn),合成后形成觀眾在屏幕上享受到的視覺盛宴。 那么視覺特效師到底都做哪些工作,我們?nèi)绾尾拍艹蔀橐幻匦熌兀?來(lái)自The Mill的三位藝術(shù)家燈光和渲染總

    2023年04月08日
    瀏覽(20)
  • 【突破想象】AI繪畫能否超越藝術(shù)家的創(chuàng)造力?

    【突破想象】AI繪畫能否超越藝術(shù)家的創(chuàng)造力?

    突破人類想象!AI繪畫能否超越藝術(shù)家的創(chuàng)造力? 沖擊還是機(jī)遇?AI繪畫能否超越藝術(shù)家? 近年來(lái),AI繪畫工具迅速崛起,悄然挑戰(zhàn)著藝術(shù)家的地位。以驚人的技術(shù)發(fā)展速度,AI繪畫在藝術(shù)領(lǐng)域迅速引起轟動(dòng)。不論是國(guó)內(nèi)還是國(guó)外,涌現(xiàn)出了許多引領(lǐng)潮流的AI繪畫平臺(tái)。幾秒鐘

    2024年02月09日
    瀏覽(83)
  • Portkey——打造人人皆是藝術(shù)家的NFT市場(chǎng)

    Portkey——打造人人皆是藝術(shù)家的NFT市場(chǎng)

    毫無(wú)疑問,經(jīng)過2021年的發(fā)酵與炒作,NFT 儼然已經(jīng)成為了Web 3.0 及元宇宙領(lǐng)域的重要賽道。在2022年, XFS 不僅將會(huì)發(fā)行寅虎 NFT,更將同步打造一個(gè)人人可鏈,人人皆是藝術(shù)家的 NFT 交易市場(chǎng)——Portkey。 與國(guó)外不同的是,中國(guó)的 NFT 叫做數(shù)字藏品,盡管我國(guó)有很多企業(yè)、政府或公

    2024年02月03日
    瀏覽(19)
  • Midjourney提示詞資源、使用技巧、藝術(shù)家資源網(wǎng)站收錄

    Midjourney提示詞資源、使用技巧、藝術(shù)家資源網(wǎng)站收錄

    為了幫助藝術(shù)家們使用Midjourney更專業(yè)、準(zhǔn)確地創(chuàng)作更完美的藝術(shù)作品,我們收錄了一些Midjourney提示詞資源分享、提示詞書寫技巧、相關(guān)專業(yè)工具,同時(shí)還有一些相關(guān)藝術(shù)家資源幫藝術(shù)家們找到創(chuàng)作靈感。有很多是社區(qū)內(nèi)資深玩家分享的云文檔,資源豐富,不容錯(cuò)過。 我們收

    2024年02月09日
    瀏覽(23)
  • Python3,2分鐘掌握Doscoart庫(kù),你也能成為藝術(shù)家。

    Python3,2分鐘掌握Doscoart庫(kù),你也能成為藝術(shù)家。

    小屌絲 :魚哥,最近在忙啥? 小魚 :咱倆陌生了? 小屌絲 :何出此言? 小魚 :你說(shuō)的話又嘛意思呢? 小屌絲 :我的意思, 最近看你這整理各種資料,貌似很忙的樣子? 小魚 :我平時(shí)不也這么忙嘛 小屌絲 :魚哥, 還能正常嘮嗑嘛? 小魚 :我又沒說(shuō)不能嘮嗑。 小屌絲

    2024年02月05日
    瀏覽(30)
  • 人人都是藝術(shù)家!AI工具Doodly讓潦草手繪變精美畫作

    人人都是藝術(shù)家!AI工具Doodly讓潦草手繪變精美畫作

    AI 繪畫界太卷了,一天一個(gè)新東西,不久前剛給大家介紹了可以一秒出圖的 SDXL-Turbo ,今天來(lái)聊一聊另一位重磅選手 Doodly 有用過 Stable Diffuison 的小伙伴都知道,想要生成一張高質(zhì)量的圖片,需要輸入非常詳細(xì)的提示詞,并伴隨多次“搖色子”才能獲得滿意的結(jié)果,有沒有簡(jiǎn)

    2024年03月16日
    瀏覽(37)
  • 基于 Stable Diffusion 一鍵 AI 作畫:什么“小鎮(zhèn)做題家”?人人都是藝術(shù)家

    基于 Stable Diffusion 一鍵 AI 作畫:什么“小鎮(zhèn)做題家”?人人都是藝術(shù)家

    前文回顧:《生成式 AI:百度“文心一言”對(duì)標(biāo) ChatGPT?什么技術(shù)趨勢(shì)促使 ChatGPT 火爆全網(wǎng)?》 Hi,各位 AI 小伙伴,相信大家最近被各種 AI 作畫的消息刷屏,有沒有手癢癢的朋友也想趕緊來(lái)把自己的奇思妙想實(shí)現(xiàn)出來(lái)?機(jī)會(huì)來(lái)啦!AI Gallery 正式上線了 AI 作畫中最火的模型 “

    2023年04月08日
    瀏覽(47)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包