MCPcopy Create free account
hub / github.com/apache/singa / __init__

Method __init__

python/singa/layer.py:896–962  ·  view source on GitHub ↗

Args: kernel_size (int or tuple): kernel size for two direction of each axis. For example, (2, 3), the first 2 means will add 2 at the beginning and also 2 at the end for its axis.and if a int is accepted, the kernel size will be i

(self,
                 kernel_size,
                 stride=None,
                 padding=0,
                 is_max=True,
                 pad_mode="NOTSET")

Source from the content-addressed store, hash-verified

894 """
895
896 def __init__(self,
897 kernel_size,
898 stride=None,
899 padding=0,
900 is_max=True,
901 pad_mode="NOTSET"):
902 """
903 Args:
904 kernel_size (int or tuple): kernel size for two direction of each
905 axis. For example, (2, 3), the first 2 means will add 2 at the
906 beginning and also 2 at the end for its axis.and if a int is
907 accepted, the kernel size will be initiated as (int, int)
908 stride (int or tuple): stride, the logic is the same as kernel size.
909 padding (int): tuple, list or None, padding, the logic is the same
910 as kernel size. However, if you set pad_mode as "SAME_UPPER" or
911 "SAME_LOWER" mode, you can set padding as None, and the padding
912 will be computed automatically.
913 is_max (bool): is max pooling or avg pooling
914 pad_mode (string): can be NOTSET, SAME_UPPER, or SAME_LOWER, where
915 default value is NOTSET, which means explicit padding is used.
916 SAME_UPPER or SAME_LOWER mean pad the input so that the output
917 spatial size match the input. In case of odd number add the extra
918 padding at the end for SAME_UPPER and at the beginning for SAME_LOWER.
919 """
920 super(Pooling2d, self).__init__()
921
922 if isinstance(kernel_size, int):
923 self.kernel_size = (kernel_size, kernel_size)
924 elif isinstance(kernel_size, tuple):
925 self.kernel_size = kernel_size
926 else:
927 raise TypeError("Wrong kernel_size type.")
928
929 if stride is None:
930 self.stride = self.kernel_size
931 elif isinstance(stride, int):
932 self.stride = (stride, stride)
933 elif isinstance(stride, tuple):
934 self.stride = stride
935 assert stride[0] > 0 or (kernel_size[0] == 1 and padding[0] == 0), (
936 "stride[0]=0, but kernel_size[0]=%d, padding[0]=%d" %
937 (kernel_size[0], padding[0]))
938 else:
939 raise TypeError("Wrong stride type.")
940
941 self.odd_padding = (0, 0, 0, 0)
942 if isinstance(padding, int):
943 self.padding = (padding, padding)
944 elif isinstance(padding, tuple) or isinstance(padding, list):
945 if len(padding) == 2:
946 self.padding = padding
947 elif len(padding) == 4:
948 _h_mask = padding[0] - padding[1]
949 _w_mask = padding[2] - padding[3]
950 # the odd paddding is the value that cannot be handled by the tuple padding (w, h) mode
951 # so we need to firstly handle the input, then use the nomal padding method.
952 self.odd_padding = (max(_h_mask, 0), max(-_h_mask, 0),
953 max(_w_mask, 0), max(-_w_mask, 0))

Callers

nothing calls this directly

Calls 2

maxFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected