大连网站开发工资,长沙品牌设计,做艺术教育类网站如何申请,flash网站模板下载基于深度学习的图像去雨去雾 文末附有源码下载地址 b站视频地址#xff1a;
https://www.bilibili.com/video/BV1Jr421p7cT/ 基于深度学习的图像去雨去雾#xff0c;使用的网络为unet#xff0c; 网络代码#xff1a;
import torch
import torch.nn as nn
from torchsumm… 基于深度学习的图像去雨去雾 文末附有源码下载地址 b站视频地址
https://www.bilibili.com/video/BV1Jr421p7cT/ 基于深度学习的图像去雨去雾使用的网络为unet 网络代码
import torch
import torch.nn as nn
from torchsummary import summary
from torchvision import models
from torchvision.models.feature_extraction import create_feature_extractor
import torch.nn.functional as F
from torchstat import statclass Resnet18(nn.Module):def __init__(self):super(Resnet18, self).__init__()self.resnet models.resnet18(pretrainedFalse)# self.resnet create_feature_extractor(self.resnet, {relu: feat320, layer1: feat160, layer2: feat80,# layer3: feat40})def forward(self,x):for name,m in self.resnet._modules.items():xm(x)if namerelu:x1xelif namelayer1:x2xelif namelayer2:x3xelif namelayer3:x4xbreak# xself.resnet(x)return x1,x2,x3,x4
class Linears(nn.Module):def __init__(self,a,b):super(Linears, self).__init__()self.linear1nn.Linear(a,b)self.relu1nn.LeakyReLU()self.linear2 nn.Linear(b, a)self.sigmoidnn.Sigmoid()def forward(self,x):xself.linear1(x)xself.relu1(x)xself.linear2(x)xself.sigmoid(x)return x
class DenseNetBlock(nn.Module):def __init__(self,inplanes1,planes1,stride1):super(DenseNetBlock,self).__init__()self.conv1nn.Conv2d(inplanes,planes,3,stride,1)self.bn1 nn.BatchNorm2d(planes)self.relu1nn.LeakyReLU()self.conv2 nn.Conv2d(inplanes, planes, 3,stride,1)self.bn2 nn.BatchNorm2d(planes)self.relu2 nn.LeakyReLU()self.conv3 nn.Conv2d(inplanes, planes, 3,stride,1)self.bn3 nn.BatchNorm2d(planes)self.relu3 nn.LeakyReLU()def forward(self,x):insxxself.conv1(x)xself.bn1(x)xself.relu1(x)x self.conv2(x)x self.bn2(x)x self.relu2(x)xxinsx2self.conv3(x)x2 self.bn3(x2)x2self.relu3(x2)outinsxx2return out
class SEnet(nn.Module):def __init__(self,chs,reduction4):super(SEnet,self).__init__()self.average_pooling nn.AdaptiveAvgPool2d(output_size(1, 1))self.fc nn.Sequential(# First reduce dimension, then raise dimension.# Add nonlinear processing to fit the correlation between channelsnn.Linear(chs, chs // reduction),nn.LeakyReLU(inplaceTrue),nn.Linear(chs // reduction, chs))self.activation nn.Sigmoid()def forward(self,x):insxbatch_size, chs, h, w x.shapexself.average_pooling(x)x x.view(batch_size, chs)xself.fc(x)x x.view(batch_size,chs,1,1)return x*ins
class UAFM(nn.Module):def __init__(self):super(UAFM, self).__init__()# self.meanPool_Ctorch.max()self.attentionnn.Sequential(nn.Conv2d(4, 8, 3, 1,1),nn.LeakyReLU(),nn.Conv2d(8, 1, 1, 1),nn.Sigmoid())def forward(self,x1,x2):x1_mean_pooltorch.mean(x1,dim1)x1_max_pool,_torch.max(x1,dim1)x2_mean_pool torch.mean(x2, dim1)x2_max_pool,_ torch.max(x2, dim1)x1_mean_pooltorch.unsqueeze(x1_mean_pool,dim1)x1_max_pooltorch.unsqueeze(x1_max_pool,dim1)x2_mean_pooltorch.unsqueeze(x2_mean_pool,dim1)x2_max_pooltorch.unsqueeze(x2_max_pool,dim1)cattorch.cat((x1_mean_pool,x1_max_pool,x2_mean_pool,x2_max_pool),dim1)aself.attention(cat)outx1*ax2*(1-a)return outclass Net(nn.Module):def __init__(self):super(Net, self).__init__()self.resnet18Resnet18()self.SENetSEnet(chs256)self.UAFMUAFM()self.DenseNet1DenseNetBlock(inplanes256,planes256)self.transConv1nn.ConvTranspose2d(256,128,3,2,1,output_padding1)self.DenseNet2 DenseNetBlock(inplanes128, planes128)self.transConv2 nn.ConvTranspose2d(128, 64, 3, 2, 1, output_padding1)self.DenseNet3 DenseNetBlock(inplanes64, planes64)self.transConv3 nn.ConvTranspose2d(64, 64, 3, 2, 1, output_padding1)self.transConv4 nn.ConvTranspose2d(64, 32, 3, 2, 1, output_padding1)self.DenseNet4DenseNetBlock(inplanes32,planes32)self.outnn.Sequential(nn.Conv2d(32,3,1,1),nn.Sigmoid())def forward(self,x):下采样部分x1,x2,x3,x4self.resnet18(x)# feat320features[feat320]# feat160features[feat160]# feat80features[feat80]# feat40features[feat40]feat320x1feat160x2feat80x3feat40x4上采样部分xself.SENet(feat40)xself.DenseNet1(x)xself.transConv1(x)xself.UAFM(x,feat80)xself.DenseNet2(x)xself.transConv2(x)xself.UAFM(x,feat160)x self.DenseNet3(x)x self.transConv3(x)x self.UAFM(x, feat320)xself.transConv4(x)xself.DenseNet4(x)outself.out(x)# outtorch.concat((out,out,out),dim1)*255.return outdef freeze_backbone(self):for param in self.resnet18.parameters():param.requires_grad Falsedef unfreeze_backbone(self):for param in self.resnet18.parameters():param.requires_grad Trueif __name__ __main__:netNet()print(net)# stat(net,(3,640,640))summary(net,input_size(3,512,512),devicecpu)aatorch.ones((6,3,512,512))outnet(aa)print(out.shape)# iitorch.zeros((1,3,640,640))# outsnet(ii)# print(outs.shape)
主题界面显示及代码
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from untitled import Ui_Form
import sys
import cv2 as cv
from PyQt5.QtCore import QCoreApplication
import numpy as np
from PyQt5 import QtCore,QtGui
from PIL import Image
from predict import *class My(QMainWindow,Ui_Form):def __init__(self):super(My,self).__init__()self.setupUi(self)self.setWindowTitle(图像去雨去雾)self.setIcon()self.pushButton.clicked.connect(self.pic)self.pushButton_2.clicked.connect(self.pre)self.pushButton_3.clicked.connect(self.pre2)def setIcon(self):palette1 QPalette()# palette1.setColor(self.backgroundRole(), QColor(192,253,123)) # 设置背景颜色palette1.setBrush(self.backgroundRole(), QBrush(QPixmap(back.png))) # 设置背景图片self.setPalette(palette1)def pre(self):outpre(self.img,0)outself.cv_qt(out)self.label_2.setPixmap(QPixmap.fromImage(out).scaled(self.label.width(),self.label.height(),QtCore.Qt.KeepAspectRatio))def pre2(self):outpre(self.img,1)outself.cv_qt(out)self.label_2.setPixmap(QPixmap.fromImage(out).scaled(self.label.width(),self.label.height(),QtCore.Qt.KeepAspectRatio))def pic(self):imgName, imgType QFileDialog.getOpenFileName(self,打开图片,, *.png;;*.jpg;;*.jpeg;;*.bmp;;All Files (*))#KeepAspectRatiopng QtGui.QPixmap(imgName).scaled(self.label.width(),self.label.height(),QtCore.Qt.KeepAspectRatio) # 适应设计label时的大小self.label.setPixmap(png)self.imgImage.open(imgName)self.imgnp.array(self.img)def cv_qt(self, src):#src必须为bgr格式图像#src必须为bgr格式图像#src必须为bgr格式图像if len(src.shape)2:srcnp.expand_dims(src,axis-1)srcnp.tile(src,(1,1,3))h, w, d src.shapeelse:h, w, d src.shapebytesperline d * w# self.srccv.cvtColor(self.src,cv.COLOR_BGR2RGB)qt_image QImage(src.data, w, h, bytesperline, QImage.Format_RGB888).rgbSwapped()return qt_imageif __name__ __main__:QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)appQApplication(sys.argv)myMy()my.show()sys.exit(app.exec_())
项目结构 直接运行main.py即可弹出交互界面。 项目下载地址下载地址-列表第19 文章转载自: http://www.morning.kpxzq.cn.gov.cn.kpxzq.cn http://www.morning.lanyee.com.cn.gov.cn.lanyee.com.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.pgmbl.cn.gov.cn.pgmbl.cn http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.mksny.cn.gov.cn.mksny.cn http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.clpfd.cn.gov.cn.clpfd.cn http://www.morning.dbrnl.cn.gov.cn.dbrnl.cn http://www.morning.fjscr.cn.gov.cn.fjscr.cn http://www.morning.fglzk.cn.gov.cn.fglzk.cn http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.wkcl.cn.gov.cn.wkcl.cn http://www.morning.rkzb.cn.gov.cn.rkzb.cn http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.ctqbc.cn.gov.cn.ctqbc.cn http://www.morning.wyfpc.cn.gov.cn.wyfpc.cn http://www.morning.lkcqz.cn.gov.cn.lkcqz.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.hrnrx.cn.gov.cn.hrnrx.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.wfkbk.cn.gov.cn.wfkbk.cn http://www.morning.wnjrf.cn.gov.cn.wnjrf.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.zzqgc.cn.gov.cn.zzqgc.cn http://www.morning.mhmsn.cn.gov.cn.mhmsn.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.bctr.cn.gov.cn.bctr.cn http://www.morning.dybth.cn.gov.cn.dybth.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.yrdt.cn.gov.cn.yrdt.cn http://www.morning.ghrhb.cn.gov.cn.ghrhb.cn http://www.morning.iterlog.com.gov.cn.iterlog.com http://www.morning.sjpht.cn.gov.cn.sjpht.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.mhmsn.cn.gov.cn.mhmsn.cn http://www.morning.gwmny.cn.gov.cn.gwmny.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.bzlfw.cn.gov.cn.bzlfw.cn http://www.morning.njnqn.cn.gov.cn.njnqn.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.xrnh.cn.gov.cn.xrnh.cn http://www.morning.ntqqm.cn.gov.cn.ntqqm.cn http://www.morning.khpx.cn.gov.cn.khpx.cn http://www.morning.ljzgf.cn.gov.cn.ljzgf.cn http://www.morning.dglszn.com.gov.cn.dglszn.com http://www.morning.leyuhh.com.gov.cn.leyuhh.com http://www.morning.jrksk.cn.gov.cn.jrksk.cn http://www.morning.kdldx.cn.gov.cn.kdldx.cn http://www.morning.mjctt.cn.gov.cn.mjctt.cn http://www.morning.lnyds.cn.gov.cn.lnyds.cn http://www.morning.qtkfp.cn.gov.cn.qtkfp.cn http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn http://www.morning.fzqfb.cn.gov.cn.fzqfb.cn http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn http://www.morning.knlyl.cn.gov.cn.knlyl.cn http://www.morning.mrxqd.cn.gov.cn.mrxqd.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.zhqfn.cn.gov.cn.zhqfn.cn http://www.morning.bsqkt.cn.gov.cn.bsqkt.cn http://www.morning.mmtbn.cn.gov.cn.mmtbn.cn http://www.morning.phlwj.cn.gov.cn.phlwj.cn http://www.morning.qmxsx.cn.gov.cn.qmxsx.cn http://www.morning.ypfw.cn.gov.cn.ypfw.cn http://www.morning.frzdt.cn.gov.cn.frzdt.cn http://www.morning.kqhlm.cn.gov.cn.kqhlm.cn http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.pzqnj.cn.gov.cn.pzqnj.cn http://www.morning.qrpdk.cn.gov.cn.qrpdk.cn http://www.morning.hbxnb.cn.gov.cn.hbxnb.cn http://www.morning.glswq.cn.gov.cn.glswq.cn http://www.morning.datadragon-auh.cn.gov.cn.datadragon-auh.cn http://www.morning.hqsnt.cn.gov.cn.hqsnt.cn