实际上faster-rcnn对于输入的图片是有resize操作的,在resize的图片基础上提取feature map,而后generate一定数量的RoI。

我想首先去掉这个resize的操作,对每张图都是在原始图片基础上进行识别,所以要找到它到底在哪里resize了图片。

直接搜 grep 'resize' ./lib/ -r

./lib/crnn/utils.py: v.data.resize_(data.size()).copy_(data)
./lib/model/config.py:# Option to set if max-pooling is appended after crop_and_resize.
./lib/model/config.py:# if true, the region will be resized to a square of 2xPOOLING_SIZE,
./lib/model/config.py:# resized to a square of POOLING_SIZE
./lib/model/test.py: im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale,
./lib/nets/network.py:from scipy.misc import imresize
./lib/nets/network.py: image = imresize(image[0], self._im_info[:2] / self._im_info[2])
./lib/utils/blob.py: im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale,

这里在training过程中应当是调用了./lib/utils/blob.py,

该文件包含了两个函数:

 def im_list_to_blob(ims):
"""Convert a list of images into a network input.
Assumes images are already prepared (means subtracted, BGR order, ...).
"""
max_shape = np.array([im.shape for im in ims]).max(axis=0)
num_images = len(ims)
blob = np.zeros((num_images, max_shape[0], max_shape[1], 3),
dtype=np.float32)
for i in range(num_images):
im = ims[i]
blob[i, 0:im.shape[0], 0:im.shape[1], :] = im return blob def prep_im_for_blob(im, pixel_means, target_size, max_size):
"""Mean subtract and scale an image for use in a blob."""
im = im.astype(np.float32, copy=False)
im -= pixel_means
im_shape = im.shape
im_size_min = np.min(im_shape[0:2])
im_size_max = np.max(im_shape[0:2])
im_scale = float(target_size) / float(im_size_min)
# Prevent the biggest axis from being more than MAX_SIZE
if np.round(im_scale * im_size_max) > max_size:
im_scale = float(max_size) / float(im_size_max)
im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale,
interpolation=cv2.INTER_LINEAR) return im, im_scale

而这两个函数都是在./lib/roi_data_layer/minibatch.py 下被调用的。

而该文件也定义了两个函数,其中get_minibatch() 调用了另一个子函数_get_image_blob()。

 def get_minibatch(roidb, num_classes):
"""Given a roidb, construct a minibatch sampled from it."""
num_images = len(roidb)
# Sample random scales to use for each image in this batch
random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES),
size=num_images)
assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), \
'num_images ({}) must divide BATCH_SIZE ({})'. \
format(num_images, cfg.TRAIN.BATCH_SIZE) # Get the input image blob, formatted for caffe
im_blob, im_scales = _get_image_blob(roidb, random_scale_inds) blobs = {'data': im_blob} assert len(im_scales) == 1, "Single batch only"
assert len(roidb) == 1, "Single batch only" # gt boxes: (x1, y1, x2, y2, cls)
if cfg.TRAIN.USE_ALL_GT:
# Include all ground truth boxes
gt_inds = np.where(roidb[0]['gt_classes'] != 0)[0]
else:
# For the COCO ground truth boxes, exclude the ones that are ''iscrowd''
gt_inds = np.where(roidb[0]['gt_classes'] != 0 & np.all(roidb[0]['gt_overlaps'].toarray() > -1.0, axis=1))[0]
gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)
gt_boxes[:, 0:4] = roidb[0]['boxes'][gt_inds, :] * im_scales[0]
gt_boxes[:, 4] = roidb[0]['gt_classes'][gt_inds]
blobs['gt_boxes'] = gt_boxes
blobs['im_info'] = np.array(
[im_blob.shape[1], im_blob.shape[2], im_scales[0]],
dtype=np.float32) return blobs def _get_image_blob(roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in range(num_images):
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im) # Create a blob to hold the input images
blob = im_list_to_blob(processed_ims) return blob, im_scales

get_minibatch()又是被./lib/roi_data_layer/layer.py中的类RoIDataLayer的一个方法forward()中调用的另一个方法_get_next_minibatch()调用的。

至此,由于RoIDataLayer类在类Network中被调用,终于把这些都接起来了。

faster-RCNN的代码实在是冗杂,来来回回定义了很多完全可以用一个函数实现的很多很多个函数。我佛了!

Faster-RCNN Pytorch实现的minibatch包装的更多相关文章

  1. 记pytorch版faster rcnn配置运行中的一些坑

    记pytorch版faster rcnn配置运行中的一些坑 项目地址 https://github.com/jwyang/faster-rcnn.pytorch 一般安装配置参考README.md文件 ...

  2. 读论文系列:Object Detection NIPS2015 Faster RCNN

    转载请注明作者:梦里茶 Faster RCNN在Fast RCNN上更进一步,将Region Proposal也用神经网络来做,如果说Fast RCNN的最大贡献是ROI pooling layer和 ...

  3. Faster RCNN 学习笔记

    下面的介绍都是基于VGG16 的Faster RCNN网络,各网络的差异在于Conv layers层提取特征时有细微差异,至于后续的RPN层.Pooling层及全连接的分类和目标定位基本相同. 一). ...

  4. faster rcnn讲解很细

    https://blog.csdn.net/bailufeiyan/article/details/50749694 https://www.cnblogs.com/dudumiaomiao/p/65 ...

  5. (原)faster rcnn的tensorflow代码的理解

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/10043864.html 参考网址: 论文:https://arxiv.org/abs/1506.01 ...

  6. 目标检测(四)Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks

    作者:Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun SPPnet.Fast R-CNN等目标检测算法已经大幅降低了目标检测网络的运行时间. ...

  7. Faster R-CNN代码例子

    主要参考文章:1,从编程实现角度学习Faster R-CNN(附极简实现) 经常是做到一半发现收敛情况不理想,然后又回去看看这篇文章的细节. 另外两篇: 2,Faster R-CNN学习总结      ...

  8. 深度学习论文翻译解析(四):Faster R-CNN: Down the rabbit hole of modern object detection

    论文标题:Faster R-CNN: Down the rabbit hole of modern object detection 论文作者:Zhi Tian , Weilin Huang, Ton ...

  9. Faster RCNN代码理解(Python)

    转自http://www.infocool.net/kb/Python/201611/209696.html#原文地址 第一步,准备 从train_faster_rcnn_alt_opt.py入: 初 ...

随机推荐

  1. linux下安装keepalived

    keepalived安装文档 1. 安装环境 su - root yum -y install kernel-devel* yum -y install openssl-* yum -y instal ...

  2. 最小树形图模板 UVA11183

    题意:给定n个节点m条边的有向带权图,求以0为根节点的最小树形图权值大小 用这个代码的时候要注意,这里的数据是从0开始的,边也是从0开始算, 所以在打主代码的时候,如果是从1开始,那么算法里面的从0开 ...

  3. PHP基础学习笔记5

    一.连接MYSQL 1.1 MySQLi - 面向对象 <?php $servername = "localhost"; $username = "username ...

  4. WinForm程序打包教程

    准备工作 1. 编写完成的WinForm程序 2. 安装部署项 VS2010中有一个自带的安装部署项目,叫:Visual Studio Installer ,通常称为:setup项目,是一个用于自定义 ...

  5. [Linux kali] Kali KDE桌面安装中文输入法 不能登录系统

    #开始 第一次实体机上面安装kali的KDE桌面版本 结果就遇到了很多的BUG 比如这次就是安装中文输入法有问题 这次安装的是fcitx框架的 尝试了 谷歌输入法 还有搜狗输入法 都有这个问题 也就是 ...

  6. Groovy脚本-通用SQL开关

    备注:使用Groovy语言进行编写,看不懂的同学请先了解Groovy脚本. Groovy学习地址:https://www.cnblogs.com/tiechui2015/p/10828457.html ...

  7. Android学习08

    PopupWindow PopupWindow用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activity之上的. 1.弹出框的布局:画一个PopupWindow的 ...

  8. 五、request模块

    描述:requests是python的一个第三方HTTP(Hypertext Transfer Protocol,超文本传输协议)库,它比python自带的网络库urllib更加简单.方便和人性化:使 ...

  9. iOS 开发之使用链式编程思想实现简单的计算器

    链式编程思想是将多个操作(多行代码)通过点号(.)链接在一起成为一句代码,使代码可读性好.例如 a(1).b(2).c(3). 链式编程思想最为关键的是,方法的返回值是block,block必须返回对 ...

  10. wsgiref模块

    学习django框架之前,可以先学习一下wsgiref模块,熟悉前后端交互. 一.先介绍下wsgiref模块 WSGI(Web Server Gateway Interface)是一种规范,它定义了使 ...