Пример #1
0
    def _global_pooling(self, x):
        if self.training or self.pooling_size is None:
            pool = x.view(x.size(0), x.size(1), -1).mean(dim=-1)
            pool = pool.view(x.size(0), x.size(1), 1, 1)
        else:
            pooling_size = (
            min(try_index(self.pooling_size, 0), x.shape[2]), min(try_index(self.pooling_size, 1), x.shape[3]))
            padding = ((pooling_size[1] - 1) // 2,
                       (pooling_size[1] - 1) // 2 if pooling_size[1] % 2 == 1 else (pooling_size[1] - 1) // 2 + 1,
                       (pooling_size[0] - 1) // 2,
                       (pooling_size[0] - 1) // 2 if pooling_size[0] % 2 == 1 else (pooling_size[0] - 1) // 2 + 1)

            pool = functional.avg_pool2d(x, pooling_size, stride=1)
            pool = functional.pad(pool, pad=padding, mode="replicate")
        return pool
Пример #2
0
 def _stride_dilation(mod_id, block_id, dilation):
     if dilation == 1:
         s = 2 if mod_id > 0 and block_id == 0 else 1
         d = 1
     else:
         if dilation[mod_id] == 1:
             s = 2 if mod_id > 0 and block_id == 0 else 1
             d = 1
         else:
             s = 1
             d = try_index(dilation[mod_id], block_id)
     return s, d