X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=pytorch.git;a=blobdiff_plain;f=ae_size.py;h=067a7fa7bc1d44f4330e7f37fe1e511d3fd92045;hp=48dc2aff09cd8994f402ba3188fcf95937cf85c2;hb=e916a8624b6a09737696c124f35059030f0f20e4;hpb=4f1a822b8d1b09bc2aed8c7fca99436db1f95620 diff --git a/ae_size.py b/ae_size.py index 48dc2af..067a7fa 100755 --- a/ae_size.py +++ b/ae_size.py @@ -1,5 +1,10 @@ #!/usr/bin/env python +# Any copyright is dedicated to the Public Domain. +# https://creativecommons.org/publicdomain/zero/1.0/ + +# Written by Francois Fleuret + import math from torch import nn from torch import Tensor @@ -11,10 +16,10 @@ def minimal_input_size(w, layer_specs): 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) + kernel_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 ###################################################################### @@ -22,9 +27,10 @@ def minimal_input_size(w, layer_specs): if __name__ == "__main__": - layer_specs = [ (11, 5), (5, 2), (3, 2), (3, 2) ] + layer_specs = [ (17, 5), (5, 4), (3, 2), (3, 2) ] layers = [] + for kernel_size, stride in layer_specs: layers.append(nn.Conv2d(1, 1, kernel_size, stride))