projects
/
pytorch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tried to make the source clearer, added the TimeAppender Module.
[pytorch.git]
/
conv_chain.py
diff --git
a/conv_chain.py
b/conv_chain.py
index
85ae4fc
..
3077874
100755
(executable)
--- a/
conv_chain.py
+++ b/
conv_chain.py
@@
-1,12
+1,14
@@
#!/usr/bin/env python
#!/usr/bin/env python
-import torch
-from torch import nn
+# Any copyright is dedicated to the Public Domain.
+# https://creativecommons.org/publicdomain/zero/1.0/
+
+# Written by Francois Fleuret <francois@fleuret.org>
######################################################################
######################################################################
-def conv_chain(input_size, output_size, depth, cond):
- if depth == 0:
+def conv_chain(input_size, output_size,
remain_
depth, cond):
+ if
remain_
depth == 0:
if input_size == output_size:
return [ [ ] ]
else:
if input_size == output_size:
return [ [ ] ]
else:
@@
-14,11
+16,11
@@
def conv_chain(input_size, output_size, depth, cond):
else:
r = [ ]
for kernel_size in range(1, input_size + 1):
else:
r = [ ]
for kernel_size in range(1, input_size + 1):
- for stride in range(1, input_size
+ 1
):
- if cond(depth, kernel_size, stride):
+ for stride in range(1, input_size):
+ if cond(
remain_
depth, kernel_size, stride):
n = (input_size - kernel_size) // stride + 1
n = (input_size - kernel_size) // stride + 1
- if (n - 1) * stride + kernel_size == input_size:
- q = conv_chain(n, output_size, depth - 1, cond)
+ if
n >= output_size and
(n - 1) * stride + kernel_size == input_size:
+ q = conv_chain(n, output_size,
remain_
depth - 1, cond)
r += [ [ (kernel_size, stride) ] + u for u in q ]
return r
r += [ [ (kernel_size, stride) ] + u for u in q ]
return r
@@
-26,12
+28,17
@@
def conv_chain(input_size, output_size, depth, cond):
if __name__ == "__main__":
if __name__ == "__main__":
+ import torch
+ from torch import nn
+
# Example
c = conv_chain(
input_size = 64, output_size = 8,
# Example
c = conv_chain(
input_size = 64, output_size = 8,
- depth = 5,
- cond = lambda d, k, s: k <= 4 and s <= k and (s == 1 or d < 3)
+ remain_depth = 5,
+ # We want kernels smaller than 4, strides smaller than the
+ # kernels, and strides of 1 except in the two last layers
+ cond = lambda d, k, s: k <= 4 and s <= k and (s == 1 or d <= 2)
)
x = torch.rand(1, 1, 64)
)
x = torch.rand(1, 1, 64)