Myosotis-Researches 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. myosotis_researches/CcGAN/train/__init__.py +4 -0
  2. myosotis_researches/CcGAN/{train_128_output_10 → train}/train_ccgan.py +4 -4
  3. myosotis_researches/CcGAN/{train_128 → train}/train_cgan.py +1 -3
  4. myosotis_researches/CcGAN/{train_128 → train}/train_cgan_concat.py +1 -3
  5. {myosotis_researches-0.1.8.dist-info → myosotis_researches-0.1.9.dist-info}/METADATA +1 -1
  6. myosotis_researches-0.1.9.dist-info/RECORD +24 -0
  7. myosotis_researches/CcGAN/models_128/CcGAN_SAGAN.py +0 -301
  8. myosotis_researches/CcGAN/models_128/ResNet_class_eval.py +0 -141
  9. myosotis_researches/CcGAN/models_128/ResNet_embed.py +0 -188
  10. myosotis_researches/CcGAN/models_128/ResNet_regre_eval.py +0 -175
  11. myosotis_researches/CcGAN/models_128/__init__.py +0 -7
  12. myosotis_researches/CcGAN/models_128/autoencoder.py +0 -119
  13. myosotis_researches/CcGAN/models_128/cGAN_SAGAN.py +0 -276
  14. myosotis_researches/CcGAN/models_128/cGAN_concat_SAGAN.py +0 -245
  15. myosotis_researches/CcGAN/models_256/CcGAN_SAGAN.py +0 -303
  16. myosotis_researches/CcGAN/models_256/ResNet_class_eval.py +0 -142
  17. myosotis_researches/CcGAN/models_256/ResNet_embed.py +0 -188
  18. myosotis_researches/CcGAN/models_256/ResNet_regre_eval.py +0 -178
  19. myosotis_researches/CcGAN/models_256/__init__.py +0 -7
  20. myosotis_researches/CcGAN/models_256/autoencoder.py +0 -133
  21. myosotis_researches/CcGAN/models_256/cGAN_SAGAN.py +0 -280
  22. myosotis_researches/CcGAN/models_256/cGAN_concat_SAGAN.py +0 -249
  23. myosotis_researches/CcGAN/train_128/DiffAugment_pytorch.py +0 -76
  24. myosotis_researches/CcGAN/train_128/__init__.py +0 -0
  25. myosotis_researches/CcGAN/train_128/eval_metrics.py +0 -205
  26. myosotis_researches/CcGAN/train_128/opts.py +0 -87
  27. myosotis_researches/CcGAN/train_128/pretrain_AE.py +0 -268
  28. myosotis_researches/CcGAN/train_128/pretrain_CNN_class.py +0 -251
  29. myosotis_researches/CcGAN/train_128/pretrain_CNN_regre.py +0 -255
  30. myosotis_researches/CcGAN/train_128/train_ccgan.py +0 -303
  31. myosotis_researches/CcGAN/train_128/utils.py +0 -120
  32. myosotis_researches/CcGAN/train_128_output_10/DiffAugment_pytorch.py +0 -76
  33. myosotis_researches/CcGAN/train_128_output_10/__init__.py +0 -0
  34. myosotis_researches/CcGAN/train_128_output_10/eval_metrics.py +0 -205
  35. myosotis_researches/CcGAN/train_128_output_10/opts.py +0 -87
  36. myosotis_researches/CcGAN/train_128_output_10/pretrain_AE.py +0 -268
  37. myosotis_researches/CcGAN/train_128_output_10/pretrain_CNN_class.py +0 -251
  38. myosotis_researches/CcGAN/train_128_output_10/pretrain_CNN_regre.py +0 -255
  39. myosotis_researches/CcGAN/train_128_output_10/train_cgan.py +0 -254
  40. myosotis_researches/CcGAN/train_128_output_10/train_cgan_concat.py +0 -242
  41. myosotis_researches/CcGAN/train_128_output_10/train_net_for_label_embed.py +0 -181
  42. myosotis_researches/CcGAN/train_128_output_10/utils.py +0 -120
  43. myosotis_researches-0.1.8.dist-info/RECORD +0 -59
  44. /myosotis_researches/CcGAN/{train_128 → train}/train_net_for_label_embed.py +0 -0
  45. {myosotis_researches-0.1.8.dist-info → myosotis_researches-0.1.9.dist-info}/WHEEL +0 -0
  46. {myosotis_researches-0.1.8.dist-info → myosotis_researches-0.1.9.dist-info}/licenses/LICENSE +0 -0
  47. {myosotis_researches-0.1.8.dist-info → myosotis_researches-0.1.9.dist-info}/top_level.txt +0 -0
@@ -1,188 +0,0 @@
1
- '''
2
- ResNet-based model to map an image from pixel space to a features space.
3
- Need to be pretrained on the dataset.
4
-
5
- if isometric_map = True, there is an extra step (elf.classifier_1 = nn.Linear(512, 32*32*3)) to increase the dimension of the feature map from 512 to 32*32*3. This selection is for desity-ratio estimation in feature space.
6
-
7
- codes are based on
8
- @article{
9
- zhang2018mixup,
10
- title={mixup: Beyond Empirical Risk Minimization},
11
- author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
12
- journal={International Conference on Learning Representations},
13
- year={2018},
14
- url={https://openreview.net/forum?id=r1Ddp1-Rb},
15
- }
16
- '''
17
-
18
-
19
- import torch
20
- import torch.nn as nn
21
- import torch.nn.functional as F
22
-
23
- NC = 3
24
- IMG_SIZE = 128
25
- DIM_EMBED = 128
26
-
27
-
28
- #------------------------------------------------------------------------------
29
- class BasicBlock(nn.Module):
30
- expansion = 1
31
-
32
- def __init__(self, in_planes, planes, stride=1):
33
- super(BasicBlock, self).__init__()
34
- self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
35
- self.bn1 = nn.BatchNorm2d(planes)
36
- self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
37
- self.bn2 = nn.BatchNorm2d(planes)
38
-
39
- self.shortcut = nn.Sequential()
40
- if stride != 1 or in_planes != self.expansion*planes:
41
- self.shortcut = nn.Sequential(
42
- nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
43
- nn.BatchNorm2d(self.expansion*planes)
44
- )
45
-
46
- def forward(self, x):
47
- out = F.relu(self.bn1(self.conv1(x)))
48
- out = self.bn2(self.conv2(out))
49
- out += self.shortcut(x)
50
- out = F.relu(out)
51
- return out
52
-
53
-
54
- class Bottleneck(nn.Module):
55
- expansion = 4
56
-
57
- def __init__(self, in_planes, planes, stride=1):
58
- super(Bottleneck, self).__init__()
59
- self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False)
60
- self.bn1 = nn.BatchNorm2d(planes)
61
- self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
62
- self.bn2 = nn.BatchNorm2d(planes)
63
- self.conv3 = nn.Conv2d(planes, self.expansion*planes, kernel_size=1, bias=False)
64
- self.bn3 = nn.BatchNorm2d(self.expansion*planes)
65
-
66
- self.shortcut = nn.Sequential()
67
- if stride != 1 or in_planes != self.expansion*planes:
68
- self.shortcut = nn.Sequential(
69
- nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
70
- nn.BatchNorm2d(self.expansion*planes)
71
- )
72
-
73
- def forward(self, x):
74
- out = F.relu(self.bn1(self.conv1(x)))
75
- out = F.relu(self.bn2(self.conv2(out)))
76
- out = self.bn3(self.conv3(out))
77
- out += self.shortcut(x)
78
- out = F.relu(out)
79
- return out
80
-
81
-
82
- class ResNet_embed(nn.Module):
83
- def __init__(self, block, num_blocks, nc=NC, dim_embed=DIM_EMBED):
84
- super(ResNet_embed, self).__init__()
85
- self.in_planes = 64
86
-
87
- self.main = nn.Sequential(
88
- nn.Conv2d(nc, 64, kernel_size=3, stride=1, padding=1, bias=False), # h=h
89
- # nn.Conv2d(nc, 64, kernel_size=4, stride=2, padding=1, bias=False), # h=h/2
90
- nn.BatchNorm2d(64),
91
- nn.ReLU(),
92
- nn.MaxPool2d(2,2), #h=h/2 64
93
- # self._make_layer(block, 64, num_blocks[0], stride=1), # h=h
94
- self._make_layer(block, 64, num_blocks[0], stride=2), # h=h/2 32
95
- self._make_layer(block, 128, num_blocks[1], stride=2), # h=h/2 16
96
- self._make_layer(block, 256, num_blocks[2], stride=2), # h=h/2 8
97
- self._make_layer(block, 512, num_blocks[3], stride=2), # h=h/2 4
98
- # nn.AvgPool2d(kernel_size=4)
99
- nn.AdaptiveAvgPool2d((1, 1))
100
- )
101
-
102
- self.x2h_res = nn.Sequential(
103
- nn.Linear(512, 512),
104
- nn.BatchNorm1d(512),
105
- nn.ReLU(),
106
-
107
- nn.Linear(512, dim_embed),
108
- nn.BatchNorm1d(dim_embed),
109
- nn.ReLU(),
110
- )
111
-
112
- self.h2y = nn.Sequential(
113
- nn.Linear(dim_embed, 1),
114
- nn.ReLU()
115
- )
116
-
117
- def _make_layer(self, block, planes, num_blocks, stride):
118
- strides = [stride] + [1]*(num_blocks-1)
119
- layers = []
120
- for stride in strides:
121
- layers.append(block(self.in_planes, planes, stride))
122
- self.in_planes = planes * block.expansion
123
- return nn.Sequential(*layers)
124
-
125
- def forward(self, x):
126
-
127
- features = self.main(x)
128
- features = features.view(features.size(0), -1)
129
- features = self.x2h_res(features)
130
- out = self.h2y(features)
131
-
132
- return out, features
133
-
134
-
135
- def ResNet18_embed(dim_embed=DIM_EMBED):
136
- return ResNet_embed(BasicBlock, [2,2,2,2], dim_embed=dim_embed)
137
-
138
- def ResNet34_embed(dim_embed=DIM_EMBED):
139
- return ResNet_embed(BasicBlock, [3,4,6,3], dim_embed=dim_embed)
140
-
141
- def ResNet50_embed(dim_embed=DIM_EMBED):
142
- return ResNet_embed(Bottleneck, [3,4,6,3], dim_embed=dim_embed)
143
-
144
- #------------------------------------------------------------------------------
145
- # map labels to the embedding space
146
- class model_y2h(nn.Module):
147
- def __init__(self, dim_embed=DIM_EMBED):
148
- super(model_y2h, self).__init__()
149
- self.main = nn.Sequential(
150
- nn.Linear(1, dim_embed),
151
- # nn.BatchNorm1d(dim_embed),
152
- nn.GroupNorm(8, dim_embed),
153
- nn.ReLU(),
154
-
155
- nn.Linear(dim_embed, dim_embed),
156
- # nn.BatchNorm1d(dim_embed),
157
- nn.GroupNorm(8, dim_embed),
158
- nn.ReLU(),
159
-
160
- nn.Linear(dim_embed, dim_embed),
161
- # nn.BatchNorm1d(dim_embed),
162
- nn.GroupNorm(8, dim_embed),
163
- nn.ReLU(),
164
-
165
- nn.Linear(dim_embed, dim_embed),
166
- # nn.BatchNorm1d(dim_embed),
167
- nn.GroupNorm(8, dim_embed),
168
- nn.ReLU(),
169
-
170
- nn.Linear(dim_embed, dim_embed),
171
- nn.ReLU()
172
- )
173
-
174
- def forward(self, y):
175
- y = y.view(-1, 1) +1e-8
176
- # y = torch.exp(y.view(-1, 1))
177
- return self.main(y)
178
-
179
-
180
-
181
- if __name__ == "__main__":
182
- net = ResNet34_embed(dim_embed=128).cuda()
183
- x = torch.randn(16,NC,IMG_SIZE,IMG_SIZE).cuda()
184
- out, features = net(x)
185
- print(out.size())
186
- print(features.size())
187
-
188
- net_y2h = model_y2h()
@@ -1,175 +0,0 @@
1
- '''
2
- codes are based on
3
- @article{
4
- zhang2018mixup,
5
- title={mixup: Beyond Empirical Risk Minimization},
6
- author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
7
- journal={International Conference on Learning Representations},
8
- year={2018},
9
- url={https://openreview.net/forum?id=r1Ddp1-Rb},
10
- }
11
- '''
12
-
13
-
14
- import torch
15
- import torch.nn as nn
16
- import torch.nn.functional as F
17
-
18
- NC = 3
19
- IMG_SIZE = 128
20
-
21
-
22
- class BasicBlock(nn.Module):
23
- expansion = 1
24
-
25
- def __init__(self, in_planes, planes, stride=1):
26
- super(BasicBlock, self).__init__()
27
- self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
28
- self.bn1 = nn.BatchNorm2d(planes)
29
- self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
30
- self.bn2 = nn.BatchNorm2d(planes)
31
-
32
- self.shortcut = nn.Sequential()
33
- if stride != 1 or in_planes != self.expansion*planes:
34
- self.shortcut = nn.Sequential(
35
- nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
36
- nn.BatchNorm2d(self.expansion*planes)
37
- )
38
-
39
- def forward(self, x):
40
- out = F.relu(self.bn1(self.conv1(x)))
41
- out = self.bn2(self.conv2(out))
42
- out += self.shortcut(x)
43
- out = F.relu(out)
44
- return out
45
-
46
-
47
- class Bottleneck(nn.Module):
48
- expansion = 4
49
-
50
- def __init__(self, in_planes, planes, stride=1):
51
- super(Bottleneck, self).__init__()
52
- self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False)
53
- self.bn1 = nn.BatchNorm2d(planes)
54
- self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
55
- self.bn2 = nn.BatchNorm2d(planes)
56
- self.conv3 = nn.Conv2d(planes, self.expansion*planes, kernel_size=1, bias=False)
57
- self.bn3 = nn.BatchNorm2d(self.expansion*planes)
58
-
59
- self.shortcut = nn.Sequential()
60
- if stride != 1 or in_planes != self.expansion*planes:
61
- self.shortcut = nn.Sequential(
62
- nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False),
63
- nn.BatchNorm2d(self.expansion*planes)
64
- )
65
-
66
- def forward(self, x):
67
- out = F.relu(self.bn1(self.conv1(x)))
68
- out = F.relu(self.bn2(self.conv2(out)))
69
- out = self.bn3(self.conv3(out))
70
- out += self.shortcut(x)
71
- out = F.relu(out)
72
- return out
73
-
74
-
75
- class ResNet_regre_eval(nn.Module):
76
- def __init__(self, block, num_blocks, nc=NC, ngpu = 1, feature_layer='f3'):
77
- super(ResNet_regre_eval, self).__init__()
78
- self.in_planes = 64
79
- self.ngpu = ngpu
80
- self.feature_layer=feature_layer
81
-
82
- self.block1 = nn.Sequential(
83
- nn.Conv2d(nc, 64, kernel_size=3, stride=1, padding=1, bias=False), # h=h
84
- nn.BatchNorm2d(64),
85
- nn.ReLU(),
86
- nn.MaxPool2d(2,2), #h=h/2 64
87
- self._make_layer(block, 64, num_blocks[0], stride=2), # h=h/2 32
88
- )
89
- self.block2 = self._make_layer(block, 128, num_blocks[1], stride=2) # h=h/2 16
90
- self.block3 = self._make_layer(block, 256, num_blocks[2], stride=2) # h=h/2 8
91
- self.block4 = self._make_layer(block, 512, num_blocks[3], stride=2) # h=h/2 4
92
-
93
- self.pool1 = nn.AvgPool2d(kernel_size=4)
94
- if self.feature_layer == 'f2':
95
- self.pool2 = nn.AdaptiveAvgPool2d((2,2))
96
- elif self.feature_layer == 'f3':
97
- self.pool2 = nn.AdaptiveAvgPool2d((2,2))
98
- else:
99
- self.pool2 = nn.AdaptiveAvgPool2d((1,1))
100
-
101
- linear_layers = [
102
- nn.Linear(512*block.expansion, 128),
103
- nn.BatchNorm1d(128),
104
- nn.ReLU(),
105
- nn.Linear(128, 128),
106
- nn.BatchNorm1d(128),
107
- nn.ReLU(),
108
- nn.Linear(128, 1),
109
- # nn.Sigmoid()
110
- nn.ReLU(),
111
- ]
112
- self.linear = nn.Sequential(*linear_layers)
113
-
114
-
115
- def _make_layer(self, block, planes, num_blocks, stride):
116
- strides = [stride] + [1]*(num_blocks-1)
117
- layers = []
118
- for stride in strides:
119
- layers.append(block(self.in_planes, planes, stride))
120
- self.in_planes = planes * block.expansion
121
- return nn.Sequential(*layers)
122
-
123
- def forward(self, x):
124
-
125
- if x.is_cuda and self.ngpu > 1:
126
- ft1 = nn.parallel.data_parallel(self.block1, x, range(self.ngpu))
127
- ft2 = nn.parallel.data_parallel(self.block2, ft1, range(self.ngpu))
128
- ft3 = nn.parallel.data_parallel(self.block3, ft2, range(self.ngpu))
129
- ft4 = nn.parallel.data_parallel(self.block4, ft3, range(self.ngpu))
130
- out = nn.parallel.data_parallel(self.pool1, ft4, range(self.ngpu))
131
- out = out.view(out.size(0), -1)
132
- out = nn.parallel.data_parallel(self.linear, out, range(self.ngpu))
133
- else:
134
- ft1 = self.block1(x)
135
- ft2 = self.block2(ft1)
136
- ft3 = self.block3(ft2)
137
- ft4 = self.block4(ft3)
138
- out = self.pool1(ft4)
139
- out = out.view(out.size(0), -1)
140
- out = self.linear(out)
141
-
142
- if self.feature_layer == 'f2':
143
- ext_features = self.pool2(ft2)
144
- elif self.feature_layer == 'f3':
145
- ext_features = self.pool2(ft3)
146
- else:
147
- ext_features = self.pool2(ft4)
148
-
149
- ext_features = ext_features.view(ext_features.size(0), -1)
150
-
151
- return out, ext_features
152
-
153
-
154
- def ResNet18_regre_eval(ngpu = 1):
155
- return ResNet_regre_eval(BasicBlock, [2,2,2,2], ngpu = ngpu)
156
-
157
- def ResNet34_regre_eval(ngpu = 1):
158
- return ResNet_regre_eval(BasicBlock, [3,4,6,3], ngpu = ngpu)
159
-
160
- def ResNet50_regre_eval(ngpu = 1):
161
- return ResNet_regre_eval(Bottleneck, [3,4,6,3], ngpu = ngpu)
162
-
163
- def ResNet101_regre_eval(ngpu = 1):
164
- return ResNet_regre_eval(Bottleneck, [3,4,23,3], ngpu = ngpu)
165
-
166
- def ResNet152_regre_eval(ngpu = 1):
167
- return ResNet_regre_eval(Bottleneck, [3,8,36,3], ngpu = ngpu)
168
-
169
-
170
- if __name__ == "__main__":
171
- net = ResNet34_regre_eval(ngpu = 1).cuda()
172
- x = torch.randn(4,NC,IMG_SIZE,IMG_SIZE).cuda()
173
- out, features = net(x)
174
- print(out.size())
175
- print(features.size())
@@ -1,7 +0,0 @@
1
- from .autoencoder import *
2
- from .cGAN_SAGAN import cGAN_SAGAN_Generator, cGAN_SAGAN_Discriminator
3
- from .cGAN_concat_SAGAN import cGAN_concat_SAGAN_Generator, cGAN_concat_SAGAN_Discriminator
4
- from .CcGAN_SAGAN import CcGAN_SAGAN_Generator, CcGAN_SAGAN_Discriminator
5
- from .ResNet_embed import ResNet18_embed, ResNet34_embed, ResNet50_embed, model_y2h
6
- from .ResNet_regre_eval import ResNet34_regre_eval
7
- from .ResNet_class_eval import ResNet34_class_eval
@@ -1,119 +0,0 @@
1
- import torch
2
- from torch import nn
3
-
4
-
5
-
6
- class encoder(nn.Module):
7
- def __init__(self, dim_bottleneck=512, ch=64):
8
- super(encoder, self).__init__()
9
- self.ch = ch
10
- self.dim_bottleneck = dim_bottleneck
11
-
12
- self.conv = nn.Sequential(
13
- nn.Conv2d(3, ch, kernel_size=4, stride=2, padding=1), #h=h/2; 64
14
- nn.BatchNorm2d(ch),
15
- nn.ReLU(),
16
- nn.MaxPool2d(2,2), #h=h/2; 32
17
- nn.Conv2d(ch, ch, kernel_size=3, stride=1, padding=1), #h=h
18
- nn.BatchNorm2d(ch),
19
- nn.ReLU(),
20
-
21
- nn.Conv2d(ch, ch*2, kernel_size=4, stride=2, padding=1), #h=h/2; 16
22
- nn.BatchNorm2d(ch*2),
23
- nn.ReLU(),
24
- nn.Conv2d(ch*2, ch*2, kernel_size=3, stride=1, padding=1), #h=h
25
- nn.BatchNorm2d(ch*2),
26
- nn.ReLU(),
27
-
28
- nn.Conv2d(ch*2, ch*4, kernel_size=4, stride=2, padding=1), #h=h/2; 8
29
- nn.BatchNorm2d(ch*4),
30
- nn.ReLU(),
31
- nn.Conv2d(ch*4, ch*4, kernel_size=3, stride=1, padding=1), #h=h
32
- nn.BatchNorm2d(ch*4),
33
- nn.ReLU(),
34
-
35
- nn.Conv2d(ch*4, ch*8, kernel_size=4, stride=2, padding=1), #h=h/2; 4
36
- nn.BatchNorm2d(ch*8),
37
- nn.ReLU(),
38
- nn.Conv2d(ch*8, ch*8, kernel_size=3, stride=1, padding=1), #h=h
39
- nn.BatchNorm2d(ch*8),
40
- nn.ReLU(),
41
- )
42
-
43
- self.linear = nn.Sequential(
44
- nn.Linear(ch*8*4*4, dim_bottleneck),
45
- # nn.ReLU()
46
- )
47
-
48
- def forward(self, x):
49
- feature = self.conv(x)
50
- feature = feature.view(-1, self.ch*8*4*4)
51
- feature = self.linear(feature)
52
- return feature
53
-
54
-
55
-
56
- class decoder(nn.Module):
57
- def __init__(self, dim_bottleneck=512, ch=64):
58
- super(decoder, self).__init__()
59
- self.ch = ch
60
- self.dim_bottleneck = dim_bottleneck
61
-
62
- self.linear = nn.Sequential(
63
- nn.Linear(dim_bottleneck, ch*16*4*4)
64
- )
65
-
66
- self.deconv = nn.Sequential(
67
- nn.ConvTranspose2d(ch*16, ch*8, kernel_size=4, stride=2, padding=1), #h=2h; 8
68
- nn.BatchNorm2d(ch*8),
69
- nn.ReLU(True),
70
- nn.Conv2d(ch*8, ch*8, kernel_size=3, stride=1, padding=1), #h=h
71
- nn.BatchNorm2d(ch*8),
72
- nn.ReLU(),
73
-
74
- nn.ConvTranspose2d(ch*8, ch*4, kernel_size=4, stride=2, padding=1), #h=2h; 16
75
- nn.BatchNorm2d(ch*4),
76
- nn.ReLU(True),
77
- nn.Conv2d(ch*4, ch*4, kernel_size=3, stride=1, padding=1), #h=h
78
- nn.BatchNorm2d(ch*4),
79
- nn.ReLU(),
80
-
81
- nn.ConvTranspose2d(ch*4, ch*2, kernel_size=4, stride=2, padding=1), #h=2h; 32
82
- nn.BatchNorm2d(ch*2),
83
- nn.ReLU(True),
84
- nn.Conv2d(ch*2, ch*2, kernel_size=3, stride=1, padding=1), #h=h
85
- nn.BatchNorm2d(ch*2),
86
- nn.ReLU(),
87
-
88
- nn.ConvTranspose2d(ch*2, ch, kernel_size=4, stride=2, padding=1), #h=2h; 64
89
- nn.BatchNorm2d(ch),
90
- nn.ReLU(True),
91
- nn.Conv2d(ch, ch, kernel_size=3, stride=1, padding=1), #h=h
92
- nn.BatchNorm2d(ch),
93
- nn.ReLU(),
94
-
95
- nn.ConvTranspose2d(ch, ch, kernel_size=4, stride=2, padding=1), #h=2h; 128
96
- nn.BatchNorm2d(ch),
97
- nn.ReLU(True),
98
- nn.Conv2d(ch, 3, kernel_size=3, stride=1, padding=1), #h=h
99
- nn.Tanh()
100
- )
101
-
102
- def forward(self, feature):
103
- out = self.linear(feature)
104
- out = out.view(-1, self.ch*16, 4, 4)
105
- out = self.deconv(out)
106
- return out
107
-
108
-
109
- if __name__=="__main__":
110
- #test
111
-
112
- net_encoder = encoder(dim_bottleneck=512, ch=64).cuda()
113
- net_decoder = decoder(dim_bottleneck=512, ch=64).cuda()
114
-
115
- x = torch.randn(10, 3, 128, 128).cuda()
116
- f = net_encoder(x)
117
- xh = net_decoder(f)
118
- print(f.size())
119
- print(xh.size())