实际上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. python-线程池的两种实现方式 【转载】

    #!/usr/bin/env python # -*- coding:utf-8 -*- import queue import threading import contextlib import ...

  2. UITextField的内存泄漏问题

    背景: 项目中使用了Facebook的FBRetainCycleDetector框架检测内存泄漏问题. 登录VC的view中放置了一个UITextField对象. 产品的要求是当进入登录界面的时候,让 ...

  3. celery参考

    1,https://www.wandouip.com/t5i377365/ 2,https://www.cnblogs.com/zhangmingcheng/p/6050270.html (syste ...

  4. turtle库常用命令

    一, 海龟动作: 移动和绘制 forward()| fd() 前进多少 backward()|bk()|back()后退 right()|rt() 右转多少度 left() 左转多少度 goto()| ...

  5. PostgreSQL日期加减

    在PostgreSQL中可以直接对时间进行加减运算:. SELECT now()::timestamp + '1 year';  --当前时间加1年 SELECT now()::timestamp + ...

  6. 安装ubuntu18.04.3全过程

    目录 一.安装ubuntu18.04.3操作系统 二.系统设置 三.非开发常用软件安装 四.开发常用软件安装 五.ubuntu相关知识 六.参考文章链接 正文 一.安装ubuntu18.04.3操作系 ...

  7. ASP.NET Core搭建多层网站架构【8.3-编写角色业务的增删改】

    2020/01/29, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[8.3-编写角色业务的增删改] 编写最简单的增删 ...

  8. 9. 图解分析Redis的RDB和AOF两种持久化机制的原理

    1.RDB和AOF两种持久化机制的介绍 2.RDB持久化机制的优点3.RDB持久化机制的缺点4.AOF持久化机制的优点5.AOF持久化机制的缺点6.RDB和AOF到底该如何选择 我们已经知道对于一个企 ...

  9. beyond compare 用法

    1.过滤器用法:点击小眼睛(回话-->回话设置)打开过滤器界面----设置多个过滤文件或目录直接使用回车键 2.比较时最好先设置编码以防出现乱码问题 工具-->文件格式. 3.比较时出现乱 ...

  10. pip配置永久国内源

    1.windows配置方式: (1)打开文件资源管理器 --------在地址栏中输入 %appdata% (2)手动创建一个文件夹叫做 pip (3)在pip的文件夹里面新建一个文件 pip.ini ...