基于卷积神经网络和 Swin Transformer 的图像处理模型

server/2024/10/25 10:35:07/

实现了一个基于卷积神经网络和 Swin Transformer 的图像处理模型。该模型主要用于对输入图像进行特征提取和处理,以实现特定的图像任务,如图像增强、去噪等。
项目完整代码下载链接:https://download.csdn.net/download/huanghm88/89909179

import torch
from torch import nn
import torch.nn.functional as F
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
##**项目完整代码下载链接:https://download.csdn.net/download/huanghm88/89909179**class Convlutioanl(nn.Module):def __init__(self,  in_channel, out_channel):super(Convlutioanl, self).__init__()self.padding=(2,2,2,2)self.conv=nn.Conv2d(in_channel,out_channel,kernel_size=5,padding=0,stride=1)self.bn=nn.BatchNorm2d(out_channel)self.relu=nn.ReLU(inplace=True)def forward(self, input):out=F.pad(input,self.padding,'replicate')out=self.conv(out)out=self.bn(out)out=self.relu(out)return outclass Convlutioanl_out(nn.Module):def __init__(self,  in_channel, out_channel):super(Convlutioanl_out, self).__init__()self.conv=nn.Conv2d(in_channel,out_channel,kernel_size=1,padding=0,stride=1)self.tanh=nn.Tanh()def forward(self, input):out=self.conv(input)out=self.tanh(out)return out
class Fem(nn.Module):def __init__(self,  in_channel, out_channel):super(Fem, self).__init__()self.padding = (1, 1, 1, 1)self.conv=nn.Conv2d(in_channel,out_channel,kernel_size=3,padding=0,stride=1)self.bn=nn.BatchNorm2d(out_channel)self.relu=nn.ReLU(inplace=True)def forward(self, input):out = F.pad(input, self.padding, 'replicate')out=self.conv(out)out=self.bn(out)out=self.relu(out)out = F.pad(out, self.padding, 'replicate')out=self.conv(out)out = self.bn(out)return outclass Channel_attention(nn.Module):def __init__(self,  channel, reduction=4):super(Channel_attention, self).__init__()self.avg_pool = nn.AdaptiveAvgPool2d(1)self.fc=nn.Sequential(nn.Conv2d(channel,channel//reduction,1),nn.ReLU(inplace=True),nn.Conv2d(channel//reduction,channel,1))self.sigmoid=nn.Sigmoid()def forward(self, input):out=self.avg_pool(input)out=self.fc(out)out=self.sigmoid(out)return outclass Spatial_attention(nn.Module):def __init__(self,  channel, reduction=4):super(Spatial_attention, self).__init__()self.body=nn.Sequential(nn.Conv2d(channel, channel//reduction,3,padding=1),nn.BatchNorm2d( channel//reduction),nn.ReLU(True),nn.Conv2d(channel // reduction, 1, 3, padding=1),nn.BatchNorm2d(1),nn.Sigmoid())def forward(self, input):return self.body(input)class WindowAttention(nn.Module):def __init__(self, dim, window_size, num_heads, qkv_bias=True, qk_scale=None, attn_drop=0., proj_drop=0.):super().__init__()self.dim = dimself.window_size = window_sizeself.num_heads = num_headshead_dim = dim // num_headsself.scale = qk_scale or head_dim ** -0.5self.relative_position_bias_table = nn

http://www.ppmy.cn/server/134687.html

相关文章

Parasoft C/C++test CT 荣获TÜV SÜD认证,在安全关键应用开发与验证方面达到最佳实践标准

新闻亮点 严格而全面的认证进一步巩固了Parasoft以安全、保障和质量为优先的发展流程。 前瞻性的功能支持与开源测试框架、现代开发工作流无缝对接。 C/Ctest CT 旨在大规模自动化,将久经考验的旗舰产品的优势扩展至更广泛的测试自动化和持续合规性领域。 在北美…

【Django】增加一个自定义字段

在查询GET的结果里增加自定义字段,这个字段只展示; 这样的字段通常有:枚举类型的、外键、其它查询内容; 枚举类型 1、在models.py里枚举类型的数据通常要使用 大写的字段名称 _CHOICES 来表示; class Snort(CoreMo…

使用休眠的方式来解决电脑合盖后偶尔不能正常睡眠的问题

背景描述 用过Windows笔记本电脑的用户应该都偶尔遇到过这样的一个问题,就是电脑直接合上盖后放在包里,按道理来说应该会自动进入睡眠模式,但是等电脑再从包里拿出来时发现电脑很烫,并且已经没电了,似乎并没有进入到休…

《PP-OCRv1》论文精读:PaddleOCR是目前SOTA级别的OCR开源技术(截止2024年10月)

PP-OCR: A Practical Ultra Lightweight OCR System论文地址PP-OCRv2: Bag of Tricks for Ultra Lightweight OCR System论文地址PP-OCRv3: More Attempts for the Improvement of Ultra Lightweight OCR System论文地址PaddleOCR Github OCR工具库 43.5K个star PP-OCRv1由百度…

【贪心算法】(第十二篇)

目录 ⽆重叠区间(medium) 题目解析 讲解算法原理 编写代码 ⽤最少数量的箭引爆⽓球(medium) 题目解析 讲解算法原理 编写代码 ⽆重叠区间(medium) 题目解析 1.题目链接:. - 力扣&#…

Kafka高可用性原理深度解析

在分布式系统中,高可用(High Availability, HA)是指系统在面对硬件故障、网络分区、软件崩溃等异常情况时,仍能继续提供服务的能力。对于消息队列系统而言,高可用性尤为重要,因为它通常作为数据流通的中枢&…

远控代码的重构-远控网络编程的设计上

套路化代码 但是我们这是一个MFC工程,我们需要考虑不是所有操作都需要到main函数里面实现,有些操作可以在main函数之前完成,有些可以在main函数返回以后完成,静态全局变量满足这个需求,我们需要添加一个自己的类 编辑器细节1 添加类和添加类向导的区别,一个是添加自己的类,一…

【数据结构】队列和栈相互实现

文章目录 1.用队列实现栈2.用栈实现队列 1.用队列实现栈 这个类使用两个队列来模拟栈的行为,其中一个队列用于主要操作(queue1),另一个队列作为辅助(queue2)。通过这种方式,我们可以确保栈的后…