projects
/
pytorch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Minor syntactic change.
[pytorch.git]
/
ae_size.py
diff --git
a/ae_size.py
b/ae_size.py
index
7bef9f5
..
067a7fa
100755
(executable)
--- a/
ae_size.py
+++ b/
ae_size.py
@@
-1,5
+1,10
@@
#!/usr/bin/env python
#!/usr/bin/env python
+# Any copyright is dedicated to the Public Domain.
+# https://creativecommons.org/publicdomain/zero/1.0/
+
+# Written by Francois Fleuret <francois@fleuret.org>
+
import math
from torch import nn
from torch import Tensor
import math
from torch import nn
from torch import Tensor
@@
-11,27
+16,34
@@
def minimal_input_size(w, layer_specs):
if layer_specs == []:
return w
else:
if layer_specs == []:
return w
else:
- k
, s
= layer_specs[0]
-
w = math.ceil((w - k) / s
) + 1
-
w = minimal_input_size(w
, layer_specs[1:])
- return
int((w - 1) * s + k)
+ k
ernel_size, stride
= layer_specs[0]
+
v = int(math.ceil((w - kernel_size) / stride)
) + 1
+
v = minimal_input_size(v
, layer_specs[1:])
+ return
(v - 1) * stride + kernel_size
######################################################################
######################################################################
-layer_specs = [ (11, 5), (5, 2), (3, 2), (3, 2) ]
+# Dummy test
+
+if __name__ == "__main__":
+
+ layer_specs = [ (17, 5), (5, 4), (3, 2), (3, 2) ]
-layers = []
-for l in layer_specs:
- layers.append(nn.Conv2d(1, 1, l[0], l[1]))
+ layers = []
-
for l in reversed(layer_specs)
:
-
layers.append(nn.ConvTranspose2d(1, 1, l[0], l[1]
))
+
for kernel_size, stride in layer_specs
:
+
layers.append(nn.Conv2d(1, 1, kernel_size, stride
))
-m = nn.Sequential(*layers)
+ for kernel_size, stride in reversed(layer_specs):
+ layers.append(nn.ConvTranspose2d(1, 1, kernel_size, stride))
-h = minimal_input_size(240, layer_specs)
-w = minimal_input_size(320, layer_specs)
+ m = nn.Sequential(*layers)
-x = Tensor(1, 1, h, w).normal_()
+ h = minimal_input_size(240, layer_specs)
+ w = minimal_input_size(320, layer_specs)
-print(x.size(), m(x).size())
+ x = Tensor(1, 1, h, w).normal_()
+
+ print(x.size(), m(x).size())
+
+######################################################################