当前位置:网站首页>Acnet: asymmetric convolution for image hypersegmentation (with implementation code)
Acnet: asymmetric convolution for image hypersegmentation (with implementation code)
2022-07-25 07:36:00 【Prodigal private dishes】
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
边栏推荐
- 9 best engineering construction project management systems
- Matlab self programming series (1) -- angular distribution function
- Offline base tile, which can be used for cesium loading
- Xinku online | cnopendata shareholder information data of A-share listed companies
- Million level element optimization: real-time vector tile service based on PG and PostGIS
- 【PyTorch】最常见的view的作用
- [paper notes] effective CNN architecture design guided by visualization
- [paper notes] next vit: next generation vision transformer for efficient deployment in real industry
- A fast method of data set enhancement for deep learning
- [unity entry plan] interface Introduction (1) -scene view
猜你喜欢
![[unity introduction program] basic concept - preform prefab](/img/c6/aac7bffdf99073978f9b2f8ff15fbb.png)
[unity introduction program] basic concept - preform prefab

【Unity入门计划】基本概念-2D刚体Rigidbody 2D

Introduction to cesium

Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?

diagramscene工程难点分析

Cluster chat server: summary of project problems

Configuring WAPI certificate security policy for Huawei wireless devices

Alibaba cloud image address & Netease cloud image

Million level element optimization: real-time vector tile service based on PG and PostGIS

Pads export Gerber file
随机推荐
Robot framework mobile terminal Automation Test ----- 01 environment installation
[dynamic programming] - Knapsack model
When deep learning makes data sets, it specifies how many frames to extract an image from the long video to the specified file path
华为无线设备STA黑白名单配置命令
Robot Framework移动端自动化测试----01环境安装
[unity entry program] make my first little game
Leetcode118. Yanghui triangle
[programmer 2 Civil Servant] I. Basic Knowledge
Oracle19 adopts automatic memory management. The AWR report shows that the settings of SGA and PGA are too small?
Analysis of common classes of Servlet
Polling, interrupt, DMA and channel
【PyTorch】最常见的view的作用
Introduction to cesium
New functions of shixizhi are online. These new functions are online in June. Can you use them?
About gbase automatically closing the connection
[unity introduction program] basic concepts -2d rigid body 2D
华为无线设备配置WPA2-802.1X-AES安全策略
【Unity入门计划】基本概念-2D刚体Rigidbody 2D
【Unity入门计划】基本概念-触发器 Trigger
Room database migration