(self, lq, priors64, priors32, locs)
| 97 | ) |
| 98 | |
| 99 | def forward(self, lq, priors64, priors32, locs): # |
| 100 | # lq_features:b*512*8*512 |
| 101 | # priors: 8, 16,32,64,128 |
| 102 | # locs: b*32, center+width for 128*2048 0~1 |
| 103 | # locs: b*16, center for 128*2048, 0~2048 |
| 104 | |
| 105 | |
| 106 | single_sr = True |
| 107 | |
| 108 | |
| 109 | lq_f_32 = self.conv_first_32(lq) |
| 110 | lq_f_16 = self.conv_first_16(lq_f_32) |
| 111 | lq_f_8 = self.conv_first_8(lq_f_16) |
| 112 | |
| 113 | sq_f_16 = self.conv_body_16(torch.cat([F.interpolate(lq_f_8, scale_factor=2, mode='bilinear'), lq_f_16], dim=1)) |
| 114 | sq_f_32 = self.conv_body_32(torch.cat([F.interpolate(sq_f_16, scale_factor=2, mode='bilinear'), lq_f_32], dim=1)) # 256*32*32 |
| 115 | |
| 116 | |
| 117 | if priors32 is not None: |
| 118 | sq_f_32_ori = sq_f_32.clone() |
| 119 | # sq_f_32_res = sq_f_32.clone().detach()*0 |
| 120 | prior_32_align = torch.zeros_like(sq_f_32_ori) |
| 121 | prior_32_mask = torch.zeros((sq_f_32_ori.size(0), 1, sq_f_32_ori.size(2), sq_f_32_ori.size(3)), dtype=sq_f_32_ori.dtype, layout=sq_f_32_ori.layout, device=sq_f_32_ori.device) |
| 122 | for b, p_32 in enumerate(priors32): #512*32*32, different batch |
| 123 | p_32_256 = self.conv_32_to256(p_32.clone()) |
| 124 | for c in range(p_32_256.size(0)): # |
| 125 | center = (locs[b][c].detach()/4.0).int() # |
| 126 | width = 16 |
| 127 | |
| 128 | if center < width: |
| 129 | x1 = 0 #lq feature left |
| 130 | y1 = max(16 - center, 0) |
| 131 | else: |
| 132 | x1 = center - width |
| 133 | y1 = max(16 - width, 0) |
| 134 | # y1 = 16 - width |
| 135 | if center + width > sq_f_32.size(-1): |
| 136 | x2 = sq_f_32.size(-1) #lq feature right |
| 137 | else: |
| 138 | x2 = center + width |
| 139 | y2 = y1 + (x2 - x1) |
| 140 | |
| 141 | ''' |
| 142 | center align |
| 143 | ''' |
| 144 | # y1 = 16 - torch.div(x2-x1, 2, rounding_mode='trunc') |
| 145 | y2 = y1 + x2 - x1 |
| 146 | |
| 147 | if single_sr: |
| 148 | char_prior_f = p_32_256[c:c+1, :, :, y1:y2].clone() #prior |
| 149 | char_lq_f = sq_f_32[b:b+1, :, :, x1:x2].clone() |
| 150 | adain_prior_f = adaptive_instance_normalization(char_prior_f, char_lq_f) |
| 151 | fuse_32_prior = self.conv_32_fuse(torch.cat((adain_prior_f, char_lq_f), dim=1)) |
| 152 | scale = self.conv_32_scale(fuse_32_prior) |
| 153 | shift = self.conv_32_shift(fuse_32_prior) |
| 154 | prior_32_align[b, :, :, x1:x2] = prior_32_align[b, :, :, x1:x2] + sq_f_32[b, :, :, x1:x2].clone() * scale[0,...] + shift[0,...] |
| 155 | else: |
| 156 | prior_32_align[b, :, :, x1:x2] = prior_32_align[b, :, :, x1:x2] + p_32_256[c:c+1, :, :, y1:y2].clone() |
nothing calls this directly
no test coverage detected