Esempio n. 1
0
def fusion_net(feature_list, num_class, out_shape=(8,3)):

    num=len(feature_list)

    input = None
    with tf.variable_scope('fuse-input') as scope:
        for n in range(num):
            feature     = feature_list[n][0]
            roi         = feature_list[n][1]
            pool_height = feature_list[n][2]
            pool_width  = feature_list[n][3]
            pool_scale  = feature_list[n][4]
            if (pool_height==0 or pool_width==0): continue

            roi_features,  roi_idxs = tf_roipooling(feature,roi, pool_height, pool_width, pool_scale, name='%d/pool'%n)
            roi_features = flatten(roi_features)
            if input is None:
                input = roi_features
            else:
                input = concat([input,roi_features], axis=1, name='%d/cat'%n)

    with tf.variable_scope('fuse-block-1') as scope:
        block = linear_bn_relu(input, num_hiddens=256, name='1')
        block = linear_bn_relu(block, num_hiddens=256, name='2')

    #include background class
    with tf.variable_scope('fuse') as scope:
        dim = np.product([*out_shape])
        scores  = linear(block, num_hiddens=num_class,     name='score')
        probs   = tf.nn.softmax (scores, name='prob')
        deltas  = linear(block, num_hiddens=dim*num_class, name='box')
        deltas  = tf.reshape(deltas,(-1,num_class,*out_shape))

    return  scores, probs, deltas
def fusion_net(feature_list, num_class, out_shape=(8,3)):

    test_num = 1
    print('\n\n !!!! test_num ={}\n\n'.format(test_num))

    if test_num==0:
        num=len(feature_list)

        input = None
        with tf.variable_scope('fuse-input') as scope:
            feature_names=['top_feature','front_feature','rgb_feature']
            for n in range(num):
                feature     = feature_list[n][0]
                roi         = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width  = feature_list[n][3]
                pool_scale  = feature_list[n][4]
                if (pool_height==0 or pool_width==0): continue

                roi_features,  roi_idxs = tf_roipooling(feature,roi, pool_height, pool_width,
                                                        pool_scale, name='%d/pool'%n)
                roi_features = flatten(roi_features)
                tf.summary.histogram(feature_names[n],roi_features)

                if input is None:
                    input = roi_features
                else:
                    input = concat([input,roi_features], axis=1, name='%d/cat'%n)

        with tf.variable_scope('fuse-block-1') as scope:
            block = linear_bn_relu(input, num_hiddens=512, name='1')
            block = linear_bn_relu(block, num_hiddens=512, name='2')
            block = linear_bn_relu(block, num_hiddens=512, name='3')
            block = linear_bn_relu(block, num_hiddens=512, name='4')


    elif test_num==1:
        with tf.variable_scope('fuse-net') as scope:
            num = len(feature_list)
            feature_names = ['top', 'front', 'rgb']
            roi_features_list = []
            for n in range(num):
                feature = feature_list[n][0]
                roi = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width = feature_list[n][3]
                pool_scale = feature_list[n][4]
                if (pool_height == 0 or pool_width == 0): continue

                with tf.variable_scope(feature_names[n] + '-roi-pooling'):
                    roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                           pool_scale, name='%s-roi_pooling' % feature_names[n])
                with tf.variable_scope(feature_names[n]+ '-feature-conv'):

                    with tf.variable_scope('block1') as scope:
                        block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                               stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                        residual=block

                        block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                               padding='SAME',name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')
                    with tf.variable_scope('block2') as scope:

                        block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_1')
                        residual = block
                        block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')
                    with tf.variable_scope('block3') as scope:

                        block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_1')
                        residual = block
                        block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')


                    roi_features = flatten(block)
                    tf.summary.histogram(feature_names[n], roi_features)
                    roi_features_list.append(roi_features)

            with tf.variable_scope('rois-feature-concat'):
                block = concat(roi_features_list, axis=1, name='concat')


    elif test_num==2:
        num = len(feature_list)

        input = None
        with tf.variable_scope('fuse-input') as scope:
            feature_names = ['top_feature', 'front_feature', 'rgb_feature']
            for n in range(num):
                feature = feature_list[n][0]
                roi = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width = feature_list[n][3]
                pool_scale = feature_list[n][4]
                if (pool_height == 0 or pool_width == 0): continue


                roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                       pool_scale, name='%d/pool' % n)

                with tf.variable_scope('roipooling-conv1') as scope:
                    block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                           stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                    residual=block

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                           padding='SAME',name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('roipooling-conv2') as scope:

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('roipooling-conv3') as scope:

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')


                roi_features = flatten(block)
                tf.summary.histogram(feature_names[n], roi_features)

                if input is None:
                    input = roi_features
                else:
                    input = concat([input, roi_features], axis=1, name='%d/cat' % n)
            block = linear_bn_relu(input,128)


        # include background class
        with tf.variable_scope('fuse') as scope:
            dim = np.product([*out_shape])
            scores = linear(block, num_hiddens=num_class, name='score')
            probs = tf.nn.softmax(scores, name='prob')
            deltas = linear(block, num_hiddens=dim * num_class, name='box')
            deltas = tf.reshape(deltas, (-1, num_class, *out_shape))


    return  block
Esempio n. 3
0
def fusion_net(feature_list, num_class, out_shape=(8,3)):
  stride=8
  num=len(feature_list)

  input = None
  with tf.variable_scope('fuse-input') as scope:
    for n in range(num):
        feature     = feature_list[n][0]
        roi         = feature_list[n][1]
        pool_height = feature_list[n][2]
        pool_width  = feature_list[n][3]
        pool_scale  = feature_list[n][4]
        if (pool_height==0 or pool_width==0): continue
        # feature   = conv2d_bn_relu(feature, num_kernels=512, kernel_size=(3,3), stride=[1,1,1,1], padding='SAME', name='%d'%n)
        roi_features,  roi_idxs = tf_roipooling(feature,roi, pool_height, pool_width, pool_scale, name='%d/pool'%n)
        # pdb.set_trace()
        roi_features=flatten(roi_features)
        with tf.variable_scope('fuse-block-1-%d'%n):
          tf.summary.histogram('fuse-block_input_%d'%n, roi_features)
          block = linear_bn_relu(roi_features, num_hiddens=512, name='1')#512, so small?
          tf.summary.histogram('fuse-block1_%d'%n, block)
          block = tf.nn.dropout(block, keep_prob, name='drop1')
          block = linear_bn_relu(block, num_hiddens=512, name='2')
          tf.summary.histogram('fuse-block2_%d'%n, block)
          block = tf.nn.dropout(block, keep_prob, name='drop2')
          block = linear_bn_relu(roi_features, num_hiddens=512, name='3')#512, so small?
          block = tf.nn.dropout(block, keep_prob, name='drop3')
          

        if input is None:
            input = block
        else:
            input = concat([input,block], axis=1, name='%d/cat'%n)

        # if input is None:
        #     input = roi_features
        # else:
        #     input = concat([input,roi_features], axis=1, name='%d/cat'%n)

  # with tf.variable_scope('fuse-block-1') as scope:
  #   input_=None
  #   for i in len(feat):
  #     with tf.variable_scope('fc%d'%i):
  #       tf.summary.histogram('fuse-block_input_%d'%i, feat[i])
  #       block = linear_bn_relu(feat[i], num_hiddens=4096, name='1')#512, so small?
  #       tf.summary.histogram('fuse-block1_%d'%i, block)
  #       block = tf.nn.dropout(block, keep_prob, name='drop1')
  #       block = linear_bn_relu(block, num_hiddens=4096, name='2')
  #       tf.summary.histogram('fuse-block2_%d'%i, block)
  #       block = tf.nn.dropout(block, keep_prob, name='drop2')
  #       if input_ is None:
  #           input_ = block
  #       else:
  #           input_ = concat([input_,block], axis=1, name='%d/cat'%n)
    # block = linear_bn_relu(block, num_hiddens=512, name='3')
    # block = linear_bn_relu(block, num_hiddens=512, name='4')

  #include background class
  with tf.variable_scope('fuse') as scope:
    block = linear_bn_relu(input, num_hiddens=512, name='4')#512, so small?
    block = tf.nn.dropout(block, keep_prob, name='drop4')
    dim = np.product([*out_shape])
    scores  = linear(block, num_hiddens=num_class,     name='score')
    probs   = tf.nn.softmax (scores, name='prob')
    deltas  = linear(block, num_hiddens=dim*num_class, name='box')
    deltas  = tf.reshape(deltas,(-1,num_class,*out_shape))

  return  scores, probs, deltas
Esempio n. 4
0
def fusion_net(feature_list, num_class, out_shape=(8,3)):

    with tf.variable_scope('fuse-net') as scope:
        num = len(feature_list)
        feature_names = ['top', 'front', 'rgb']
        roi_features_list = []
        for n in range(num):
            feature = feature_list[n][0]
            roi = feature_list[n][1]
            pool_height = feature_list[n][2]
            pool_width = feature_list[n][3]
            pool_scale = feature_list[n][4]
            if (pool_height == 0 or pool_width == 0): continue

            with tf.variable_scope(feature_names[n] + '-roi-pooling'):
                roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                       pool_scale, name='%s-roi_pooling' % feature_names[n])
            with tf.variable_scope(feature_names[n]+ '-feature-conv'):

                with tf.variable_scope('block1') as scope:
                    block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                           stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                    residual=block

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                           padding='SAME',name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('block2') as scope:

                    block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('block3') as scope:

                    block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')


                roi_features = flatten(block)
                tf.summary.histogram(feature_names[n], roi_features)
                roi_features_list.append(roi_features)

        with tf.variable_scope('rois-feature-concat'):
            block = concat(roi_features_list, axis=1, name='concat')

        with tf.variable_scope('fusion-feature-fc'):
            print('\nUse fusion-feature-2fc')
            block = linear_bn_relu(block, num_hiddens=512, name='1')
            block = linear_bn_relu(block, num_hiddens=512, name='2')

    return  block
Esempio n. 5
0
def fusion_net(feature_list, num_class, out_shape=(8,3)):

    test_num = 1
    print('\n\n !!!! test_num ={}\n\n'.format(test_num))

    if test_num==0:
        num=len(feature_list)

        input = None
        with tf.variable_scope('fuse-input') as scope:
            feature_names=['top_feature','front_feature','rgb_feature']
            for n in range(num):
                feature     = feature_list[n][0]
                roi         = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width  = feature_list[n][3]
                pool_scale  = feature_list[n][4]
                if (pool_height==0 or pool_width==0): continue

                roi_features,  roi_idxs = tf_roipooling(feature,roi, pool_height, pool_width,
                                                        pool_scale, name='%d/pool'%n)
                roi_features = flatten(roi_features)
                tf.summary.histogram(feature_names[n],roi_features)

                if input is None:
                    input = roi_features
                else:
                    input = concat([input,roi_features], axis=1, name='%d/cat'%n)

        with tf.variable_scope('fuse-block-1') as scope:
            block = linear_bn_relu(input, num_hiddens=512, name='1')
            block = linear_bn_relu(block, num_hiddens=512, name='2')
            block = linear_bn_relu(block, num_hiddens=512, name='3')
            block = linear_bn_relu(block, num_hiddens=512, name='4')


    elif test_num==1:
        with tf.variable_scope('fuse-net') as scope:
            num = len(feature_list)
            feature_names = ['top', 'front', 'rgb']
            roi_features_list = []
            for n in range(num):
                feature = feature_list[n][0]
                roi = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width = feature_list[n][3]
                pool_scale = feature_list[n][4]
                if (pool_height == 0 or pool_width == 0): continue

                with tf.variable_scope(feature_names[n] + '-roi-pooling'):
                    roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                           pool_scale, name='%s-roi_pooling' % feature_names[n])
                with tf.variable_scope(feature_names[n]+ '-feature-conv'):

                    with tf.variable_scope('block1') as scope:
                        block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                               stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                        residual=block

                        block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                               padding='SAME',name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')
                    with tf.variable_scope('block2') as scope:

                        block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_1')
                        residual = block
                        block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')
                    with tf.variable_scope('block3') as scope:

                        block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_1')
                        residual = block
                        block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                               name=feature_names[n]+'_conv_2')+residual

                        block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                        padding='SAME', name=feature_names[n]+'_max_pool')


                    roi_features = flatten(block)
                    tf.summary.histogram(feature_names[n], roi_features)
                    roi_features_list.append(roi_features)

            with tf.variable_scope('rois-feature-concat'):
                block = concat(roi_features_list, axis=1, name='concat')

            with tf.variable_scope('fusion-feature-fc'):
                block = linear_bn_relu(block, num_hiddens=512, name='1')
                block = linear_bn_relu(block, num_hiddens=512, name='2')
                block = linear_bn_relu(block, num_hiddens=512, name='3')
                block = linear_bn_relu(block, num_hiddens=512, name='4')


    elif test_num==2:
        num = len(feature_list)

        input = None
        with tf.variable_scope('fuse-input') as scope:
            feature_names = ['top_feature', 'front_feature', 'rgb_feature']
            for n in range(num):
                feature = feature_list[n][0]
                roi = feature_list[n][1]
                pool_height = feature_list[n][2]
                pool_width = feature_list[n][3]
                pool_scale = feature_list[n][4]
                if (pool_height == 0 or pool_width == 0): continue


                roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                       pool_scale, name='%d/pool' % n)

                with tf.variable_scope('roipooling-conv1') as scope:
                    block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                           stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                    residual=block

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                           padding='SAME',name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('roipooling-conv2') as scope:

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('roipooling-conv3') as scope:

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')


                roi_features = flatten(block)
                tf.summary.histogram(feature_names[n], roi_features)

                if input is None:
                    input = roi_features
                else:
                    input = concat([input, roi_features], axis=1, name='%d/cat' % n)
            block = linear_bn_relu(input,128)


        # include background class
        with tf.variable_scope('fuse') as scope:
            dim = np.product([*out_shape])
            scores = linear(block, num_hiddens=num_class, name='score')
            probs = tf.nn.softmax(scores, name='prob')
            deltas = linear(block, num_hiddens=dim * num_class, name='box')
            deltas = tf.reshape(deltas, (-1, num_class, *out_shape))


    return  block
Esempio n. 6
0
def fusion_net(feature_list, num_class, out_shape=(2, 2)):
    num = len(feature_list)

    input = None
    with tf.variable_scope('fuse-input') as scope:
        for n in range(num):
            feature = feature_list[n][0]
            roi = feature_list[n][1]
            pool_height = feature_list[n][2]
            pool_width = feature_list[n][3]
            pool_scale = feature_list[n][4]
            if (pool_height == 0 or pool_width == 0): continue
            # feature   = conv2d_bn_relu(feature, num_kernels=512, kernel_size=(3,3), stride=[1,1,1,1], padding='SAME', name='%d'%n)
            roi_features, roi_idxs = tf_roipooling(feature,
                                                   roi,
                                                   pool_height,
                                                   pool_width,
                                                   pool_scale,
                                                   name='%d/pool' % n)
            # pdb.set_trace()
            roi_features = flatten(roi_features)
            # roi_features_ = tf.stop_gradient(roi_features)

            with tf.variable_scope('fuse-block-1-%d' % n):
                tf.summary.histogram('fuse-block_input_%d' % n, roi_features)
                block = linear_bn_relu(roi_features,
                                       num_hiddens=2048,
                                       name='1')  #512, so small?
                tf.summary.histogram('fuse-block1_%d' % n, block)
                block = tf.nn.dropout(block, CFG.KEEPPROBS, name='drop1')

            if input is None:
                input = block
            else:
                # input = concat([input,block], axis=1, name='%d/cat'%n)
                input = tf.add(input, block, name='fuse_feature')
        # input_ = tf.stop_gradient(input)
    input_ = input
    #include background class
    with tf.variable_scope('fuse') as scope:
        block = linear_bn_relu(input_, num_hiddens=512,
                               name='4')  #512, so small?
        # block = tf.stop_gradient(block)
        block = tf.nn.dropout(block, CFG.KEEPPROBS, name='drop4')
        with tf.variable_scope('2D') as sc:
            dim = np.product([*out_shape])
            scores_3d = linear(block, num_hiddens=num_class, name='score')
            probs_3d = tf.nn.softmax(scores_3d, name='prob')
            deltas_3d = linear(block, num_hiddens=dim * num_class, name='box')
            deltas_3d = tf.reshape(deltas_3d, (-1, num_class, *out_shape))
        with tf.variable_scope('3D') as sc_:
            block3D = linear_bn_relu(roi_features, num_hiddens=2048,
                                     name='1')  #512, so small?
            block3D_1 = tf.nn.dropout(block3D, CFG.KEEPPROBS, name='drop1')
            block = linear_bn_relu(block3D_1, num_hiddens=512, name='3D')
            # block = tf.nn.dropout(block, CFG.KEEPPROBS , name='drop4')
            dim = np.product(16)
            deltas_2d = linear(block, num_hiddens=dim * num_class, name='box')
            deltas_2d = tf.reshape(deltas_2d, (-1, num_class, 16))
        # scores_3d = tf.stop_gradient(scores_3d)
        # probs_3d = tf.stop_gradient(probs_3d)
        # deltas_3d = tf.stop_gradient(deltas_3d)

    return scores_3d, probs_3d, deltas_3d, deltas_2d
Esempio n. 7
0
def fusion_net(feature_list, num_class, out_shape=(8,3)):

    with tf.variable_scope('fuse-net') as scope:
        num = len(feature_list)
        feature_names = ['top', 'front', 'rgb']
        roi_features_list = []
        for n in range(num):
            feature = feature_list[n][0]
            roi = feature_list[n][1]
            pool_height = feature_list[n][2]
            pool_width = feature_list[n][3]
            pool_scale = feature_list[n][4]
            if (pool_height == 0 or pool_width == 0): continue

            with tf.variable_scope(feature_names[n] + '-roi-pooling'):
                roi_features, roi_idxs = tf_roipooling(feature, roi, pool_height, pool_width,
                                                       pool_scale, name='%s-roi_pooling' % feature_names[n])
            with tf.variable_scope(feature_names[n]+ '-feature-conv'):

                with tf.variable_scope('block1') as scope:
                    block = conv2d_bn_relu(roi_features, num_kernels=128, kernel_size=(3, 3),
                                           stride=[1, 1, 1, 1], padding='SAME',name=feature_names[n]+'_conv_1')
                    residual=block

                    block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(3, 3), stride=[1, 1, 1, 1],
                                           padding='SAME',name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('block2') as scope:

                    block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=256, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')
                with tf.variable_scope('block3') as scope:

                    block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_1')
                    residual = block
                    block = conv2d_bn_relu(block, num_kernels=512, kernel_size=(3, 3), stride=[1, 1, 1, 1], padding='SAME',
                                           name=feature_names[n]+'_conv_2')+residual

                    block = avgpool(block, kernel_size=(2, 2), stride=[1, 2, 2, 1],
                                    padding='SAME', name=feature_names[n]+'_max_pool')


                roi_features = flatten(block)
                tf.summary.histogram(feature_names[n], roi_features)
                roi_features_list.append(roi_features)

        with tf.variable_scope('rois-feature-concat'):
            block = concat(roi_features_list, axis=1, name='concat')

        with tf.variable_scope('fusion-feature-fc'):
            print('\nUse fusion-feature-2fc')
            block = linear_bn_relu(block, num_hiddens=512, name='1')
            block = linear_bn_relu(block, num_hiddens=512, name='2')

    return  block