解决 Faster R-CNN 图片中框不在一张图片上显示的问题

发现问题

在使用demo.py的时候,选取测试用的图片,放到demo,然后修改demo.py中对应的图片名称,然后进行测试:

发现:图片中被框出来的部分并没有完全到一张图片上去,经过多张图片的测试,可以发现,并不是一张图片上一个框,而是按照类别进行的划分,即:每一类一张图片

如何解决这个问题?

原先的画图部分主要在这里:

def vis_detections(im, class_name, dets, thresh=0.5):
"""Draw detected bounding boxes."""
inds = np.where(dets[:, -1] >= thresh)[0]
if len(inds) == 0:
return im = im[:, :, (2, 1, 0)]
fig, ax = plt.subplots(figsize=(12, 12))
ax.imshow(im, aspect='equal')
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(class_name, 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.axis('off')
plt.tight_layout()
plt.draw() def demo(net, image_name):
"""Detect object classes in an image using pre-computed object proposals.""" # Load the demo image
im_file = os.path.join(cfg.DATA_DIR, 'demo', image_name)
im = cv2.imread(im_file) # Detect all object classes and regress object bounds
timer = Timer()
timer.tic()
scores, boxes = im_detect(net, im)
timer.toc()
print ('Detection took {:.3f}s for '
'{:d} object proposals').format(timer.total_time, boxes.shape[0]) # Visualize detections for each class
CONF_THRESH = 0.8
NMS_THRESH = 0.3
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, thresh=CONF_THRESH)

修改为:

# 将检测可视化
def vis_detections(ax,im, class_name, dets, thresh=0.5):
"""Draw detected bounding boxes."""
#print("+_+")
#print(class_name,dets,thresh)
inds = np.where(dets[:, -1] >= thresh)[0]
print("!!!")
#print(inds) # 是否检测出来东西,如果有的话为0如果没有为空
if len(inds) == 0:
return
#print(im.shape) # 4000 6000 3
#调整通道顺序,如果不调整通道顺序,图像就不正常 for i in inds:
bbox = dets[i, :4]
score = dets[i, -1]
#print(bbox[0],bbox[1],bbox[2],bbox[3])
print("add one patch")
ax.add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2] - bbox[0],
bbox[3] - bbox[1], fill=False,
edgecolor='red', linewidth=2)
)
ax.text(bbox[0], bbox[1] - 2,
'{:s} {:.3f}'.format(class_name, score),
bbox=dict(facecolor='white', alpha=0.9),
fontsize=8, color='black')
ax.set_title(('{} detections with '
'p({} | box) >= {:.1f}').format(class_name, class_name,thresh),fontsize=12) def demo(sess, net, image_name):
"""Detect object classes in an image using pre-computed object proposals.""" # Load the demo image
im_file = os.path.join(cfg.FLAGS2["data_dir"], 'demo', image_name)
im = cv2.imread(im_file) # Detect all object classes and regress object bounds
timer = Timer() timer.tic()
# detect the picture to find score and boxes
scores, boxes = im_detect(sess, net, im)
# 检测主体部分,在这里加上save_feature_picture
# 这里的net内容是vgg timer.toc() print('Detection took {:.3f}s for {:d} object proposals'.format(timer.total_time, boxes.shape[0])) # Visualize detections for each class
CONF_THRESH = 0.8
NMS_THRESH = 0.3 im = im[:, :, (2, 1, 0)]
fig, ax = plt.subplots(figsize=(10,10))
ax.imshow(im, aspect='equal') 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(ax,im, cls, dets, thresh=CONF_THRESH)
plt.draw()

点拨:一开始的时候我也没有发现这两个有什么区别,后来发现图片是按照类别进行区分的以后,就可以看出,demo函数中是按照类别进行划分的,所以只要修改plt位置,将plt从vis_detections中放到demo中,这样所有类都会花在同一个plt中,而不会分开了,这样就解决了这个问题。

参考issues

How detect multiple object on same picture?

解决 Faster R-CNN 图片中框不在一张图片上显示的问题的更多相关文章

  1. 解决f.lux总是弹框定位

    解决f.lux总是弹框定位,直接导入成功定位的注册表文件即可. 以下保存为f.lux.reg 双击导入即可. Windows Registry Editor Version 5.00 [HKEY_CU ...

  2. JavaScript解决select下拉框中的内容太长显示不全的问题

    JavaScript解决select下拉框中的内容太长显示不全的问题 1.说明 有些情况下,select下拉框的内容过长,导致部分看不见: 现在通过鼠标事件,让下拉框中的内容显示完全 2.实现源码 & ...

  3. (数据科学学习手札07)R在数据框操作上方法的总结(初级篇)

    上篇我们了解了Python中pandas内封装的关于数据框的常用操作方法,而作为专为数据科学而生的一门语言,R在数据框的操作上则更为丰富精彩,本篇就R处理数据框的常用方法进行总结: 1.数据框的生成 ...

  4. 解决32位plsql客户端连接不64位Oracle11g上数据库

    一.解决方案 因为本人安装的是64位的Oracle,plsql 是32位的故连接不上.网上有方法能连接. 1. 文件下载 下载PLSQL_Developer地址 http://pan.baidu.co ...

  5. Flash Stage3D 在2D UI 界面上显示3D模型问题完美解决

    一直以来很多Stage3D开发者都在为3D模型在2DUI上显示的问题头疼.Stage3D一直是在 Stage2D下面.为了做到3D模型在2DUI上显示通常大家有几种实现方式,下面来说说这几种实现方式吧 ...

  6. 解决pycharm左侧项目文件名中文字体乱码情况?中文显示口口口口.

    解决pycharm左侧项目文件名中文字体乱码情况?中文显示口口口口. 点击file,进入settings 出现 Appearance & Behavior 点击Appearance UI Op ...

  7. 解决boostrap中,iframe渲染下,苹果手机横向无法显示剩余内容问题

    描述: 问题解决了,采用的手势拖动显示剩余内容,并不是有了横向滚动条 在head标签中加入 <head> <meta charset="utf-8"> &l ...

  8. 如何用html把文本框外观格式设为只显示底部的横线

    html把文本框外观格式设为只显示底部的横线 <style> input[type='text']{background:none;border:none;border-bottom:1p ...

  9. 解决Tomcat6解压版在64位windows系统上无法启动服务的问题

    解决Tomcat6解压版在64位windows系统上无法启动服务的问题         由于客户环境为64位windows系统,开发环境一直用32位.tomcat使用6.0.20非安装版.部署时发现在 ...

随机推荐

  1. sencha touch 扩展篇之将sencha touch打包成安装程序(上)- 使用sencha cmd打包安装程序

    由于最近一直忙着android原生的开发,很久没有更新博客了,官方的sencha cmd工具功能非常强大,创建项目,压缩项目,打包安装程序都能轻松实现,这讲我们就给大家介绍下如何使用sencha cm ...

  2. swiper的延迟加载(非官网方法)

    网上找的: https://github.com/nolimits4web/Swiper/issues/626 var tabsSwiper = new Swiper('#games-content' ...

  3. nutch 1.7导入Eclipse

    1.下载Nutch1.7的包 apache-nutch-1.7-src.zip,解压之后应该包括 bin,conf,src等目录 2.将解压之后的 apache-nutch-1.7 文件夹放到ecli ...

  4. 微信小程序 --- 绘画

    cavans及context详解 绘画API的使用 游戏的制作

  5. 线段树(成段更新,区间求和lazy操作 )

    hdu1556 Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. matplotlib 散点图scatter

    最近开始学习python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...

  7. <select>里动态添加option

    因为是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接有时候会失效,所以 ...

  8. Eclipse git pull 报Nothing to fetch 异常原因

    eclipse git pull 报错 // 使用这个配置就可以正常pull了        [core]        symlinks = false         repositoryform ...

  9. scribe、chukwa、kafka、flume日志系统对比

    scribe.chukwa.kafka.flume日志系统对比   1. 背景介绍许多公司的平台每天会产生大量的日志(一般为流式数据,如,搜索引擎的pv,查询等),处理 这些日志需要特定的日志系统,一 ...

  10. 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask

    参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...