, please answer thank you!!!!!! 1
In model building recently, add a module to the original model, restore the image color change, below are the results to the picture and part of the code:
The original picture:
To restore the picture
Feeling of image gray no green
Code:
X_out_branch x_spsr, x_grad=self. SPSR (XSPSR) # added module
X=F.r elu (self. Conv_merge (torch. The cat ((x, x_spsr), dim=1))) # 64
X=self. Conv_tail1 (x)
X=self. Conv_tail2 (x)
Among them:
The self. The SPSR=SPSR. SPSRNet (in_nc=3, out_nc=3, nf=64,
Nb=23, gc=32, upscale=4, norm_type=None,
Act_type='leakyrelu, mode=' CNA ', upsample_mode='upconv')
Self. Conv_merge=conv3x3 (n_feats * 2, n_feats)
Self. Conv_tail1=conv3x3 (n_feats n_feats//2)
Self. Conv_tail2=conv1x1 (n_feats//2, 3)
The class SPSRNet (nn Module) :
Def __init__ (self, in_nc out_nc, nf, nb, gc=32, upscale=4, norm_type=None, \
Act_type='leakyrelu, mode=' CNA ', upsample_mode='upconv') :
Super (SPSRNet, self) __init__ ()
N_upscale=int (math. The log (upscale, 2))
If upscale==3:
N_upscale=1
Fea_conv=biggest onv_block (in_nc, nf, kernel_size=3, norm_type=None, act_type=None)
Rb_blocks=[B.R RDB (nf, kernel_size=3, gc=32, stride=1, bias,=True, pad_type='zero', \
Norm_type=norm_type, act_type=act_type, mode='CNA') for _ in range (nb)]
LR_conv=biggest onv_block (nf, nf, kernel_size=3, norm_type=norm_type, act_type=None, mode=mode)
If upsample_mode=='upconv:
Upsample_block=B.u pconv_blcok
Elif upsample_mode=='pixelshuffle:
Upsample_block=p. ixelshuffle_block
The else:
Raise NotImplementedError (' upsample mode [} {: s] is not found '. The format (upsample_mode))
If upscale==3:
Upsampler=upsample_block (nf, nf, and 3, act_type=act_type)
The else:
Upsampler=[upsample_block (nf, nf, act_type=act_type) for _ in range (n_upscale)]
Self. HR_conv0_new=biggest onv_block (nf, nf, kernel_size=3, norm_type=None, act_type=act_type)
Self. HR_conv1_new=biggest onv_block (nf, nf, kernel_size=3, norm_type=None, act_type=None)
The self. The model=B.s equential (fea_conv, B.s hortcutBlock (B.s equential (* rb_blocks LR_conv)), \
* upsampler, self. HR_conv0_new)
Self. Get_g_nopadding=Get_gradient_nopadding ()
Self. B_fea_conv=biggest onv_block (in_nc, nf, kernel_size=3, norm_type=None, act_type=None)
Self. B_concat_1=biggest onv_block (2 * nf, nf, kernel_size=3, norm_type=None, act_type=None)
Self. B_block_1=B.R RDB (nf * 2, kernel_size=3, gc=32, stride=1, bias,=True, pad_type='zero', \
Norm_type=norm_type, act_type=act_type, mode='CNA')
Self. B_concat_2=biggest onv_block (2 * nf, nf, kernel_size=3, norm_type=None, act_type=None)
Self. B_block_2=B.R RDB (nf * 2, kernel_size=3, gc=32, stride=1, bias,=True, pad_type='zero', \
Norm_type=norm_type, act_type=act_type, mode='CNA')
Self. B_concat_3=biggest onv_block (2 * nf, nf, kernel_size=3, norm_type=None, act_type=None)
Self. B_block_3=B.R RDB (nf * 2, kernel_size=3, gc=32, stride=1, bias,=True, pad_type='zero', \
Norm_type=norm_type, act_type=act_type, mode='CNA')
Self. B_LR_conv=biggest onv_block (nf, nf, kernel_size=3, norm_type=norm_type, act_type=None, mode=mode)
If upsample_mode=='upconv:
Upsample_block=B.u pconv_blcok
Elif upsample_mode=='pixelshuffle:
Upsample_block=p. ixelshuffle_block
The else:
Raise NotImplementedError (' upsample mode [} {: s] is not found '. The format (upsample_mode))
If upscale==3:
B_upsampler=upsample_block (nf, nf, and 3, act_type=act_type)
The else:
B_upsampler=[upsample_block (nf, nf, act_type=act_type) for _ in range (n_upscale)]
B_HR_conv0=biggest onv_block (nf, nf, kernel_size=3, norm_type=None, act_type=act_type)
B_HR_conv1=biggest onv_block (nf, nf, kernel_size=3, norm_type=None, act_type=None)
Self. B_module=B.s equential (* b_upsampler b_HR_conv0 b_HR_conv1)
Self. Conv_w=biggest onv_block (nf, out_nc kernel_size=1, norm_type=None, act_type=None)
Self. F_concat=biggest onv_block (nf * 2, nf, kernel_size=3, norm_type=None, act_type=None)
Self. F_block=B.R RDB (nf * 2, kernel_size=3, gc=32, stride=1, bias,=True, pad_type='zero', \
Norm_type=norm_type, act_type=act_type, mode='CNA')
Self. F_HR_conv0=biggest onv_block (nf, nf, kernel_size=3, norm_type=None, act_type=act_type)
Def forward (self, x) :
X_grad=self. Get_g_nopadding (x)
X=self. Model [0] (x)
X, block_list=self. Model [1] (x)
X_ori=x
For I in range (5) :
X=block_list [I] (x)
X_fea1=x
For I in range (5) :
X=block_list [I + 5) (x)
X_fea2=x
For I in range (5) :
X=block_list + 10 [I] (x)
X_fea3=x
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull