faster-rcnn for tensorflow 测试过程

如有错误,望大家指出!

1 训练过程见之前写的两篇博客:
http://blog.csdn.net/weiguanqun/article/details/78754898
http://blog.csdn.net/weiguanqun/article/details/78765502
之后的测试过程是基于之前的训练过程的。

2 本文的测试程序是在源码 https://github.com/dBeker/Faster-RCNN-TensorFlow-Python3.5的基础之上进行改进。
测试程序为:demo.py
这里写图片描述

3 修改demo中的部分程序适应自己的程序:
我把图像的结果保存了下来
修改一:

修改了类的个数:3

if demonet == 'vgg16':
        net = vgg16(batch_size=1)
    # elif demonet == 'res101':
        # net = resnetv1(batch_size=1, num_layers=101)
    else:
        raise NotImplementedError
    net.create_architecture(sess, "TEST", 3, tag='default', anchor_scales=[8, 16, 32])
    saver = tf.train.Saver()
    saver.restore(sess, tfmodel)

修改二:

弃用了vis_detections函数,把vis_detections函数的东西直接写到了demo中进行画图
save_jpg :为存储路径

def demo(sess, net, image_name):
    # Load the demo image
    im_file = os.path.join(cfg.FLAGS2["data_dir"], 'test', image_name)
    im = cv2.imread(im_file)

    # Detect all object classes and regress object bounds
    timer = Timer()
    timer.tic()
    scores, boxes = im_detect(sess, net, im)
    timer.toc()
    print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0]))
    save_jpg = os.path.join('E:\\WGQ\\TF-fasterRcnn\\Faster-RCNN-TensorFlow-Python3.5-master\\data\\save_test',
                            image_name)
    # Visualize detections for each class
    CONF_THRESH = 0.1
    NMS_THRESH = 0.1
    fig, ax = plt.subplots(figsize=(12, 12))
    im = im[:, :, (2, 1, 0)]
    ax.imshow(im, aspect='equal')
    plt.axis('off')
    plt.tight_layout()
    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack((cls_boxes,
                          cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, NMS_THRESH)
        dets = dets[keep, :]
        #vis_detections(im, cls, dets,image_name, thresh=CONF_THRESH)
        inds = np.where(dets[:, -1] >= 0.5)[0]

        #print('Detected {:d} BoundingBox'.format(len(inds)))
        if len(inds) != 0:
            #print('Detected {:d} BoundingBox'.format(len(inds)))
            #im = im[:, :, (2, 1, 0)]
            for i in inds:
                bbox = dets[i, :4]
                score = dets[i, -1]
                ax.add_patch(
                    plt.Rectangle((bbox[0], bbox[1]),
                                  bbox[2] - bbox[0],
                                  bbox[3] - bbox[1], fill=False,
                                  edgecolor='red', linewidth=3.5)
                )
                ax.text(bbox[0], bbox[1] - 2,
                        '{:s} {:.3f}'.format(cls, score),
                        bbox=dict(facecolor='blue', alpha=0.5),
                        fontsize=14, color='white')

            # ax.set_title(('{} detections with '
            #               'p({} | box) >= {:.1f}').format(class_name, class_name,
            #                                               thresh),
            #              fontsize=14)
            plt.draw()
            #im = im[:, :, (2, 1, 0)]
            #fig, ax = plt.subplots(figsize=(12, 12))
            #ax.imshow(im, aspect='equal')
            #plt.axis('off')
            #plt.tight_layout()
            #plt.savefig(save_jpg)
            # cv2.imwrite(save_jpg,im)
            #return
        # else:
        #     im = im[:, :, :]
        #     fig, ax = plt.subplots(figsize=(12, 12))
        #     ax.imshow(im, aspect='equal')
        #     plt.axis('off')
        #     plt.tight_layout()
    plt.savefig(save_jpg)

“`

4 出现的错误基本上都是路径错误,在此不再贴出,贴出实验结果与截图:

速度:
这里写图片描述

结果:
这里写图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# 工程内容 这个程序是基于tensorflow的tflearn库实现部分RCNN功能。 # 开发环境 windows10 + python3.5 + tensorflow1.2 + tflearn + cv2 + scikit-learn # 数据集 采用17flowers据集, 官网下载:http://www.robots.ox.ac.uk/~vgg/data/flowers/17/ # 程序说明 1、setup.py---初始化路径 2、config.py---配置 3、tools.py---进度条和显示带框图像工具 4、train_alexnet.py---大数据集预训练Alexnet网络,140个epoch左右,bitch_size为64 5、preprocessing_RCNN.py---图像的处理(选择性搜索、数据存取等) 6、selectivesearch.py---选择性搜索源码 7、fine_tune_RCNN.py---小数据集微调Alexnet 8、RCNN_output.py---训练SVM并测试RCNN测试的时候测试图片选择第7、16类中没有参与训练的,单朵的花效果好,因为训练用的都是单朵的) # 文件说明 1、train_list.txt---预训练数据,数据在17flowers文件夹中 2、fine_tune_list.txt---微调数据2flowers文件夹中 3、1.png---直接用选择性搜索的区域划分 4、2.png---通过RCNN后的区域划分 # 程序问题 1、由于数据集小的原因,在微调时候并没有像论文一样按一个bitch32个正样本,128个负样本输入,感觉正样本过少; 2、还没有懂最后是怎么给区域打分的,所有非极大值抑制集合canny算子没有进行,待续; 3、对选择的区域是直接进行缩放的; 4、由于数据集合论文采用不一样,但是微调和训练SVM时采用的IOU阈值一样,有待调参。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值