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 ######################################################################
11 def conv_chain(input_size, output_size, remain_depth, cond):
13 if input_size == output_size:
19 for kernel_size in range(1, input_size + 1):
20 for stride in range(1, input_size):
21 if cond(remain_depth, kernel_size, stride):
22 n = (input_size - kernel_size) // stride + 1
25 and (n - 1) * stride + kernel_size == input_size
27 q = conv_chain(n, output_size, remain_depth - 1, cond)
28 r += [[(kernel_size, stride)] + u for u in q]
32 ######################################################################
34 if __name__ == "__main__":
44 # We want kernels smaller than 4, strides smaller than the
45 # kernels, and strides of 1 except in the two last layers
46 cond=lambda d, k, s: k <= 4 and s <= k and (s == 1 or d <= 2),
49 x = torch.rand(1, 1, 64)
52 model = nn.Sequential(*[nn.Conv1d(1, 1, l[0], l[1]) for l in m])
54 print(x.size(), model(x).size())
56 ######################################################################