3 # Any copyright is dedicated to the Public Domain.
4 # https://creativecommons.org/publicdomain/zero/1.0/
6 # Written by Francois Fleuret <francois@fleuret.org>
8 ######################################################################
10 def conv_chain(input_size, output_size, remain_depth, cond):
12 if input_size == output_size:
18 for kernel_size in range(1, input_size + 1):
19 for stride in range(1, input_size):
20 if cond(remain_depth, kernel_size, stride):
21 n = (input_size - kernel_size) // stride + 1
22 if n >= output_size and (n - 1) * stride + kernel_size == input_size:
23 q = conv_chain(n, output_size, remain_depth - 1, cond)
24 r += [ [ (kernel_size, stride) ] + u for u in q ]
27 ######################################################################
29 if __name__ == "__main__":
37 input_size = 64, output_size = 8,
39 # We want kernels smaller than 4, strides smaller than the
40 # kernels, and strides of 1 except in the two last layers
41 cond = lambda d, k, s: k <= 4 and s <= k and (s == 1 or d <= 2)
44 x = torch.rand(1, 1, 64)
47 model = nn.Sequential(*[ nn.Conv1d(1, 1, l[0], l[1]) for l in m ])
49 print(x.size(), model(x).size())
51 ######################################################################