提交 ef2b2255 编写于 作者: R Ross Girshick

Merge remote-tracking branch 'flip/master'

import os
import PIL
class imdb(object):
def __init__(self, name):
......@@ -63,3 +64,22 @@ class imdb(object):
all_boxes[class][image] = [] or np.array of shape #dets x 5
"""
raise NotImplementedError
def append_flipped_roidb(self):
num_images = len(self.image_index)
widths = [PIL.Image.open(self.image_path_at(i)).size[0]
for i in xrange(num_images)]
for i in xrange(num_images):
self.roidb[i]['flipped'] = False
boxes = self.roidb[i]['boxes'].copy()
oldx1 = boxes[:, 0].copy()
oldx2 = boxes[:, 2].copy()
boxes[:, 0] = widths[i] - oldx2 - 1
boxes[:, 2] = widths[i] - oldx1 - 1
assert (boxes[:, 2] >= boxes[:, 0]).all()
entry = {'boxes' : boxes,
'gt_overlaps' : self.roidb[i]['gt_overlaps'],
'gt_classes' : self.roidb[i]['gt_classes'],
'flipped' : True}
self.roidb.append(entry)
self._image_index = self._image_index * 2
......@@ -58,7 +58,7 @@ class pascal_voc(datasets.imdb):
self._image_set + '.txt')
assert os.path.exists(image_set_file)
with open(image_set_file) as f:
image_index = tuple([x.strip() for x in f.readlines()])
image_index = [x.strip() for x in f.readlines()]
return image_index
def _get_default_path(self):
......
......@@ -156,6 +156,9 @@ if __name__ == '__main__':
imdb_train = datasets.pascal_voc('trainval', '2007')
# enhance roidb to contain flipped examples
imdb_train.append_flipped_roidb()
# enhance roidb to contain some useful derived quanties
roidb_train = training_roidb(imdb_train)
......
......@@ -129,6 +129,8 @@ def _get_image_blob(roidb, scale_inds):
im_scale_factors = []
for i in xrange(num_images):
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
im = im.astype(np.float32, copy=False)
im -= conf.PIXEL_MEANS
im_shape = im.shape
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册