示例#1
0
 def test_maxpool(self):
     """
     Test maximum pooling layer.
     """
     mp = layers.MaxPool((3, 3), (2, 2))
     o = mp(torch.randn(1, 2, 32, 64))
     self.assertEqual(o.shape, (1, 2, 15, 31))
示例#2
0
 def build_maxpool(self, input: Tuple[int, int, int, int], block: str) -> Union[Tuple[None, None, None], Tuple[Tuple[int, int, int, int], str, Callable]]:
     """
     Builds a maxpool layer.
     """
     pattern = re.compile(r'(?P<type>Mp)(?P<name>{\w+})?(\d+),(\d+)(?:,(\d+),(\d+))?')
     m = pattern.match(block)
     if not m:
         return None, None, None
     kernel_size = (int(m.group(3)), int(m.group(4)))
     stride = (kernel_size[0] if not m.group(5) else int(m.group(5)),
               kernel_size[1] if not m.group(6) else int(m.group(6)))
     fn = layers.MaxPool(kernel_size, stride)
     logger.debug('{}\t\tmaxpool\tkernel {} x {} stride {} x {}'.format(self.idx+1, kernel_size[0], kernel_size[1], stride[0], stride[1]))
     return fn.get_shape(input), self.get_layer_name(m.group('type'), m.group('name')), fn
示例#3
0
 def build_maxpool(
     self, input: Tuple[int, int, int, int], blocks: List[str], idx: int
 ) -> Union[Tuple[None, None, None], Tuple[Tuple[int, int, int, int], str,
                                           Callable]]:
     """
     Builds a maxpool layer.
     """
     pattern = re.compile(
         r'(?P<type>Mp)(?P<name>{\w+})?(\d+),(\d+)(?:,(\d+),(\d+))?')
     m = pattern.match(blocks[idx])
     if not m:
         return None, None, None
     kernel_size = (int(m.group(3)), int(m.group(4)))
     stride = (kernel_size[0] if not m.group(5) else int(m.group(5)),
               kernel_size[1] if not m.group(6) else int(m.group(6)))
     fn = layers.MaxPool(kernel_size, stride)
     self.idx += 1
     logger.debug(
         f'{self.idx}\t\tmaxpool\tkernel {kernel_size[0]} x {kernel_size[1]} stride {stride[0]} x {stride[1]}'
     )
     return fn.get_shape(input), [
         VGSLBlock(blocks[idx], m.group('type'), m.group('name'), self.idx)
     ], fn