首页 最新 热门 推荐

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

C# OnnxRuntime部署LivePortrait实现快速、高质量的人像驱动视频生成

  • 25-02-19 03:41
  • 3454
  • 9795
blog.csdn.net

目录

效果

说明

项目

模型信息

代码

下载


效果

LivePortrait实现快速、高质量的人像驱动视频生成

说明

官网地址:https://github.com/KwaiVGI/LivePortrait

代码实现参考:https://github.com/hpc203/liveportrait-onnxrun

模型下载:onnx文件在百度云盘,链接: https://pan.baidu.com/s/13wjBFRHIIyCyBsgnBOKqsw 提取码: si95

项目

模型信息

appearance_feature_extractor.onnx

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

Inputs
-------------------------
name:img
tensor:Float[1, 3, 256, 256]
---------------------------------------------------------------

Outputs
-------------------------
name:output
tensor:Float[1, 32, 16, 64, 64]
---------------------------------------------------------------

face_2dpose_106_static.onnx

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

Inputs
-------------------------
name:data
tensor:Float[1, 3, 192, 192]
---------------------------------------------------------------

Outputs
-------------------------
name:fc1
tensor:Float[1, 212]
---------------------------------------------------------------


landmark.onnx
Model Properties
-------------------------
---------------------------------------------------------------

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

Outputs
-------------------------
name:output
tensor:Float[1, 214]
name:853
tensor:Float[1, 262]
name:856
tensor:Float[1, 406]
---------------------------------------------------------------

motion_extractor.onnx
Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:img
tensor:Float[1, 3, 256, 256]
---------------------------------------------------------------

Outputs
-------------------------
name:pitch
tensor:Float[1, 66]
name:yaw
tensor:Float[1, 66]
name:roll
tensor:Float[1, 66]
name:t
tensor:Float[1, 3]
name:exp
tensor:Float[1, 63]
name:scale
tensor:Float[1, 1]
name:kp
tensor:Float[1, 63]
---------------------------------------------------------------

retinaface_det_static.onnx
Model Properties
-------------------------
---------------------------------------------------------------

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

Outputs
-------------------------
name:448
tensor:Float[8192, 1]
name:471
tensor:Float[2048, 1]
name:494
tensor:Float[512, 1]
name:451
tensor:Float[8192, 4]
name:474
tensor:Float[2048, 4]
name:497
tensor:Float[512, 4]
name:454
tensor:Float[8192, 10]
name:477
tensor:Float[2048, 10]
name:500
tensor:Float[512, 10]
---------------------------------------------------------------

stitching.onnx

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

Inputs
-------------------------
name:input
tensor:Float[1, 126]
---------------------------------------------------------------

Outputs
-------------------------
name:output
tensor:Float[1, 65]
---------------------------------------------------------------

warping_spade.onnx

Inputs
feature_3d
name: feature_3d
tensor: float32[1,32,16,64,64]
kp_driving
name: kp_driving
tensor: float32[1,21,3]
kp_source
name: kp_source
tensor: float32[1,21,3]
Outputs
name: out
tensor: float32[1,3,512,512]

代码

using LivePortraitSharp;
using OpenCvSharp;
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        string fileFilter = "图片|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string startupPath = "";
        string source_path = "";
        string video_path = "";
        string videoFilter = "视频|*.mp4;*.avi;";
        LivePortraitPipeline livePortraitPipeline;

        ///


        /// 选择静态图像
        ///

        ///
        ///
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            ofd.InitialDirectory = Application.StartupPath + "\\test";
            if (ofd.ShowDialog() != DialogResult.OK) return;

            pictureBox1.Image = null;

            source_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(source_path);
        }

        ///


        /// 驱动视频
        ///

        ///
        ///
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = videoFilter;
            ofd.InitialDirectory = Application.StartupPath + "\\test\\driving";
            if (ofd.ShowDialog() != DialogResult.OK) return;

            video_path = ofd.FileName;
            textBox1.Text = video_path;

            //读取第一帧显示
            VideoCapture vcapture = new VideoCapture(video_path);
            if (!vcapture.IsOpened())
            {
                MessageBox.Show("打开视频文件失败");
                video_path = "";
                return;
            }
            Mat frame = new Mat();
            if (vcapture.Read(frame))
            {
                pictureBox2.Image = new Bitmap(frame.ToMemoryStream());
                frame.Dispose();
            }
            else
            {
                MessageBox.Show("读取视频文件失败");
                video_path = "";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (source_path == "")
            {
                MessageBox.Show("请选择静态图");
                return;
            }

            if (video_path == "")
            {
                MessageBox.Show("请选择驱动视频");
                return;
            }

            bool saveDetVideo = false;
            if (checkBox1.Checked)
            {
                saveDetVideo = true;
            }
            else
            {
                saveDetVideo = false;
            }

            button1.Enabled = false;
            textBox1.Text = "";
            Application.DoEvents();

            Task.Factory.StartNew(() =>
            {

                string msg;
                if (!livePortraitPipeline.execute(source_path, video_path, saveDetVideo, out msg))
                {
                    this.Invoke(new Action(() =>
                    {
                        button1.Enabled = true;
                        textBox1.Text = msg;
                    }));
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        button1.Enabled = true;
                        textBox1.Text = "执行完成!";
                    }));
                }

            }, TaskCreationOptions.LongRunning);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            livePortraitPipeline = new LivePortraitPipeline();

            source_path = "test\\0.jpg";
            pictureBox1.Image = new Bitmap(source_path);

            video_path = "test\\driving\\d0.mp4";
            //读取第一帧显示
            VideoCapture vcapture = new VideoCapture(video_path);
            if (!vcapture.IsOpened())
            {
                video_path = "";
                return;
            }
            Mat frame = new Mat();
            if (vcapture.Read(frame))
            {
                pictureBox2.Image = new Bitmap(frame.ToMemoryStream());
                frame.Dispose();
            }
            else
            {
                video_path = "";
            }
        }

    }
}

  1. using LivePortraitSharp;
  2. using OpenCvSharp;
  3. using System;
  4. using System.Drawing;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace FaceFusionSharp
  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 startupPath = "";
  17. string source_path = "";
  18. string video_path = "";
  19. string videoFilter = "视频|*.mp4;*.avi;";
  20. LivePortraitPipeline livePortraitPipeline;
  21. /// <summary>
  22. /// 选择静态图像
  23. /// </summary>
  24. /// <param name="sender"></param>
  25. /// <param name="e"></param>
  26. private void button2_Click(object sender, EventArgs e)
  27. {
  28. OpenFileDialog ofd = new OpenFileDialog();
  29. ofd.Filter = fileFilter;
  30. ofd.InitialDirectory = Application.StartupPath + "\\test";
  31. if (ofd.ShowDialog() != DialogResult.OK) return;
  32. pictureBox1.Image = null;
  33. source_path = ofd.FileName;
  34. pictureBox1.Image = new Bitmap(source_path);
  35. }
  36. /// <summary>
  37. /// 驱动视频
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. private void button3_Click(object sender, EventArgs e)
  42. {
  43. OpenFileDialog ofd = new OpenFileDialog();
  44. ofd.Filter = videoFilter;
  45. ofd.InitialDirectory = Application.StartupPath + "\\test\\driving";
  46. if (ofd.ShowDialog() != DialogResult.OK) return;
  47. video_path = ofd.FileName;
  48. textBox1.Text = video_path;
  49. //读取第一帧显示
  50. VideoCapture vcapture = new VideoCapture(video_path);
  51. if (!vcapture.IsOpened())
  52. {
  53. MessageBox.Show("打开视频文件失败");
  54. video_path = "";
  55. return;
  56. }
  57. Mat frame = new Mat();
  58. if (vcapture.Read(frame))
  59. {
  60. pictureBox2.Image = new Bitmap(frame.ToMemoryStream());
  61. frame.Dispose();
  62. }
  63. else
  64. {
  65. MessageBox.Show("读取视频文件失败");
  66. video_path = "";
  67. }
  68. }
  69. private void button1_Click(object sender, EventArgs e)
  70. {
  71. if (source_path == "")
  72. {
  73. MessageBox.Show("请选择静态图");
  74. return;
  75. }
  76. if (video_path == "")
  77. {
  78. MessageBox.Show("请选择驱动视频");
  79. return;
  80. }
  81. bool saveDetVideo = false;
  82. if (checkBox1.Checked)
  83. {
  84. saveDetVideo = true;
  85. }
  86. else
  87. {
  88. saveDetVideo = false;
  89. }
  90. button1.Enabled = false;
  91. textBox1.Text = "";
  92. Application.DoEvents();
  93. Task.Factory.StartNew(() =>
  94. {
  95. string msg;
  96. if (!livePortraitPipeline.execute(source_path, video_path, saveDetVideo, out msg))
  97. {
  98. this.Invoke(new Action(() =>
  99. {
  100. button1.Enabled = true;
  101. textBox1.Text = msg;
  102. }));
  103. }
  104. else
  105. {
  106. this.Invoke(new Action(() =>
  107. {
  108. button1.Enabled = true;
  109. textBox1.Text = "执行完成!";
  110. }));
  111. }
  112. }, TaskCreationOptions.LongRunning);
  113. }
  114. private void Form1_Load(object sender, EventArgs e)
  115. {
  116. livePortraitPipeline = new LivePortraitPipeline();
  117. source_path = "test\\0.jpg";
  118. pictureBox1.Image = new Bitmap(source_path);
  119. video_path = "test\\driving\\d0.mp4";
  120. //读取第一帧显示
  121. VideoCapture vcapture = new VideoCapture(video_path);
  122. if (!vcapture.IsOpened())
  123. {
  124. video_path = "";
  125. return;
  126. }
  127. Mat frame = new Mat();
  128. if (vcapture.Read(frame))
  129. {
  130. pictureBox2.Image = new Bitmap(frame.ToMemoryStream());
  131. frame.Dispose();
  132. }
  133. else
  134. {
  135. video_path = "";
  136. }
  137. }
  138. }
  139. }

下载

源码下载

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

/ 登录

评论记录:

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

分类栏目

后端 (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