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();

        }
    }
}

下载

源码下载

相关推荐
ZHOU_WUYI27 分钟前
4.metagpt中的软件公司智能体 (ProjectManager 角色)
人工智能·metagpt
靴子学长1 小时前
基于字节大模型的论文翻译(含免费源码)
人工智能·深度学习·nlp
AI_NEW_COME2 小时前
知识库管理系统可扩展性深度测评
人工智能
海棠AI实验室2 小时前
AI的进阶之路:从机器学习到深度学习的演变(一)
人工智能·深度学习·机器学习
hunteritself2 小时前
AI Weekly『12月16-22日』:OpenAI公布o3,谷歌发布首个推理模型,GitHub Copilot免费版上线!
人工智能·gpt·chatgpt·github·openai·copilot
IT古董3 小时前
【机器学习】机器学习的基本分类-强化学习-策略梯度(Policy Gradient,PG)
人工智能·机器学习·分类
centurysee3 小时前
【最佳实践】Anthropic:Agentic系统实践案例
人工智能
mahuifa3 小时前
混合开发环境---使用编程AI辅助开发Qt
人工智能·vscode·qt·qtcreator·编程ai
四口鲸鱼爱吃盐3 小时前
Pytorch | 从零构建GoogleNet对CIFAR10进行分类
人工智能·pytorch·分类
蓝天星空3 小时前
Python调用open ai接口
人工智能·python