def test_imdb_comp(net, imdb, anchors): # generate proposal result boxes res_boxes = test_net(net, imdb, anchors) num_image = len(imdb.image_index) max_per_image = 100 max_per_set = 40 * num_image thresh = -np.inf top_scores = [] # get boxes with high score for i in xrange(num_image): dets = res_boxes[i] dets = dets[:min(len(dets), max_per_image)] res_boxes[i] = dets for det in dets: heapq.heappush(top_scores, det[-1]) if len(top_scores) > max_per_set: while len(top_scores) > max_per_set: heapq.heappop(top_scores) thresh = top_scores[0] print 'filter boxes (top {:d}): {:d}/{:d}'.format( max_per_image, i, num_image) # conf thresh and nms for i in xrange(num_image): inds = np.where(res_boxes[i][:, -1] > thresh)[0] res_boxes[i] = res_boxes[i][inds, :] res_boxes[i] = boxes_filter(res_boxes[i], -1, cfg.TEST.NMS, -1) print 'filter boxes (conf thresh & nms): {:d}/{:d}'.format( i, num_image) return res_boxes
def test_imdb_comp(net, imdb, anchors): # generate proposal result boxes res_boxes = test_net(net, imdb, anchors) num_image = len(imdb.image_index) max_per_image = 100 max_per_set = 40 * num_image thresh = -np.inf top_scores = [] # get boxes with high score for i in xrange(num_image): dets = res_boxes[i] dets = dets[: min(len(dets), max_per_image)] res_boxes[i] = dets for det in dets: heapq.heappush(top_scores, det[-1]) if len(top_scores) > max_per_set: while len(top_scores) > max_per_set: heapq.heappop(top_scores) thresh = top_scores[0] print 'filter boxes (top {:d}): {:d}/{:d}'.format(max_per_image, i, num_image) # conf thresh and nms for i in xrange(num_image): inds = np.where(res_boxes[i][:, -1] > thresh)[0] res_boxes[i] = res_boxes[i][inds, :] res_boxes[i] = boxes_filter(res_boxes[i], -1, cfg.TEST.NMS, -1) print 'filter boxes (conf thresh & nms): {:d}/{:d}'.format(i, num_image) return res_boxes
def test_imdb(net, imdb, anchors): """ Test a region proposal network on a image dataset """ output_dir = get_output_dir(imdb, net) cache_file = os.path.join(output_dir, 'res_boxes.pkl') # load cache result boxes (filtered) if os.path.exists(cache_file): with open(cache_file, 'rb') as f: proposal_boxes = cPickle.load(f) print 'load res boxes from \'{}\''.format(cache_file) return proposal_boxes if not os.path.exists(output_dir): os.makedirs(output_dir) print 'Generating proposal boxes by rpn model...' proposal_boxes = test_net(net, imdb, anchors) print 'Get proposal boxes done!' print 'Current NMS configuration:' print NMS_CONFIG expand_val = lambda boxes: np.array([ boxes[:, 0] - boxes[:, 2], boxes[:, 1] - boxes[:, 3], boxes[:, 2] - boxes[:, 0], boxes[:, 3] - boxes[:, 1], np.zeros(boxes.shape[0]) ]).T * EXPAND_RATIO # filter boxes print 'Filtering proposal boxes...' for i in xrange(len(proposal_boxes)): proposal_boxes[i] = boxes_filter( proposal_boxes[i], PRE_NMS_TOPN=NMS_CONFIG['PRE_NMS_TOPN'], NMS_THRESH=NMS_CONFIG['NMS_THRESH'], POST_NMS_TOPN=NMS_CONFIG['POST_NMS_TOPN'], CONF_THRESH=CONF_THRESH, USE_GPU=NMS_CONFIG['USE_GPU']) # expand bounding box if len(proposal_boxes[i]) > 0: proposal_boxes[i] = proposal_boxes[i] + expand_val( proposal_boxes[i]) print 'filter proposal box: {:d}/{:d}'.format(i + 1, len(proposal_boxes)) print 'Filter proposal boxes done!' # save file with open(cache_file, 'wb') as f: cPickle.dump(proposal_boxes, f, cPickle.HIGHEST_PROTOCOL) print 'save result boxes to `{:s}`'.format(cache_file) return proposal_boxes
def test_imdb(net, imdb, anchors): """ Test a region proposal network on a image dataset """ output_dir = get_output_dir(imdb, net) cache_file = os.path.join(output_dir, 'res_boxes.pkl') # load cache result boxes (filtered) if os.path.exists(cache_file): with open(cache_file, 'rb') as f: proposal_boxes = cPickle.load(f) print 'load res boxes from \'{}\''.format(cache_file) return proposal_boxes if not os.path.exists(output_dir): os.makedirs(output_dir) print 'Generating proposal boxes by rpn model...' proposal_boxes = test_net(net, imdb, anchors) print 'Get proposal boxes done!' print 'Current NMS configuration:' print NMS_CONFIG expand_val = lambda boxes: np.array([boxes[:,0] - boxes[:,2], boxes[:,1] - boxes[:,3], boxes[:,2] - boxes[:,0], boxes[:,3] - boxes[:,1], np.zeros(boxes.shape[0])]).T * EXPAND_RATIO # filter boxes print 'Filtering proposal boxes...' for i in xrange(len(proposal_boxes)): proposal_boxes[i] = boxes_filter(proposal_boxes[i], PRE_NMS_TOPN=NMS_CONFIG['PRE_NMS_TOPN'], NMS_THRESH=NMS_CONFIG['NMS_THRESH'], POST_NMS_TOPN=NMS_CONFIG['POST_NMS_TOPN'], CONF_THRESH=CONF_THRESH, USE_GPU=NMS_CONFIG['USE_GPU']) # expand bounding box if len(proposal_boxes[i]) > 0: proposal_boxes[i] = proposal_boxes[i] + expand_val(proposal_boxes[i]) print 'filter proposal box: {:d}/{:d}'.format(i+1, len(proposal_boxes)) print 'Filter proposal boxes done!' # save file with open(cache_file, 'wb') as f: cPickle.dump(proposal_boxes, f, cPickle.HIGHEST_PROTOCOL) print 'save result boxes to `{:s}`'.format(cache_file) return proposal_boxes
def test_imdb(net, imdb, anchors): """ Test a region proposal network on a image dataset """ print 'Generating proposal boxes by rpn model...' proposal_boxes = test_net(net, imdb, anchors) print 'Get proposal boxes done!' print 'Current NMS configuration:' print NMS_CONFIG # filter boxes print 'Filtering proposal boxes...' for i in xrange(len(proposal_boxes)): proposal_boxes[i] = boxes_filter(proposal_boxes[i], PRE_NMS_TOPN=NMS_CONFIG['PRE_NMS_TOPN'], NMS_THRESH=NMS_CONFIG['NMS_THRESH'], POST_NMS_TOPN=NMS_CONFIG['POST_NMS_TOPN'], USE_GPU=NMS_CONFIG['USE_GPU']) print 'filter proposal box: {:d}/{:d}'.format(i, len(proposal_boxes)) print 'Filter proposal boxes done!' return proposal_boxes
def test_imdb(net, imdb, anchors): """ Test a region proposal network on a image dataset """ print 'Generating proposal boxes by rpn model...' proposal_boxes = test_net(net, imdb, anchors) print 'Get proposal boxes done!' print 'Current NMS configuration:' print NMS_CONFIG # filter boxes print 'Filtering proposal boxes...' for i in xrange(len(proposal_boxes)): proposal_boxes[i] = boxes_filter( proposal_boxes[i], PRE_NMS_TOPN=NMS_CONFIG['PRE_NMS_TOPN'], NMS_THRESH=NMS_CONFIG['NMS_THRESH'], POST_NMS_TOPN=NMS_CONFIG['POST_NMS_TOPN'], USE_GPU=NMS_CONFIG['USE_GPU']) print 'filter proposal box: {:d}/{:d}'.format(i, len(proposal_boxes)) print 'Filter proposal boxes done!' return proposal_boxes