
Loss function for Autoencoder, also we may have to use other pretrained network for feature extractor for the loss function or even not using feature extractor. I ... honestly do not think using neural network for VGG is strictly nesccesary, and may have to be replaced with other image preprocessing like MSCN which was implimented before.
@744883d07d3d7028072d6a3fc46551eade5f2f87
--- model/Autoencoder.py
+++ model/Autoencoder.py
... | ... | @@ -39,6 +39,8 @@ |
39 | 39 |
self.skip_output3 = nn.Conv2d(in_channels=32, out_channels=3, kernel_size=3, stride=1, padding=1, bias=False) |
40 | 40 |
|
41 | 41 |
# Loss specific definitions |
42 |
+ # the paper uses vgg16 for features extraction, |
|
43 |
+ # however, since vgg16 is not a light model, we may consider it to be replaced |
|
42 | 44 |
self.vgg = vgg16(pretrained=True).features |
43 | 45 |
self.vgg.eval() |
44 | 46 |
for param in self.vgg.parameters(): |
... | ... | @@ -106,8 +108,8 @@ |
106 | 108 |
lm_loss += mse_loss |
107 | 109 |
|
108 | 110 |
# Compute lp_loss |
109 |
- src_vgg_feats = self.extract_vgg_feats(label_tensor) |
|
110 |
- pred_vgg_feats = self.extract_vgg_feats(output_list[-1]) |
|
111 |
+ src_vgg_feats = self.vgg(label_tensor) |
|
112 |
+ pred_vgg_feats = self.vgg(output_list[-1]) |
|
111 | 113 |
|
112 | 114 |
lp_losses = [] |
113 | 115 |
for index in range(len(src_vgg_feats)): |
... | ... | @@ -116,14 +118,4 @@ |
116 | 118 |
|
117 | 119 |
loss = lm_loss + lp_loss |
118 | 120 |
|
119 |
- return loss, inference_ret['skip_3'] |
|
120 |
- |
|
121 |
- def extract_vgg_feats(self, input_tensor): |
|
122 |
- # Extract features from the input tensor using the VGG network |
|
123 |
- feats = [] |
|
124 |
- x = input_tensor |
|
125 |
- for layer_num, layer in enumerate(self.vgg): |
|
126 |
- x = layer(x) |
|
127 |
- if layer_num in {3, 8, 15, 22, 29}: |
|
128 |
- feats.append(x) |
|
129 |
- return feats(파일 끝에 줄바꿈 문자 없음) |
|
121 |
+ return loss, inference_ret['skip_3'](파일 끝에 줄바꿈 문자 없음) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?