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

        }
    }
}

下载

源码下载

相关推荐
The_Ticker11 分钟前
CFD平台如何接入实时行情源
java·大数据·数据库·人工智能·算法·区块链·软件工程
Elastic 中国社区官方博客17 分钟前
Elasticsearch 开放推理 API 增加了对 IBM watsonx.ai Slate 嵌入模型的支持
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
jwolf217 分钟前
摸一下elasticsearch8的AI能力:语义搜索/vector向量搜索案例
人工智能·搜索引擎
有Li26 分钟前
跨视角差异-依赖网络用于体积医学图像分割|文献速递-生成式模型与transformer在医学影像中的应用
人工智能·计算机视觉
新加坡内哥谈技术1 小时前
Mistral推出“Le Chat”,对标ChatGPT
人工智能·chatgpt
GOTXX1 小时前
基于Opencv的图像处理软件
图像处理·人工智能·深度学习·opencv·卷积神经网络
IT古董1 小时前
【人工智能】Python在机器学习与人工智能中的应用
开发语言·人工智能·python·机器学习
CV学术叫叫兽1 小时前
快速图像识别:落叶植物叶片分类
人工智能·分类·数据挖掘
嵌入式大圣1 小时前
单片机结合OpenCV
单片机·嵌入式硬件·opencv
xrgs_shz1 小时前
MATLAB读入不同类型图像并显示图像和相关信息
图像处理·计算机视觉·matlab