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

        }
    }
}

下载

源码下载

相关推荐
冷眼看人间恩怨3 分钟前
【话题讨论】AI大模型重塑软件开发:定义、应用、优势与挑战
人工智能·ai编程·软件开发
2401_883041085 分钟前
新锐品牌电商代运营公司都有哪些?
大数据·人工智能
AI极客菌1 小时前
Controlnet作者新作IC-light V2:基于FLUX训练,支持处理风格化图像,细节远高于SD1.5。
人工智能·计算机视觉·ai作画·stable diffusion·aigc·flux·人工智能作画
阿_旭1 小时前
一文读懂| 自注意力与交叉注意力机制在计算机视觉中作用与基本原理
人工智能·深度学习·计算机视觉·cross-attention·self-attention
王哈哈^_^1 小时前
【数据集】【YOLO】【目标检测】交通事故识别数据集 8939 张,YOLO道路事故目标检测实战训练教程!
前端·人工智能·深度学习·yolo·目标检测·计算机视觉·pyqt
Power20246662 小时前
NLP论文速读|LongReward:基于AI反馈来提升长上下文大语言模型
人工智能·深度学习·机器学习·自然语言处理·nlp
数据猎手小k2 小时前
AIDOVECL数据集:包含超过15000张AI生成的车辆图像数据集,目的解决旨在解决眼水平分类和定位问题。
人工智能·分类·数据挖掘
好奇龙猫2 小时前
【学习AI-相关路程-mnist手写数字分类-win-硬件:windows-自我学习AI-实验步骤-全连接神经网络(BPnetwork)-操作流程(3) 】
人工智能·算法
沉下心来学鲁班2 小时前
复现LLM:带你从零认识语言模型
人工智能·语言模型
数据猎手小k2 小时前
AndroidLab:一个系统化的Android代理框架,包含操作环境和可复现的基准测试,支持大型语言模型和多模态模型。
android·人工智能·机器学习·语言模型