Example #1
0
    def _create_conv(self, input_im):

        VGG_MEAN = [103.939, 116.779, 123.68]

        red, green, blue = tf.split(axis=3,
                                    num_or_size_splits=3,
                                    value=input_im)
        input_bgr = tf.concat(axis=3,
                              values=[
                                  blue - VGG_MEAN[0],
                                  green - VGG_MEAN[1],
                                  red - VGG_MEAN[2],
                              ])

        data_dict = {}
        if self._is_load:
            data_dict = np.load(self._pre_train_path, encoding='latin1').item()

        arg_scope = tf.contrib.framework.arg_scope
        with arg_scope([conv],
                       nl=tf.nn.relu,
                       trainable=False,
                       data_dict=data_dict):
            conv1_1 = conv(input_bgr, 3, 64, 'conv1_1')
            conv1_2 = conv(conv1_1, 3, 64, 'conv1_2')
            pool1 = max_pool(conv1_2, 'pool1', padding='SAME')

            conv2_1 = conv(pool1, 3, 128, 'conv2_1')
            conv2_2 = conv(conv2_1, 3, 128, 'conv2_2')
            pool2 = max_pool(conv2_2, 'pool2', padding='SAME')

            conv3_1 = conv(pool2, 3, 256, 'conv3_1')
            conv3_2 = conv(conv3_1, 3, 256, 'conv3_2')
            conv3_3 = conv(conv3_2, 3, 256, 'conv3_3')
            conv3_4 = conv(conv3_3, 3, 256, 'conv3_4')
            pool3 = max_pool(conv3_4, 'pool3', padding='SAME')

            conv4_1 = conv(pool3, 3, 512, 'conv4_1')
            conv4_2 = conv(conv4_1, 3, 512, 'conv4_2')
            conv4_3 = conv(conv4_2, 3, 512, 'conv4_3')
            conv4_4 = conv(conv4_3, 3, 512, 'conv4_4')
            pool4 = max_pool(conv4_4, 'pool4', padding='SAME')

            conv5_1 = conv(pool4, 3, 512, 'conv5_1')
            conv5_2 = conv(conv5_1, 3, 512, 'conv5_2')
            conv5_3 = conv(conv5_2, 3, 512, 'conv5_3')
            conv5_4 = conv(conv5_3, 3, 512, 'conv5_4')

        return conv5_4
Example #2
0
def inception_layer(inputs,
                    conv_11_size,
                    conv_33_reduce_size, conv_33_size,
                    conv_55_reduce_size, conv_55_size,
                    pool_size,
                    data_dict={},
                    trainable=False,
                    name='inception'):

    arg_scope = tf.contrib.framework.arg_scope
    with arg_scope([conv], nl=tf.nn.relu, trainable=trainable,
                   data_dict=data_dict):
        conv_11 = conv(inputs, 1, conv_11_size, '{}_1x1'.format(name))

        conv_33_reduce = conv(inputs, 1, conv_33_reduce_size,
                              '{}_3x3_reduce'.format(name))
        conv_33 = conv(conv_33_reduce, 3, conv_33_size, '{}_3x3'.format(name))

        conv_55_reduce = conv(inputs, 1, conv_55_reduce_size,
                              '{}_5x5_reduce'.format(name))
        conv_55 = conv(conv_55_reduce, 5, conv_55_size, '{}_5x5'.format(name))

        pool = max_pool(inputs, '{}_pool'.format(name), stride=1,
                        padding='SAME', filter_size=3)
        convpool = conv(pool, 1, pool_size, '{}_pool_proj'.format(name))

    return tf.concat([conv_11, conv_33, conv_55, convpool],
                     3, name='{}_concat'.format(name))
Example #3
0
    def _create_conv(self, inputs):
        self.dropout = tf.placeholder(tf.float32, name='dropout')
        mlpconv_1 = mlpconv(inputs,
                            filter_size=8,
                            hidden_size=[96, 96],
                            name='mlpconv_1',
                            wd=self._wd)
        # mlpconv_1 = mlpconv(
        #     inputs,
        #     filter_size=5,
        #     hidden_size=[192, 160, 96],
        #     name='mlpconv_1',
        #     wd=self._wd)
        mlpconv_1 = max_pool(mlpconv_1, 'pool1', padding='SAME')
        mlpconv_1 = dropout(mlpconv_1, self.dropout, self._is_traing)
        mlpconv_1 = batch_norm(mlpconv_1, train=self._is_traing, name='bn_1')

        mlpconv_2 = mlpconv(mlpconv_1,
                            filter_size=8,
                            hidden_size=[192, 192],
                            name='mlpconv_2',
                            wd=self._wd)
        # mlpconv_2 = mlpconv(
        #     mlpconv_1,
        #     filter_size=5,
        #     hidden_size=[192, 192, 192],
        #     name='mlpconv_2',
        #     wd=self._wd)
        mlpconv_2 = max_pool(mlpconv_2, 'pool2', padding='SAME')
        mlpconv_2 = dropout(mlpconv_2, self.dropout, self._is_traing)
        mlpconv_2 = batch_norm(mlpconv_2, train=self._is_traing, name='bn_2')

        mlpconv_3 = mlpconv(mlpconv_2,
                            filter_size=5,
                            hidden_size=[192, self._n_class],
                            name='mlpconv_3',
                            wd=self._wd)
        # mlpconv_3 = mlpconv(
        #     mlpconv_2,
        #     filter_size=3,
        #     hidden_size=[192, 192, self._n_class],
        #     name='mlpconv_3',
        #     wd=self._wd)
        # mlpconv_3 = max_pool(mlpconv_3, 'pool3', padding='SAME')
        # mlpconv_3 = dropout(pool3, 0.5, self._is_traing)

        return mlpconv_3
Example #4
0
    def _create_conv(self, inputs, data_dict):
        arg_scope = tf.contrib.framework.arg_scope

        with arg_scope([conv],
                       trainable=self._trainable,
                       data_dict=data_dict,
                       nl=tf.nn.relu):
            conv1 = conv(inputs, 7, 64, name='conv1_7x7_s2', stride=2)
            padding1 = tf.constant([[0, 0], [0, 1], [0, 1], [0, 0]])
            conv1_pad = tf.pad(conv1, padding1, 'CONSTANT')
            pool1 = max_pool(conv1_pad,
                             'pool1',
                             padding='VALID',
                             filter_size=3,
                             stride=2)
            pool1_lrn = tf.nn.local_response_normalization(pool1,
                                                           depth_radius=2,
                                                           alpha=2e-05,
                                                           beta=0.75,
                                                           name='pool1_lrn')

            conv2_reduce = conv(pool1_lrn, 1, 64, name='conv2_3x3_reduce')
            conv2 = conv(conv2_reduce, 3, 192, name='conv2_3x3')
            padding2 = tf.constant([[0, 0], [0, 1], [0, 1], [0, 0]])
            conv2_pad = tf.pad(conv2, padding1, 'CONSTANT')
            pool2 = max_pool(conv2_pad,
                             'pool2',
                             padding='VALID',
                             filter_size=3,
                             stride=2)
            pool2_lrn = tf.nn.local_response_normalization(pool2,
                                                           depth_radius=2,
                                                           alpha=2e-05,
                                                           beta=0.75,
                                                           name='pool2_lrn')

        with arg_scope([inception_layer],
                       trainable=self._trainable,
                       data_dict=data_dict):
            inception3a = inception_layer(pool2_lrn,
                                          64,
                                          96,
                                          128,
                                          16,
                                          32,
                                          32,
                                          name='inception_3a')
            inception3b = inception_layer(inception3a,
                                          128,
                                          128,
                                          192,
                                          32,
                                          96,
                                          64,
                                          name='inception_3b')
            pool3 = max_pool(inception3b,
                             'pool3',
                             padding='SAME',
                             filter_size=3,
                             stride=2)

            inception4a = inception_layer(pool3,
                                          192,
                                          96,
                                          208,
                                          16,
                                          48,
                                          64,
                                          name='inception_4a')
            inception4b = inception_layer(inception4a,
                                          160,
                                          112,
                                          224,
                                          24,
                                          64,
                                          64,
                                          name='inception_4b')
            inception4c = inception_layer(inception4b,
                                          128,
                                          128,
                                          256,
                                          24,
                                          64,
                                          64,
                                          name='inception_4c')
            inception4d = inception_layer(inception4c,
                                          112,
                                          144,
                                          288,
                                          32,
                                          64,
                                          64,
                                          name='inception_4d')
            inception4e = inception_layer(inception4d,
                                          256,
                                          160,
                                          320,
                                          32,
                                          128,
                                          128,
                                          name='inception_4e')
            pool4 = max_pool(inception4e,
                             'pool4',
                             padding='SAME',
                             filter_size=3,
                             stride=2)

            inception5a = inception_layer(pool4,
                                          256,
                                          160,
                                          320,
                                          32,
                                          128,
                                          128,
                                          name='inception_5a')
            inception5b = inception_layer(inception5a,
                                          384,
                                          192,
                                          384,
                                          48,
                                          128,
                                          128,
                                          name='inception_5b')

        return inception5b