1. Usage
- Create checkProposals.ipynb in py-faster-rcnn/tools/
- Paste three code cells into ipynb.
- Run each cell and see the output.
- You may need to change rpn_file and insulator_2016_train to your own.
2. Code
1.load roidb
import _init_paths
from fast_rcnn.train import get_training_roidb
from datasets.factory import get_imdb
import numpy as np
def get_roidb(imdb_name, rpn_file=None):
imdb = get_imdb(imdb_name)
imdb.set_proposal_method('rpn')
if rpn_file is not None:
imdb.config['rpn_file'] = rpn_file
roidb = get_training_roidb(imdb)
return roidb, imdb
rpn_file = '/home/cv/project/py-faster-rcnn/output/faster_rcnn_alt_opt/insulator_2016_train/zf_rpn_stage1_iter_80000_proposals.pkl'
roidb, imdb = get_roidb('insulator_2016_train', rpn_file)
2.print roidb information
print roidb[0]['width'], roidb[0]['height']
print 'gt_classes', roidb[0]['gt_classes']
print 'boxes',roidb[0]['boxes'].shape
print len([i for i in roidb[0]['max_classes'].tolist() if i == 1])
3.plot proposals
from matplotlib.pyplot import imshow
%matplotlib inline
from PIL import Image
from PIL import ImageDraw
index = 0
img = Image.open(roidb[index]['image'])
draw = ImageDraw.Draw(img)
for i in range(0,50):
draw.rectangle(roidb[index]['boxes'][i,0:4].tolist(), outline=(255,0,0))
imshow(np.asarray(img))