From 8e494b4259fb0a03564a9ccdec91e767e14d9afa Mon Sep 17 00:00:00 2001 From: Huaqi Fang Date: Fri, 25 May 2018 04:13:22 +0200 Subject: [PATCH] Update for Pruning tool, include merged 2007 and 2012 VOC dataset support --- lib/datasets/factory.py | 2 +- lib/datasets/voc_eval.py | 6 ++++++ lib/fast_rcnn/config.py | 4 ++-- lib/fast_rcnn/train.py | 1 + lib/rpn/proposal_target_layer.py | 3 +++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/datasets/factory.py b/lib/datasets/factory.py index 8c3fdb898..614067e8e 100644 --- a/lib/datasets/factory.py +++ b/lib/datasets/factory.py @@ -14,7 +14,7 @@ import numpy as np # Set up voc__ using selective search "fast" mode -for year in ['2007', '2012']: +for year in ['2007', '2012', '0712']: for split in ['train', 'val', 'trainval', 'test']: name = 'voc_{}_{}'.format(year, split) __sets[name] = (lambda split=split, year=year: pascal_voc(split, year)) diff --git a/lib/datasets/voc_eval.py b/lib/datasets/voc_eval.py index 8d0a83076..7c40697b2 100644 --- a/lib/datasets/voc_eval.py +++ b/lib/datasets/voc_eval.py @@ -145,6 +145,12 @@ def voc_eval(detpath, # sort by confidence sorted_ind = np.argsort(-confidence) sorted_scores = np.sort(-confidence) + ###FIX added + if (len(sorted_ind)<1): + rec = 0 + prec = 0 + ap = 0 + return rec, prec, ap BB = BB[sorted_ind, :] image_ids = [image_ids[x] for x in sorted_ind] diff --git a/lib/fast_rcnn/config.py b/lib/fast_rcnn/config.py index 253017369..19d5596c2 100644 --- a/lib/fast_rcnn/config.py +++ b/lib/fast_rcnn/config.py @@ -41,7 +41,7 @@ __C.TRAIN.MAX_SIZE = 1000 # Images to use per minibatch -__C.TRAIN.IMS_PER_BATCH = 2 +__C.TRAIN.IMS_PER_BATCH = 1 # Minibatch size (number of regions of interest [ROIs]) __C.TRAIN.BATCH_SIZE = 128 @@ -97,7 +97,7 @@ __C.TRAIN.ASPECT_GROUPING = True # Use RPN to detect objects -__C.TRAIN.HAS_RPN = False +__C.TRAIN.HAS_RPN = True # IOU >= thresh: positive example __C.TRAIN.RPN_POSITIVE_OVERLAP = 0.7 # IOU < thresh: negative example diff --git a/lib/fast_rcnn/train.py b/lib/fast_rcnn/train.py index 05bd594ff..4a6d362ec 100644 --- a/lib/fast_rcnn/train.py +++ b/lib/fast_rcnn/train.py @@ -16,6 +16,7 @@ from caffe.proto import caffe_pb2 import google.protobuf as pb2 +import google.protobuf.text_format class SolverWrapper(object): """A simple wrapper around Caffe's solver. diff --git a/lib/rpn/proposal_target_layer.py b/lib/rpn/proposal_target_layer.py index 38e1f2c88..7e30d5516 100644 --- a/lib/rpn/proposal_target_layer.py +++ b/lib/rpn/proposal_target_layer.py @@ -124,6 +124,8 @@ def _get_bbox_regression_labels(bbox_target_data, num_classes): cls = clss[ind] start = 4 * cls end = start + 4 + start=int(start) + end=int(end) bbox_targets[ind, start:end] = bbox_target_data[ind, 1:] bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS return bbox_targets, bbox_inside_weights @@ -161,6 +163,7 @@ def _sample_rois(all_rois, gt_boxes, fg_rois_per_image, rois_per_image, num_clas # Guard against the case when an image has fewer than fg_rois_per_image # foreground RoIs fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size) + fg_rois_per_this_image=int(fg_rois_per_this_image) # Sample foreground regions without replacement if fg_inds.size > 0: fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)