LaMa Image Inpainting 图像修复 OpenVINO Demo

LaMa Image Inpainting 图像修复 OpenVINO Demo

目录

介绍

效果

模型信息

项目

代码

下载


介绍

gihub地址:GitHub - advimman/lama: 🦙 LaMa Image Inpainting, Resolution-robust Large Mask Inpainting with Fourier Convolutions, WACV 2022

🦙 LaMa Image Inpainting, Resolution-robust Large Mask Inpainting with Fourier Convolutions, WACV 2022

效果

模型信息

OVVersion { BuildNumber = 2023.1.0-12185-9e6b00e51cd-releases/2023/1, Description = OpenVINO Runtime }


本机可用设备

CPU

GNA

GPU


Inputs


name:image

tensor:F32[1, 3, 1000, 1504]

name:mask

tensor:F32[1, 1, 1000, 1504]


Outputs


name:inpainted

tensor:F32[1, 1000, 1504, 3]


项目

代码

using OpenCvSharp;

using Sdcb.OpenVINO;

using System;

using System.Diagnostics;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace LaMa_Image_Inpainting_图像修复_OpenVINO_Demo

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

string image_path = "";

string image_mask_path = "";

string model_path;

Mat image;

Mat image_mask;

StringBuilder sb = new StringBuilder();

Model rawModel;

PrePostProcessor pp;

Model m;

CompiledModel cm;

InferRequest ir;

private void button2_Click(object sender, EventArgs e)

{

if (pictureBox1.Image == null)

{

return;

}

pictureBox2.Image = null;

textBox1.Text = "";

sb.Clear();

Application.DoEvents();

image = new Mat(image_path);

int w = image.Width;

int h = image.Height;

image_mask = new Mat(image_mask_path);

Stopwatch stopwatch = new Stopwatch();

stopwatch.Start();

float[] input_tensor_data, input_mask_data;

Common.Preprocess(image, image_mask, out input_tensor_data, out input_mask_data);

Tensor input_tensor = Tensor.FromArray(input_tensor_data, new Shape(1, 3, 1000, 1504));

Tensor input_tensor_mask = Tensor.FromArray(input_mask_data, new Shape(1, 1, 1000, 1504));

ir.Inputs[0] = input_tensor;

ir.Inputs[1] = input_tensor_mask;

double preprocessTime = stopwatch.Elapsed.TotalMilliseconds;

stopwatch.Restart();

ir.Run();

double inferTime = stopwatch.Elapsed.TotalMilliseconds;

stopwatch.Restart();

Mat result = Common.Postprocess(ir.Outputs[0], w, h);

double postprocessTime = stopwatch.Elapsed.TotalMilliseconds;

stopwatch.Stop();

double totalTime = preprocessTime + inferTime + postprocessTime;

pictureBox2.Image = new Bitmap(result.ToMemoryStream());

sb.AppendLine($"Preprocess: {preprocessTime:F2}ms");

sb.AppendLine($"Infer: {inferTime:F2}ms");

sb.AppendLine($"Postprocess: {postprocessTime:F2}ms");

sb.AppendLine($"Total: {totalTime:F2}ms");

textBox1.Text = sb.ToString();

}

private void Form1_Load(object sender, EventArgs e)

{

image_path = "test_img/test.jpg";

pictureBox1.Image = new Bitmap(image_path);

image_mask_path = "test_img/mask.jpg";

pictureBox3.Image = new Bitmap(image_mask_path);

model_path = "model/big_lama_regular_inpaint.onnx";

rawModel = OVCore.Shared.ReadModel(model_path);

pp = rawModel.CreatePrePostProcessor();

m = pp.BuildModel();

cm = OVCore.Shared.CompileModel(m, "CPU");

ir = cm.CreateInferRequest();

}

}

}

using OpenCvSharp;
using Sdcb.OpenVINO;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LaMa_Image_Inpainting_图像修复_OpenVINO_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string image_path = "";
        string image_mask_path = "";
        string model_path;
        Mat image;
        Mat image_mask;

        StringBuilder sb = new StringBuilder();

        Model rawModel;
        PrePostProcessor pp;
        Model m;
        CompiledModel cm;
        InferRequest ir;

        private void button2_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }

            pictureBox2.Image = null;
            textBox1.Text = "";
            sb.Clear();

            Application.DoEvents();

            image = new Mat(image_path);
            int w = image.Width;
            int h = image.Height;
            image_mask = new Mat(image_mask_path);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            float[] input_tensor_data, input_mask_data;

            Common.Preprocess(image, image_mask, out input_tensor_data, out input_mask_data);

            Tensor input_tensor = Tensor.FromArray(input_tensor_data, new Shape(1, 3, 1000, 1504));
            Tensor input_tensor_mask = Tensor.FromArray(input_mask_data, new Shape(1, 1, 1000, 1504));

            ir.Inputs[0] = input_tensor;
            ir.Inputs[1] = input_tensor_mask;

            double preprocessTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Restart();

            ir.Run();

            double inferTime = stopwatch.Elapsed.TotalMilliseconds;

            stopwatch.Restart();

            Mat result = Common.Postprocess(ir.Outputs[0], w, h);

            double postprocessTime = stopwatch.Elapsed.TotalMilliseconds;
            stopwatch.Stop();

            double totalTime = preprocessTime + inferTime + postprocessTime;

            pictureBox2.Image = new Bitmap(result.ToMemoryStream());
            sb.AppendLine($"Preprocess: {preprocessTime:F2}ms");
            sb.AppendLine($"Infer: {inferTime:F2}ms");
            sb.AppendLine($"Postprocess: {postprocessTime:F2}ms");
            sb.AppendLine($"Total: {totalTime:F2}ms");
            textBox1.Text = sb.ToString();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            image_path = "test_img/test.jpg";
            pictureBox1.Image = new Bitmap(image_path);

            image_mask_path = "test_img/mask.jpg";
            pictureBox3.Image = new Bitmap(image_mask_path);

            model_path = "model/big_lama_regular_inpaint.onnx";
            rawModel = OVCore.Shared.ReadModel(model_path);
            pp = rawModel.CreatePrePostProcessor();

            m = pp.BuildModel();
            cm = OVCore.Shared.CompileModel(m, "CPU");
            ir = cm.CreateInferRequest();

        }
    }
}

下载

源码下载

相关推荐
厚德云21 分钟前
Runway开放Gen-3:比Sora更好的视频模型?
人工智能·ai·云计算·视频
渡众机器人41 分钟前
自动驾驶水泥搅拌车在梁场的应用(下)
人工智能·科技·物联网·机器学习·机器人·自动驾驶·搅拌车
yuanlulu44 分钟前
在昇腾服务器上使用llama-factory对baichuan2-13b模型进行lora微调
人工智能·深度学习·lora·nlp·大语言模型·llama
易通慧谷1 小时前
金融科技在反洗钱领域的创新应用
机器学习·区块链·ai大模型·金融科技·反洗钱
CoderIsArt1 小时前
Python:一个挑选黑色棋盘的程序
python·计算机视觉
sagima_sdu1 小时前
Win11 Python3.10 安装pytorch3d
人工智能·pytorch·python
WHAT8161 小时前
【CUDA】 由GPGPU控制核心架构考虑CUDA编程中线程块的分配
开发语言·c++·人工智能·架构
小白白白又白cdllp1 小时前
Cube-Studio:开源大模型全链路一站式中台
人工智能·开源·大模型
王大锤43911 小时前
OpenCV 用mediapipe做一个虚拟鼠标
人工智能·opencv·计算机外设
Papicatch2 小时前
TensorFlow开源项目
人工智能·python·学习·开源·tensorflow