【训练源码】
https://github.com/MaybeShewill-CV/attentive-gan-derainnet
【参考源码】
https://github.com/hpc203/attentive-gan-derainnet-onnxruntime
【算法介绍】
主要基于CVPR2018论文“单图像雨滴去除的注意生成对抗网络”,使用tensorflow实现图像去噪任务的深度卷积生成对抗网络。你可以参考他们的论文了解详情https://arxiv.org/abs/1711.10098.该模型由注意力-注意力循环网络、上下文自动编码器网络和判别网络组成。使用卷积lstm单元生成注意力图,用于帮助定位雨滴、多尺度损失和感知损失,以训练上下文自动编码器网络。感谢原始作者Rui Qian
主要网络架构如下:
可以在线体验:
https://maybeshewill-cv.github.io/attentive_derain_net
【效果展示】
【部分实现代码】
using System;
using System.Diagnostics;
using System.Windows.Forms;
using OpenCvSharp;
namespace FIRC
{
public partial class Form1 : Form
{
Mat src = null;
AGDManager dm = new AGDManager();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
src = Cv2.ImRead(openFileDialog.FileName);
pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);
}
}
private void button2_Click(object sender, EventArgs e)
{
if(pictureBox1.Image==null)
{
return;
}
var resultImg = dm.Inference(src);
pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultImg);
}
private void Form1_Load(object sender, EventArgs e)
{
dm.LoadWeights(Application.StartupPath+ "\\weights\\attentive_gan_derainnet_180x320.onnx");
}
private void button3_Click(object sender, EventArgs e)
{
VideoCapture capture = new VideoCapture(0);
if (!capture.IsOpened())
{
Console.WriteLine("video not open!");
return;
}
Mat frame = new Mat();
var sw = new Stopwatch();
int fps = 0;
while (true)
{
capture.Read(frame);
if (frame.Empty())
{
Console.WriteLine("data is empty!");
break;
}
sw.Start();
var resultImg = dm.Inference(frame);
sw.Stop();
fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);
sw.Reset();
Cv2.PutText(resultImg, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);
//显示结果
Cv2.ImShow("Result", resultImg);
int key = Cv2.WaitKey(10);
if (key == 27)
break;
}
capture.Release();
}
}
}
【测试环境】
netframework4.7.2
opencvsharp==4.8.0
onnxruntime==1.16.2
【视频演示】
【源码下载地址】