def rpn_compute_stats(queue=None, imdb_name=None, cfg=None, rpn_test_prototxt=None): """Compute mean stds for anchors """ cfg.TRAIN.HAS_RPN = True cfg.TRAIN.BBOX_REG = False # applies only to R-FCN bbox regression cfg.TRAIN.PROPOSAL_METHOD = 'gt' cfg.TRAIN.IMS_PER_BATCH = 1 import caffe _init_caffe(cfg) # NOTE: the matlab implementation computes proposals on flipped images, too. # We compute them on the image once and then flip the already computed # proposals. This might cause a minor loss in mAP (less proposal jittering). roidb, imdb = get_roidb(imdb_name) print 'Loaded dataset `{:s}` for proposal generation'.format(imdb.name) mean_file = os.path.join(imdb.cache_path, imdb.name + '_means.npy') std_file = os.path.join(imdb.cache_path, imdb.name + '_stds.npy') if os.path.exists(mean_file) and os.path.exists(std_file): means = np.load(mean_file) stds = np.load(std_file) else: # Load RPN and configure output directory rpn_net = caffe.Net(rpn_test_prototxt, caffe.TEST) # Generate proposals on the imdb print 'start computing means/stds, it may take several minutes...' if imdb_name.startswith('coco'): means, stds = imdb_rpn_compute_stats(rpn_net, imdb, anchor_scales=(4, 8, 16, 32)) else: means, stds = imdb_rpn_compute_stats(rpn_net, imdb, anchor_scales=(8, 16, 32)) np.save(mean_file, means) np.save(std_file, stds) queue.put({'means': means, 'stds': stds})