예제 #1
0
파일: mv3d_net.py 프로젝트: erickwan/MV3D
def top_feature_net_r(input, anchors, inds_inside, num_bases):
    """
    :param input: 
    :param anchors: 
    :param inds_inside: 
    :param num_bases: 
    :return: 
            top_features, top_scores, top_probs, top_deltas, proposals, proposal_scores
    """
    stride=1.
    #with tf.variable_scope('top-preprocess') as scope:
    #    input = input
    batch_size, img_height, img_width, img_channel = input.get_shape().as_list()

    with tf.variable_scope('feature-extract-resnet') as scope:
        print('build_resnet')
        block = ResnetBuilder.resnet_tiny_smaller_kernel(input)
        feature = block

        top_feature_stride = 4
        # resnet_input = resnet.get_layer('input_1').input
        # resnet_output = resnet.get_layer('add_7').output
        # resnet_f = Model(inputs=resnet_input, outputs=resnet_output)  # add_7
        # # print(resnet_f.summary())
        # block = resnet_f(input)
        block = upsample2d(block, factor=2, has_bias=True, trainable=True, name='upsampling')



    with tf.variable_scope('predict') as scope:
        # block = upsample2d(block, factor=4, has_bias=True, trainable=True, name='1')
        # up     = block
        # kernel_size = config.cfg.TOP_CONV_KERNEL_SIZE
        top_anchors_stride = 2
        block = conv2d_bn_relu(block, num_kernels=128, kernel_size=(1, 1), stride=[1, 1, 1, 1], padding='SAME', name='2')
        scores = conv2d(block, num_kernels=2 * num_bases, kernel_size=(1, 1), stride=[1, 1, 1, 1], padding='SAME',name='score')
        probs = tf.nn.softmax(tf.reshape(scores, [-1, 2]), name='prob')
        deltas = conv2d(block, num_kernels=4 * num_bases, kernel_size=(1, 1), stride=[1, 1, 1, 1], padding='SAME',name='delta')

    #<todo> flip to train and test mode nms (e.g. different nms_pre_topn values): use tf.cond
    with tf.variable_scope('NMS') as scope:    #non-max

        img_scale = 1
        rois, roi_scores = tf_rpn_nms( probs, deltas, anchors, inds_inside,
                                       stride, img_width, img_height, img_scale,
                                       nms_thresh=0.3, min_size=stride, nms_pre_topn=6000, nms_post_topn=100,
                                       name ='nms')



    print ('top: scale=%f, stride=%d'%(1./stride, stride))
    return feature, scores, probs, deltas, rois, roi_scores, top_anchors_stride,top_feature_stride
예제 #2
0
def top_feature_net_r(input, anchors, inds_inside, num_bases):
    """
    :param input: 
    :param anchors: 
    :param inds_inside: 
    :param num_bases: 
    :return: 
            top_features, top_scores, top_probs, top_deltas, proposals, proposal_scores
    """
    batch_size, img_height, img_width, img_channel = input.get_shape().as_list(
    )

    with tf.variable_scope('feature-extract-resnet') as scope:
        print('build_resnet')
        block = ResnetBuilder.resnet_tiny_smaller_kernel(input)
        feature = block

        top_feature_stride = 4
        # resnet_input = resnet.get_layer('input_1').input
        # resnet_output = resnet.get_layer('add_7').output
        # resnet_f = Model(inputs=resnet_input, outputs=resnet_output)  # add_7
        # # print(resnet_f.summary())
        # block = resnet_f(input)
        block = upsample2d(block,
                           factor=2,
                           has_bias=True,
                           trainable=True,
                           name='upsampling')

    with tf.variable_scope('predict') as scope:
        # block = upsample2d(block, factor=4, has_bias=True, trainable=True, name='1')
        # up     = block
        # kernel_size = config.cfg.TOP_CONV_KERNEL_SIZE
        top_anchors_stride = 2
        block = conv2d_bn_relu(block,
                               num_kernels=128,
                               kernel_size=(1, 1),
                               stride=[1, 1, 1, 1],
                               padding='SAME',
                               name='2')
        scores = conv2d(block,
                        num_kernels=2 * num_bases,
                        kernel_size=(1, 1),
                        stride=[1, 1, 1, 1],
                        padding='SAME',
                        name='score')
        probs = tf.nn.softmax(tf.reshape(scores, [-1, 2]), name='prob')
        deltas = conv2d(block,
                        num_kernels=4 * num_bases,
                        kernel_size=(1, 1),
                        stride=[1, 1, 1, 1],
                        padding='SAME',
                        name='delta')

    with tf.variable_scope('RPN-NMS') as scope:

        train_rois, train_roi_scores = tf_rpn_nms( probs, deltas, anchors, inds_inside, \
                                       top_anchors_stride, img_width, img_height, img_scale=1, \
                                       nms_thresh=0.7, min_size=top_anchors_stride, \
                                       nms_pre_topn=CFG.TRAIN.RPN_NMS_PRE_TOPN, nms_post_topn=CFG.TRAIN.RPN_NMS_POST_TOPN, \
                                       name ='train-rpn-nms')

        infer_rois, infer_roi_scores = tf_rpn_nms( probs, deltas, anchors, inds_inside, \
                                       top_anchors_stride, img_width, img_height, img_scale=1, \
                                       nms_thresh=0.1, min_size=top_anchors_stride, \
                                       nms_pre_topn=CFG.TRAIN.RPN_NMS_PRE_TOPN, nms_post_topn=CFG.TEST.RPN_NMS_POST_TOPN, \
                                       name ='infer-rpn-nms')

    print('top: anchor stride=%d, feature_stride=%d' %
          (top_anchors_stride, top_feature_stride))
    return feature, scores, probs, deltas, train_rois, train_roi_scores, top_anchors_stride,top_feature_stride, \
            infer_rois, infer_roi_scores
예제 #3
0
def top_feature_net_r(input, anchors, inds_inside, num_bases):
    """
    :param input: 
    :param anchors: 
    :param inds_inside: 
    :param num_bases: 
    :return: 
            top_features, top_scores, top_probs, top_deltas, proposals, proposal_scores
    """
    stride = 1.
    #with tf.variable_scope('top-preprocess') as scope:
    #    input = input
    batch_size, img_height, img_width, img_channel = input.get_shape().as_list(
    )

    with tf.variable_scope('feature-extract-resnet') as scope:
        print('build_resnet')
        block = ResnetBuilder.resnet_tiny_smaller_kernel(input)
        feature = block

        top_feature_stride = 4
        # resnet_input = resnet.get_layer('input_1').input
        # resnet_output = resnet.get_layer('add_7').output
        # resnet_f = Model(inputs=resnet_input, outputs=resnet_output)  # add_7
        # # print(resnet_f.summary())
        # block = resnet_f(input)
        block = upsample2d(block,
                           factor=2,
                           has_bias=True,
                           trainable=True,
                           name='upsampling')

    with tf.variable_scope('predict') as scope:
        # block = upsample2d(block, factor=4, has_bias=True, trainable=True, name='1')
        # up     = block
        # kernel_size = config.cfg.TOP_CONV_KERNEL_SIZE
        top_anchors_stride = 2
        block = conv2d_bn_relu(block,
                               num_kernels=128,
                               kernel_size=(1, 1),
                               stride=[1, 1, 1, 1],
                               padding='SAME',
                               name='2')
        scores = conv2d(block,
                        num_kernels=2 * num_bases,
                        kernel_size=(1, 1),
                        stride=[1, 1, 1, 1],
                        padding='SAME',
                        name='score')
        probs = tf.nn.softmax(tf.reshape(scores, [-1, 2]), name='prob')
        deltas = conv2d(block,
                        num_kernels=4 * num_bases,
                        kernel_size=(1, 1),
                        stride=[1, 1, 1, 1],
                        padding='SAME',
                        name='delta')

    #<todo> flip to train and test mode nms (e.g. different nms_pre_topn values): use tf.cond
    with tf.variable_scope('NMS') as scope:  #non-max

        img_scale = 1
        rois, roi_scores = tf_rpn_nms(probs,
                                      deltas,
                                      anchors,
                                      inds_inside,
                                      stride,
                                      img_width,
                                      img_height,
                                      img_scale,
                                      nms_thresh=0.3,
                                      min_size=stride,
                                      nms_pre_topn=6000,
                                      nms_post_topn=100,
                                      name='nms')

    print('top: scale=%f, stride=%d' % (1. / stride, stride))
    return feature, scores, probs, deltas, rois, roi_scores, top_anchors_stride, top_feature_stride