Exemple #1
0
def get_pool(pool_type, pool_size, strides, **kwargs):
    """ Wrapper for Pooling operations"""
    if pool_type == "maxpool":
        return MaxPool2D(pool_size=pool_size, strides=strides, **kwargs)
    if pool_type == "avgpool":
        return AvgPool2D(pool_size=pool_size, strides=strides, **kwargs)
    raise NotImplementedError
Exemple #2
0
def get_pool(pool_type, pool_size, strides, **kwargs):
    if pool_type == "maxpool":
        return MaxPool2D(pool_size=pool_size, strides=strides, **kwargs)
    elif pool_type == "avgpool":
        return AvgPool2D(pool_size=pool_size, strides=strides, **kwargs)
    else:
        raise NotImplementedError
Exemple #3
0
 def __init__(self, fname, compressed_dim):
     self._ctx = mx.gpu(config.gpu_id) if config.use_gpu else mx.cpu(0)
     self._vgg16 = vision.vgg16(pretrained=True, ctx=self._ctx)
     self._compressed_dim = compressed_dim
     self._cell_size = [4, 16]
     self.penalty = [0., 0.]
     self.min_cell_size = np.min(self._cell_size)
     self._avg_pool2d = AvgPool2D()
Exemple #4
0
 def __init__(self, fname, compressed_dim,config=otb_deep_config.OTBDeepConfig()):
     super(VGG16Feature,self).__init__(config)
     self._ctx = mx.gpu(gpu_config.gpu_id) if gpu_config.use_gpu else mx.cpu(0)
     self._vgg16 = vision.vgg16(pretrained=True, ctx=self._ctx)
     self._compressed_dim = compressed_dim
     self._cell_size = [4, 16]
     self.penalty = [0., 0.]
     self.min_cell_size = np.min(self._cell_size)
     self._avg_pool2d = AvgPool2D()
    def __init__(self, name, nb_act_maps, ratio=16, act_type='relu'):

        super(_SqueezeExcitation, self).__init__(prefix=name)

        self.nb_act_maps = nb_act_maps
        self.body = HybridSequential(prefix='')

        nb_units_hidden = nb_act_maps // ratio
        with self.name_scope():
            self.body.add(AvgPool2D(pool_size=8))
            self.body.add(Dense(nb_units_hidden))
            self.body.add(get_act(act_type,))
            self.body.add(Dense(nb_act_maps))
            self.body.add(get_act('sigmoid'))
Exemple #6
0
    def __init__(self, is_color, img_sample_sz=[], size_mode='same'):
        super().__init__(is_color)
        use_for_color = settings.cnn_params.get('useForColor', True)
        use_for_gray = settings.cnn_params.get('useForGray', True)

        self.net = vision.vgg16(pretrained=True)
        self.pool2d = AvgPool2D()

        self.use_feature = (use_for_color and is_color) or (use_for_gray
                                                            and not is_color)
        self.nDim = np.array(
            [64, 512])  #[96 512] net["info"]["dataSize"][layer_dim_ind, 2]
        self.cell_size = np.array([4, 16])
        self.penalty = np.zeros((2, 1))
        self.compressed_dim = settings.cnn_params['compressed_dim']
        self.img_sample_sz = self._set_size(img_sample_sz, size_mode)
        self.data_sz = np.ceil(self.img_sample_sz / self.cell_size[:, None])
    m.ops = dict(_ops_dict)
    m.register_forward_hook(hook)
    print("input:", inputs.shape)
    print("output:", m(inputs).shape )
    for op_type, num in m.ops.items():
        print("{}: {:,}".format(op_type, num))
    print()


if __name__ == "__main__":
    inputs = nd.zeros(shape=(2,3,10,20))

    m = Conv2D(channels=10, in_channels=3, strides=1, padding=1, use_bias=True, kernel_size=5)
    m.initialize()
    test_counter(inputs, m, count_conv2d)

    m = BatchNorm()
    m.initialize()
    test_counter(inputs, m, count_bn)

    m = AvgPool2D()
    m.initialize()
    test_counter(inputs, m, count_avgpool)

    m = AvgPool3D()
    m.initialize()
    test_counter(nd.zeros(shape=(2,3,10,10,20)), m, count_avgpool)

    m = Dense(in_units=10, units=20)
    m.initialize()
    test_counter(nd.zeros(shape=(2,10)), m, count_fc)