当前位置:网站首页>ACNet:用于图像超分的非对称卷积(附实现code)
ACNet:用于图像超分的非对称卷积(附实现code)
2022-07-25 07:33:00 【浪子私房菜】
https://blog.csdn.net/huohu728/article/details/115448262
class MeanShift(nn.Conv2d):
def __init__(self,
rgb_range=1.0,
rgb_mean=(0.4488, 0.4371, 0.4040),
rgb_std=(1.0, 1.0, 1.0),
sign=-1):
super(MeanShift, self).__init__(3, 3, kernel_size=1)
std = torch.Tensor(rgb_std)
self.weight.data = torch.eye(3).view(3, 3, 1, 1) / std.view(3, 1, 1, 1)
self.bias.data = sign * rgb_range * torch.Tensor(rgb_mean) / std
self.requires_grad = False
class Upsampler(nn.Sequential):
def __init__(self,
scale,
channels,
bn=False,
act=False,
bias=True):
m = []
if (scale & (scale - 1)) == 0:
for _ in range(int(math.log(scale, 2))):
m.append(nn.Conv2d(channels, 4 * channels, 3, 1, 1, bias=bias))
m.append(nn.PixelShuffle(2))
if bn:
m.append(nn.BatchNorm2d(channels))
if act:
m.append(nn.ReLU(inplace=True))
elif scale == 3:
m.append(nn.Conv2d(channels, 9 * channels, 3, 1, 1, bias=bias))
m.append(nn.PixelShuffle(3))
if bn:
m.append(nn.BatchNorm2d(channels))
if act:
m.append(nn.ReLU(inplace=True))
else:
raise NotImplementedError
super().__init__(*m)
class ACBlock(nn.Module):
def __init__(self, in_channels, out_channels):
super(ACBlock, self).__init__()
self.conv1x3 = nn.Conv2d(in_channels, out_channels, (1, 3), 1, (0, 1))
self.conv3x1 = nn.Conv2d(in_channels, out_channels, (3, 1), 1, (1, 0))
self.conv3x3 = nn.Conv2d(in_channels, out_channels, (3, 3), 1, (1, 1))
def forward(self, x):
conv3x1 = self.conv3x1(x)
conv1x3 = self.conv1x3(x)
conv3x3 = self.conv3x3(x)
return conv3x1 + conv1x3 + conv3x3
class ACNet(nn.Module):
def __init__(self,
scale=2,
in_channels=3,
out_channels=3,
num_features=64,
num_blocks=17,
rgb_range=1.0):
super(ACNet, self).__init__()
self.scale = scale
self.num_blocks = num_blocks
self.num_features = num_features
# pre and post process
self.sub_mean = MeanShift(rgb_range=rgb_range, sign=-1)
self.add_mena = MeanShift(rgb_range=rgb_range, sign=1)
# AB module
self.blk1 = ACBlock(in_channels, num_features)
for idx in range(1, num_blocks):
self.__setattr__(f"blk{idx+1}", nn.Sequential(nn.ReLU(inplace=True), ACBlock(num_features, num_features)))
# MEB
self.lff = nn.Sequential(
nn.ReLU(inplace=False),
Upsampler(scale, num_features),
nn.Conv2d(num_features, num_features, 3, 1, 1),
nn.ReLU(inplace=True),
nn.Conv2d(num_features, num_features, 3, 1, 1)
)
self.hff = nn.Sequential(
nn.ReLU(inplace=False),
Upsampler(scale, num_features),
nn.Conv2d(num_features, num_features, 3, 1, 1),
nn.ReLU(inplace=True),
nn.Conv2d(num_features, num_features, 3, 1, 1)
)
# HFFEB
self.fusion = nn.Sequential(
nn.ReLU(inplace=False),
nn.Conv2d(num_features, num_features, 3, 1, 1),
nn.ReLU(inplace=True),
nn.Conv2d(num_features, num_features, 3, 1, 1),
nn.ReLU(inplace=True),
nn.Conv2d(num_features, out_channels, 3, 1, 1),
)
def forward(self, x):
inputs = self.sub_mean(x)
blk1 = self.blk1(inputs)
high = blk1
tmp = blk1
for idx in range(1, self.num_blocks):
tmp = self.__getattr__(f"blk{idx+1}")(tmp)
high = high + tmp
lff = self.lff(blk1)
hff = self.hff(high)
fusion = self.fusion(lff + hff)
output = self.add_mena(fusion)
return output
边栏推荐
- 曼哈顿距离简介
- 《游戏机图鉴》:一份献给游戏玩家的回忆录
- 深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
- JS note 17: the whole process of jest project configuration of typescript project
- Gan series of confrontation generation network -- Gan principle and small case of handwritten digit generation
- 论文阅读:UNET 3+: A FULL-SCALE CONNECTED UNET FOR MEDICAL IMAGE SEGMENTATION
- 【刷题笔记】搜索旋转排序数组
- js无法获取headers中Content-Disposition
- SAP queries open Po (open purchase order)
- About gbase automatically closing the connection
猜你喜欢

leetcode刷题:动态规划06(整数拆分)

【Unity入门计划】基本概念-触发器 Trigger

J1 常用的DOS命令(P25)

曼哈顿距离简介

Luo min from qudian, prefabricate "leeks"?

Introduction to cesium

Huawei wireless device configuration wpa2-802.1x-aes security policy

全新8.6版本SEO快排系统(可源码级搭建)

How to use network installation to deploy multiple virtual servers in KVM environment

【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
随机推荐
Pads export Gerber file
for循环与if判断语句的运用
Install homebrew, NVM and verdaccio to build a private NPM warehouse
Quickly build a centralized logging platform through elk
How to do a good job in safety development?
Beijing internal promotion | Microsoft STCA recruits nlp/ir/dl research interns (remote)
BOM概述
QT6 with vs Code: compiling source code and basic configuration
Delete in elasticserach_ by_ What is the mechanism of query?
NLP hotspots from ACL 2022 onsite experience
Line generation (matrix ')
A domestic open source redis visualization tool that is super easy to use, with a high-value UI, which is really fragrant!!
Incremental crawler in distributed crawler
About gbase automatically closing the connection
[programmer 2 Civil Servant] III. resource collection
List derivation
华为无线设备STA黑白名单配置命令
js无法获取headers中Content-Disposition
华为无线设备配置WPA2-802.1X-AES安全策略
Bingbing's learning notes: classes and objects (Part 1)