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

        }
    }
}

下载

源码下载

相关推荐
努力犯错玩AI3 分钟前
16.4B参数仅激活2.8B!Kimi-VL-A3B开源:长文本、多模态、低成本的AI全能选手
人工智能·后端·开源
Watermelo6179 分钟前
《Science》观点解读:AI无法创造真正的智能体(AI Agent)
人工智能·深度学习·神经网络·机器学习·语言模型·自然语言处理·数据挖掘
suke11 分钟前
企业级部署实操: SGLang 多节点集群部署 Qwen 系列大模型
人工智能·ai编程
灏瀚星空21 分钟前
AI 模型高效化:推理加速与训练优化的技术原理与理论解析
开发语言·人工智能·深度学习·程序人生·机器人·智慧城市·量子计算
fytianlan26 分钟前
OpenCV day5
opencv·计算机视觉
mex_wayne30 分钟前
基础学习:(6)nanoGPT
人工智能·学习·transformer
都是些老物件35 分钟前
目标检测概述
人工智能·目标检测·计算机视觉
AI大模型团团1 小时前
从基础概念到前沿应用了解机器学习
人工智能·python·随机森林·机器学习·ai·线性回归·llama
点我头像干啥1 小时前
第8节:机器学习基础 - 监督学习概念
人工智能·神经网络·学习·机器学习
yuweififi1 小时前
随手笔记-python-opencv 读取图像的顺序 与pytorch处理图像的顺序
pytorch·笔记·python·opencv