MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / autoencoder_vgg5

Class autoencoder_vgg5

script/feature/model.py:214–293  ·  view source on GitHub ↗

vgg encoder with bilinear upsampling

Source from the content-addressed store, hash-verified

212 return feat_out, x
213
214class autoencoder_vgg5(nn.Module): # 36.78 PSNR
215 ''' vgg encoder with bilinear upsampling'''
216 def __init__(self):
217 super(autoencoder_vgg5, self).__init__()
218 self.encoder = models.vgg19(pretrained=True).features
219 self.decoder = nn.Sequential(
220 # (b, 512, 14, 14)
221 nn.Conv2d(512, 512, 3, stride=1, padding=1),
222 nn.ReLU(True),
223 # (b, 512, 28, 28)
224 nn.Conv2d(512, 512, 3, stride=1, padding=1),
225 nn.ReLU(True),
226 # (b, 256, 56, 56)
227 nn.Conv2d(512, 256, 3, stride=1, padding=1),
228 nn.ReLU(True),
229 # (b, 128, 112, 112)
230 nn.Conv2d(256, 128, 3, stride=1, padding=1),
231 nn.ReLU(True),
232 # (b, 64, 224, 224)
233 nn.Conv2d(128, 64, 3, stride=1, padding=1),
234 nn.ReLU(True),
235 nn.Conv2d(64, 3, 3, stride=1, padding=1),
236 # nn.Tanh() # MSELoss
237 nn.Sigmoid() # BCELoss
238 )
239 def forward(self, x):
240 # pdb.set_trace()
241 feat = []
242 feat_out = [] # we only use high level features
243 for i in range(len(self.encoder)):
244 # print("layer {} encoder layer: {}".format(i, self.encoder[i]))
245 x = self.encoder[i](x)
246 if i == 3: # ReLU-4
247 # pdb.set_trace()
248 feat.append(x)
249 elif i == 8: # ReLU-9
250 # pdb.set_trace()
251 feat.append(x)
252 elif i == 17: # ReLU-18
253 # pdb.set_trace()
254 feat.append(x)
255 elif i == 26: # ReLU-27
256 # pdb.set_trace()
257 feat.append(x)
258 elif i == 35: # ReLU-36
259 # pdb.set_trace()
260 feat.append(x)
261 # pdb.set_trace()
262 for i in range(len(self.decoder)):
263 # print("layer {} decoder layer: {}".format(i, self.decoder[i]))
264 x = self.decoder[i](x)
265 if i == 1:
266 # pdb.set_trace()
267 _, _, h, w = feat[4].shape
268 x = nn.UpsamplingBilinear2d(size=(h,w))(x)
269 x = x + feat[4]
270 elif i == 3:
271 # pdb.set_trace()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected