How to use the batchflow.models.tf.layers.conv_block function in batchflow

To help you get started, we’ve selected a few batchflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github analysiscenter / batchflow / batchflow / models / tf / inception_v3.py View on Github external
name : str
            scope name

        Returns
        -------
        tf.Tensor
        """
        with tf.variable_scope(name):
            axis = cls.channels_axis(kwargs['data_format'])
            branch_1 = conv_block(inputs, layout, filters[0], 1, name='conv_1', **kwargs)

            branch_pool = conv_block(inputs, 'p'+layout, filters[3], 1, name='c_pool',
                                     **{**kwargs, 'pool_strides': 1})

            branch_a1 = conv_block(inputs, layout, filters[1], 1, name='conv_a1', **kwargs)
            branch_a1_31 = conv_block(branch_a1, layout, filters[1], [3, 1], name='conv_1_31', **kwargs)
            branch_a1_13 = conv_block(branch_a1, layout, filters[1], [1, 3], name='conv_1_13', **kwargs)
            branch_a = tf.concat([branch_a1_31, branch_a1_13], axis=axis)

            branch_b13 = conv_block(inputs, layout*2, [filters[2], filters[1]], [1, 3], name='conv_b13', **kwargs)
            branch_b13_31 = conv_block(branch_b13, layout, filters[1], [3, 1], name='conv_b13_31', **kwargs)
            branch_b13_13 = conv_block(branch_b13, layout, filters[1], [1, 3], name='conv_b13_13', **kwargs)
            branch_b = tf.concat([branch_b13_31, branch_b13_13], axis=axis)

            output = tf.concat([branch_1, branch_pool, branch_a, branch_b], axis=axis, name='output')
        return output
github analysiscenter / batchflow / batchflow / models / tf / base.py View on Github external
inputs : tf.Tensor
            Input tensor.
        name : str
            Scope name.

        Notes
        -----
        For other parameters see :class:`~.tf.layers.ConvBlock`.

        Returns
        -------
        tf.Tensor
        """
        kwargs = cls.fill_params('initial_block', **kwargs)
        if kwargs.get('layout'):
            return conv_block(inputs, name=name, **kwargs)
        return inputs
github analysiscenter / batchflow / batchflow / models / tf / inception_v4.py View on Github external
x = conv_block(x, layout, filters[1], 3, name='conv_3_3_3', **kwargs)

            branch_3 = conv_block(x, layout, filters[2], 3, name='conv_3', strides=2, padding='valid', **kwargs)
            branch_pool = conv_block(x, layout='p', name='max_pool', padding='valid', **kwargs)
            x = tf.concat([branch_3, branch_pool], axis, name='concat_3_and_pool')

            branch_1 = conv_block(x, layout, filters[1], 1, name='conv_1', **kwargs)
            branch_1_3 = conv_block(branch_1, layout, filters[2], 3, name='conv_1_3', padding='valid', **kwargs)

            branch_1_7 = conv_block(x, layout*3, [filters[1]]*3, [1, [7, 1], [1, 7]], name='conv_1_7', **kwargs)
            branch_1_7_3 = conv_block(branch_1_7, layout, filters[2], 3, name='conv_1_7_3', padding='valid', **kwargs)
            x = tf.concat([branch_1_3, branch_1_7_3], axis, name='concat_1_3_and_1_7_3')

            branch_out_3 = conv_block(x, layout, filters[3], 3, name='conv_out_3', strides=2,
                                      padding='valid', **kwargs)
            branch_out_pool = conv_block(x, layout='p', name='out_max_pooling', padding='valid', **kwargs)

            output = tf.concat([branch_out_3, branch_out_pool], axis, name='output')
        return output
github analysiscenter / batchflow / batchflow / models / tf / inception_resnet_v2.py View on Github external
number of output filters
        name : str
            scope name

        Returns
        -------
        tf.Tensor
        """
        with tf.variable_scope(name):
            x = inputs
            branch_1 = conv_block(x, 'p', pool_size=3, pool_strides=2, name='max-pool', **kwargs)
            branch_2 = conv_block(x, layout*2, [filters[0], filters[1]], [1, 3], strides=[1, 2],
                                  name='conv_2', **kwargs)
            branch_3 = conv_block(x, layout*2, [filters[2], filters[3]], [1, 3], strides=[1, 2],
                                  name='conv_3', **kwargs)
            branch_4 = conv_block(x, layout*3, [filters[4], filters[5], filters[6]], [1, 3, 3], strides=[1, 1, 2],
                                  name='conv_4', **kwargs)

            axis = cls.channels_axis(kwargs['data_format'])
            x = tf.concat([branch_1, branch_2, branch_3, branch_4], axis)

        return x
github analysiscenter / batchflow / batchflow / models / tf / faster_rcnn.py View on Github external
def _rpn_head(self, inputs, name='rpn_head', **kwargs):
        n_anchors = self.n_anchors
        anchors = self.anchors_placeholders['anchors']
        anchor_reg = self.anchors_placeholders['reg']
        anchor_clsf = self.anchors_placeholders['clsf']
        anchor_batch = self.anchors_placeholders['batch']

        with tf.variable_scope(name):

            rpn_reg = conv_block(inputs, 'c', filters=4*9, kernel_size=1, name='conv_reg', **kwargs)
            rpn_clsf = conv_block(inputs, 'c', filters=1*9, kernel_size=1, name='conv_clsf', **kwargs)

            if kwargs['data_format'] == 'channels_first':
                rpn_reg = tf.transpose(rpn_reg, [0, 2, 3, 1])
                rpn_clsf = tf.transpose(rpn_clsf, [0, 2, 3, 1])


            rpn_reg = tf.reshape(rpn_reg, [-1, n_anchors, 4])
            rpn_clsf = tf.reshape(rpn_clsf, [-1, n_anchors])

            anchor_reg_param = self.parametrize(anchor_reg, anchors)

            loss = self.rpn_loss(rpn_reg, rpn_clsf, anchor_reg_param, anchor_clsf, anchor_batch)
            loss = tf.identity(loss, 'loss')

            rpn_reg = tf.identity(self.unparametrize(rpn_reg, anchors), 'reg')
            rpn_clsf = tf.sigmoid(rpn_clsf, 'clsf')
github analysiscenter / batchflow / batchflow / models / tf / inception_v4.py View on Github external
-------
        tf.Tensor
        """
        with tf.variable_scope(name):
            branch_1 = conv_block(inputs, layout, filters[0], 1, name='conv_1_3', **kwargs)

            factor = [[1, 7], [7, 1]]
            kernel_size = [1, *factor]
            branch_1_7 = conv_block(inputs, layout*3, [filters[1], filters[2], filters[3]], kernel_size,
                                    name='conv_1_7', **kwargs)

            kernel_size = [1, *factor*2]
            branch_1_7_7 = conv_block(inputs, layout*5, [filters[1]]*2+[filters[2]]*2+[filters[3]], kernel_size,
                                      name='conv_1_7_7', **kwargs)

            branch_pool = conv_block(inputs, 'v'+layout, filters[4], 1, name='c_pool', **{**kwargs, 'pool_strides': 1})

            axis = cls.channels_axis(kwargs['data_format'])
            output = tf.concat([branch_1, branch_1_7, branch_1_7_7, branch_pool], axis, name='output')
        return output
github analysiscenter / batchflow / batchflow / models / tf / inception_resnet_v2.py View on Github external
input tensor
        filters : tuple of 7 int
            number of output filters
        name : str
            scope name

        Returns
        -------
        tf.Tensor
        """
        with tf.variable_scope(name):
            x = inputs
            branch_1 = conv_block(x, 'p', pool_size=3, pool_strides=2, name='max-pool', **kwargs)
            branch_2 = conv_block(x, layout*2, [filters[0], filters[1]], [1, 3], strides=[1, 2],
                                  name='conv_2', **kwargs)
            branch_3 = conv_block(x, layout*2, [filters[2], filters[3]], [1, 3], strides=[1, 2],
                                  name='conv_3', **kwargs)
            branch_4 = conv_block(x, layout*3, [filters[4], filters[5], filters[6]], [1, 3, 3], strides=[1, 1, 2],
                                  name='conv_4', **kwargs)

            axis = cls.channels_axis(kwargs['data_format'])
            x = tf.concat([branch_1, branch_2, branch_3, branch_4], axis)

        return x
github analysiscenter / batchflow / batchflow / models / tf / inception_v1.py View on Github external
- number of filters in 1x1 conv going before conv 3x3
            - number of filters in 3x3 conv
            - number of filters in 1x1 conv going before conv 5x5,
            - number of filters in 5x5 conv,
            - number of filters in 1x1 conv going before max-pooling
        layout : str
            a sequence of layers in the block. Default is 'cn'.
        name : str
            scope name

        Returns
        -------
        tf.Tensor
        """
        with tf.variable_scope(name):
            branch_1 = conv_block(inputs, layout, filters[0], 1, name='conv_1', **kwargs)

            branch_3 = conv_block(inputs, layout*2, [filters[1], filters[2]], [1, 3], name='conv_3', **kwargs)

            branch_5 = conv_block(inputs, layout*2, [filters[3], filters[4]], [1, 5], name='conv_5', **kwargs)

            branch_pool = conv_block(inputs, 'p'+layout, filters[5], 1, 'conv_pool', **{**kwargs, 'pool_strides': 1})

            axis = cls.channels_axis(kwargs['data_format'])
            output = tf.concat([branch_1, branch_3, branch_5, branch_pool], axis, name='output')
        return output
github analysiscenter / batchflow / batchflow / models / tf / fcn.py View on Github external
""" Base layers

        Parameters
        ----------
        inputs : tf.Tensor
            input tensor
        num_classes : int
            number of classes

        Returns
        -------
        tf.Tensor
        """
        _ = num_classes
        kwargs = cls.fill_params('body', **kwargs)
        return conv_block(inputs, name=name, **kwargs)