MCPcopy Create free account
hub / github.com/csxmli2016/MARCONetPlusPlus / forward

Method forward

networks/sr_arch_singlec.py:89–193  ·  view source on GitHub ↗
(self, lq, priors64, priors32, locs)

Source from the content-addressed store, hash-verified

87 )
88
89 def forward(self, lq, priors64, priors32, locs): #
90
91 lq_f_32 = self.conv_first_32(lq)
92 lq_f_16 = self.conv_first_16(lq_f_32)
93 lq_f_8 = self.conv_first_8(lq_f_16)
94
95 sq_f_16 = self.conv_body_16(torch.cat([F.interpolate(lq_f_8, scale_factor=2, mode='bilinear'), lq_f_16], dim=1))
96 sq_f_32 = self.conv_body_32(torch.cat([F.interpolate(sq_f_16, scale_factor=2, mode='bilinear'), lq_f_32], dim=1)) #
97
98
99 if priors32 is not None:
100 sq_f_32_ori = sq_f_32.clone()
101 sq_f_32_res = sq_f_32.clone().detach()*0
102 for b, p_32 in enumerate(priors32): #
103 p_32_256 = self.conv_32_to256(p_32.clone().detach())
104 for c in range(p_32_256.size(0)): #
105 center = int(locs[b][c].item()/4.0) #+ random.randint(-2,2)### no backward
106 width = 16
107
108 if center < width:
109 x1 = 0 #lq feature left
110 y1 = max(16 - center, 0)
111 else:
112 x1 = center - width
113 y1 = max(16 - width, 0)
114 # y1 = 16 - width
115 if center + width > sq_f_32.size(-1):
116 x2 = sq_f_32.size(-1) #lq feature right
117 else:
118 x2 = center + width
119 y2 = y1 + (x2 - x1)
120
121 ''&#x27;
122 center align
123 ''&#x27;
124 y1 = 16 - torch.div(x2-x1, 2, rounding_mode='trunc')
125 y2 = y1 + x2 - x1
126
127 char_prior_f = p_32_256[c:c+1, :, :, y1:y2].clone() #prior
128 char_lq_f = sq_f_32[b:b+1, :, :, x1:x2].clone()
129 adain_prior_f = adaptive_instance_normalization(char_prior_f, char_lq_f)
130 fuse_32_prior = self.conv_32_fuse(torch.cat((adain_prior_f, char_lq_f), dim=1))
131 scale = self.conv_32_scale(fuse_32_prior)
132 shift = self.conv_32_shift(fuse_32_prior)
133
134 sq_f_32_res[b, :, :, x1:x2] = sq_f_32_res[b, :, :, x1:x2] + sq_f_32[b, :, :, x1:x2].clone() * scale[0,...] + shift[0,...]
135
136 sq_pf_32_out = sq_f_32_ori + sq_f_32_res
137
138 else:
139 sq_pf_32_out = sq_f_32.clone()
140
141
142 sq_f_64 = self.conv_up(sq_pf_32_out) #64*1024
143
144
145 sq_f_64_ori = sq_f_64.clone()
146 sq_f_64_res = sq_f_64.clone().detach() * 0

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected