本文整理汇总了Python中model.common.ResBlock方法的典型用法代码示例。如果您正苦于以下问题:Python common.ResBlock方法的具体用法?Python common.ResBlock怎么用?Python common.ResBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.common
的用法示例。
在下文中一共展示了common.ResBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(MDSR, self).__init__()
n_resblocks = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
act = nn.ReLU(True)
self.scale_idx = 0
self.url = url['r{}f{}'.format(n_resblocks, n_feats)]
self.sub_mean = common.MeanShift(args.rgb_range)
self.add_mean = common.MeanShift(args.rgb_range, sign=1)
m_head = [conv(args.n_colors, n_feats, kernel_size)]
self.pre_process = nn.ModuleList([
nn.Sequential(
common.ResBlock(conv, n_feats, 5, act=act),
common.ResBlock(conv, n_feats, 5, act=act)
) for _ in args.scale
])
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act
) for _ in range(n_resblocks)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
self.upsample = nn.ModuleList([
common.Upsampler(conv, s, n_feats, act=False) for s in args.scale
])
m_tail = [conv(n_feats, args.n_colors, kernel_size)]
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例2: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblocks = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
self.sub_mean = common.MeanShift(args.rgb_range)
self.add_mean = common.MeanShift(args.rgb_range, sign=1)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblocks)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例3: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblocks = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
# self.url = url['r{}f{}x{}'.format(n_resblocks, n_feats, scale)]
self.sub_mean = common.MeanShift(args.rgb_range)
self.add_mean = common.MeanShift(args.rgb_range, sign=1)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblocks)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例4: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, opt):
super(NET, self).__init__()
n_resblocks = opt.n_resblocks
n_feats = opt.channels
bias = opt.bias
norm_type = opt.norm_type
act_type = opt.act_type
block_type = opt.block_type
denoise = opt.denoise
scale = opt.scale
if denoise:
head = [common.ConvBlock(4, n_feats, 5, act_type=act_type, bias=True)]
else:
head = [common.ConvBlock(3, n_feats, 5, act_type=act_type, bias=True)]
if block_type.lower() == 'rrdb':
resblock = [common.RRDB(n_feats, n_feats, 3,
1, bias, norm_type, act_type, 0.2)
for _ in range(n_resblocks)]
elif block_type.lower() == 'res':
resblock = [common.ResBlock(n_feats, 3, norm_type, act_type, res_scale=1, bias=bias)
for _ in range(n_resblocks)]
else:
raise RuntimeError('block_type is not supported')
resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
up = [common.Upsampler(scale, n_feats, norm_type, act_type, bias=bias),
common.ConvBlock(n_feats, 3, 3, bias=True)]
self.model = nn.Sequential(*head, common.ShortcutBlock(nn.Sequential(*resblock)), *up)
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight)
m.weight.requires_grad = True
if m.bias is not None:
m.bias.data.zero_()
m.bias.requires_grad = True
示例5: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, opt):
super(NET, self).__init__()
n_resblocks = opt.n_resblocks
n_feats = opt.channels
bias = opt.bias
norm_type = opt.norm_type
act_type = opt.act_type
block_type = opt.block_type
denoise = opt.denoise
scale = opt.scale
if denoise:
head = [common.ConvBlock(5, n_feats, 5, act_type=act_type, bias=True)]
else:
head = [common.ConvBlock(4, n_feats, 5, act_type=act_type, bias=True)]
if block_type.lower() == 'rrdb':
resblock = [common.RRDB(n_feats, n_feats, 3,
1, bias, norm_type, act_type, 0.2)
for _ in range(n_resblocks)]
elif block_type.lower() == 'res':
resblock = [common.ResBlock(n_feats, 3, norm_type, act_type, res_scale=1, bias=bias)
for _ in range(n_resblocks)]
else:
raise RuntimeError('block_type is not supported')
resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
up = [common.Upsampler(scale*2, n_feats, norm_type, act_type, bias=bias),
common.ConvBlock(n_feats, 1, 3, bias=True)]
self.model = nn.Sequential(*head, common.ShortcutBlock(nn.Sequential(*resblock)), *up)
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight)
m.weight.requires_grad = True
if m.bias is not None:
m.bias.data.zero_()
m.bias.requires_grad = True
示例6: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, opt):
super(NET, self).__init__()
n_resblocks = opt.n_resblocks
n_feats = opt.channels
bias = opt.bias
norm_type = opt.norm_type
act_type = opt.act_type
block_type = opt.block_type
head = [common.ConvBlock(5, n_feats, 5, act_type=act_type, bias=True)]
if block_type.lower() == 'rrdb':
resblock = [common.RRDB(n_feats, n_feats, 3,
1, bias, norm_type, act_type, 0.2)
for _ in range(n_resblocks)]
elif block_type.lower() == 'res':
resblock = [common.ResBlock(n_feats, 3, norm_type, act_type, res_scale=1, bias=bias)
for _ in range(n_resblocks)]
else:
raise RuntimeError('block_type is not supported')
resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
tail = [common.Upsampler(2, n_feats, norm_type, act_type, bias=bias),
common.ConvBlock(n_feats, 1, 3, bias=True)]
self.model = nn.Sequential(*head, common.ShortcutBlock(nn.Sequential(*resblock)), *tail)
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight)
m.weight.requires_grad = True
if m.bias is not None:
m.bias.data.zero_()
m.bias.requires_grad = True
示例7: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, opt):
super(NET, self).__init__()
n_resblocks = opt.n_resblocks
n_feats = opt.channels
bias = opt.bias
norm_type = opt.norm_type
act_type = opt.act_type
block_type = opt.block_type
head = [common.ConvBlock(4, n_feats, 5, act_type=act_type, bias=True)]
if block_type.lower() == 'rrdb':
resblock = [common.RRDB(n_feats, n_feats, 3,
1, bias, norm_type, act_type, 0.2)
for _ in range(n_resblocks)]
elif block_type.lower() == 'res':
resblock = [common.ResBlock(n_feats, 3, norm_type, act_type, res_scale=1, bias=bias)
for _ in range(n_resblocks)]
else:
raise RuntimeError('block_type is not supported')
resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
tail = [common.ConvBlock(n_feats, 3, 3, bias=True)]
self.model = nn.Sequential(*head, common.ShortcutBlock(nn.Sequential(*resblock)), *tail)
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight)
m.weight.requires_grad = True
if m.bias is not None:
m.bias.data.zero_()
m.bias.requires_grad = True
示例8: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblocks = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
url_name = 'r{}f{}x{}'.format(n_resblocks, n_feats, scale)
if url_name in url:
self.url = url[url_name]
else:
self.url = None
self.sub_mean = common.MeanShift(args.rgb_range)
self.add_mean = common.MeanShift(args.rgb_range, sign=1)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblocks)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例9: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(NHR_Res32, self).__init__()
n_resblocks = args.n_resblocks
args.n_resblocks = args.n_resblocks - args.n_resblocks_ft
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
tail_ft2 = [
common.ResBlock(
conv, n_feats+4, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(args.n_resblocks_ft)
]
tail_ft2.append(conv(n_feats+4, args.n_colors, kernel_size))
tail_ft1 = [
common.Upsampler(conv, scale, n_feats, act=False),
]
premodel = EDSR(args)
self.sub_mean = premodel.sub_mean
self.head = premodel.head
body = premodel.body
body_child = list(body.children())
body_ft = [body_child.pop()]
self.body = nn.Sequential(*body_child)
self.body_ft = nn.Sequential(*body_ft)
self.tail_ft1 = nn.Sequential(*tail_ft1)
self.tail_ft2 = nn.Sequential(*tail_ft2)
self.add_mean = premodel.add_mean
args.n_resblocks = n_resblocks
# self.premodel = EDSR(args)
# from IPython import embed; embed(); exit()
示例10: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblock = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
rgb_mean = (0.4488, 0.4371, 0.4040)
rgb_std = (1.0, 1.0, 1.0)
self.sub_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblock)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
self.add_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std, 1)
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
# from IPython import embed; embed(); exit()
示例11: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblock = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
rgb_mean = (0.4488, 0.4371, 0.4040)
rgb_std = (1.0, 1.0, 1.0)
self.sub_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblock)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
nn.Conv2d(
n_feats, args.n_colors, kernel_size,
padding=(kernel_size//2)
)
]
self.add_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std, 1)
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例12: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblock = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
rgb_mean = (0.4488, 0.4371, 0.4040)
rgb_std = (1.0, 1.0, 1.0)
self.sub_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
m_body = [
common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale
) for _ in range(n_resblock)
]
m_body.append(conv(n_feats, n_feats, kernel_size))
# define tail module
m_tail = [
common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
self.add_mean = common.MeanShift(args.rgb_range, rgb_mean, rgb_std, 1)
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例13: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, args, conv=common.default_conv):
super(EDSR, self).__init__()
n_resblocks = args.n_resblocks
n_feats = args.n_feats
kernel_size = 3
scale = args.scale[0]
act = nn.ReLU(True)
# self.url = url['r{}f{}x{}'.format(n_resblocks, n_feats, scale)]
self.sub_mean = common.MeanShift(args.rgb_range)
self.add_mean = common.MeanShift(args.rgb_range, sign=1)
# define head module
m_head = [conv(args.n_colors, n_feats, kernel_size)]
# define body module
self.m_body0 = common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample0 = conv(n_feats, n_feats//4, 1)
self.m_body1 = common.ResBlock(
conv, n_feats//4, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample1 = conv(n_feats//4, n_feats, 1)
# self.tail1 = conv(n_feats//4, n_feats//16, kernel_size)
self.m_body2 = common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample2 = conv(n_feats, n_feats//4, 1)
self.m_body3 = common.ResBlock(
conv, n_feats//4, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample3 = conv(n_feats//4, n_feats, 1)
# self.tail3 = conv(n_feats//4, n_feats//16, kernel_size)
self.m_body4 = common.ResBlock(
conv, n_feats, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample4 = conv(n_feats, n_feats//4, 1)
self.m_body5 = common.ResBlock(
conv, n_feats//4, kernel_size, act=act, res_scale=args.res_scale)
self.m_downsample5 = conv(n_feats//4, n_feats, 1)
# self.tail5 = conv(n_feats//4, n_feats//16, kernel_size)
m_body = [conv(n_feats, n_feats, kernel_size)]
# define tail module
m_tail = [
# common.Upsampler(conv, scale, n_feats, act=False),
conv(n_feats, args.n_colors, kernel_size)
]
# self.refine = conv(n_feats//4, args.n_colors, kernel_size)
self.head = nn.Sequential(*m_head)
self.body = nn.Sequential(*m_body)
self.tail = nn.Sequential(*m_tail)
示例14: __init__
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def __init__(self, opt):
super(NET, self).__init__()
# parameter
denoise = opt.denoise
block_type = opt.block_type
n_feats = opt.channels
act_type = opt.act_type
bias = opt.bias
norm_type = opt.norm_type
n_resblocks = opt.n_resblocks
# architecture
if denoise:
dm_head = [common.ConvBlock(5, n_feats, 5,
act_type=act_type, bias=True)]
else:
dm_head = [common.ConvBlock(4, n_feats, 5,
act_type=act_type, bias=True)]
if block_type.lower() == 'rrdb':
dm_resblock = [common.RRDB(n_feats, n_feats, 3,
1, bias, norm_type, act_type, 0.2)
for _ in range(n_resblocks)]
elif block_type.lower() == 'res':
dm_resblock = [common.ResBlock(n_feats, 3, norm_type,
act_type, res_scale=1, bias=bias)
for _ in range(n_resblocks)]
else:
raise RuntimeError('block_type is not supported')
dm_resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
m_dm_up = [common.Upsampler(2, n_feats, norm_type, act_type, bias=bias),
common.ConvBlock(n_feats, 3, 3, bias=True)]
self.model_dm = nn.Sequential(*dm_head, common.ShortcutBlock(nn.Sequential(*dm_resblock)),
*m_dm_up)
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight)
m.weight.requires_grad = True
if m.bias is not None:
m.bias.data.zero_()
m.bias.requires_grad = True
示例15: forward
# 需要导入模块: from model import common [as 别名]
# 或者: from model.common import ResBlock [as 别名]
def forward(self, x):
x = self.model_dm(x)
return x
#
# def __init__(self, n_resblock=3, n_feats=64, denoise=True, bias=True,
# norm_type=False, act_type='relu', block_type='rrdb'):
# super(NET, self).__init__()
#
# if denoise:
# dm_head = [common.ConvBlock(5, n_feats, 5,
# act_type=act_type, bias=True)]
# else:
# dm_head = [common.ConvBlock(4, n_feats, 5,
# act_type=act_type, bias=True)]
# if block_type.lower() == 'rrdb':
# dm_resblock = [common.RRDB(n_feats, n_feats, 3,
# 1, bias, norm_type, act_type, 0.2)
# for _ in range(n_resblock)]
# elif block_type.lower() == 'res':
# dm_resblock = [common.ResBlock(n_feats, 3, norm_type,
# act_type, res_scale=1, bias=bias)
# for _ in range(n_resblock)]
# else:
# raise RuntimeError('block_type is not supported')
#
# dm_resblock += [common.ConvBlock(n_feats, n_feats, 3, bias=True)]
# m_dm_up = [common.Upsampler(2, n_feats, norm_type, act_type, bias=bias),
# common.ConvBlock(n_feats, 3, 3, bias=True)]
#
# self.model_dm = nn.Sequential(*dm_head, common.ShortcutBlock(nn.Sequential(*dm_resblock)),
# *m_dm_up)
#
# for m in self.modules():
# if isinstance(m, nn.Conv2d):
# nn.init.xavier_normal_(m.weight)
# m.weight.requires_grad = True
# if m.bias is not None:
# m.bias.data.zero_()
# m.bias.requires_grad = True
#
# def forward(self, x):
# x = self.model_dm(x)
# return x