深度学习python之用Faster-rcnn 检测结果(detections.pkl 和class_pr.pkl) 在原图画出box

class_pr.pkl 包括召回率(Recall),精确率(Precision),平均正确率(Average_precision(AP) )
在Spyer中敲入如下代码即可打开,在变量栏查看具体数值(本文只对一类目标进行检测)

import cPickle as pickle  
f = open('ship_pr.pkl')  
info = pickle.load(f)  

下面是使用detections.pkl画框,里面包括的是list,list里包含两个list,坐标值在第二个list里

import os
import os.path
import numpy as np
import xml.etree.ElementTree as xmlET
from PIL import Image, ImageDraw
import cPickle as pickle 

f = open('ship_pr.pkl')  
ship_pr = pickle.load(f) 

test_file = 'test.txt'
file_path_img = 'JPEGImages'
save_file_path = 'pkl/results'

with open(test_file) as f:
    image_index = [x.strip() for x in f.readlines()]

f = open('detections.pkl')  
info = pickle.load(f)


dets = info[1]

num = 0
for idx in xrange(len(dets)):
    if len(dets[idx]) == 0:
        continue
    img = Image.open(os.path.join(file_path_img, image_index[idx] + '.jpg')) 
    draw = ImageDraw.Draw(img)
    for i in xrange(len(dets[idx])):
        box = dets[idx][i]
        draw.rectangle([int(np.round(float(box[0]))), int(np.round(float(box[1]))), 
                    int(np.round(float(box[2]))), int(np.round(float(box[3])))], outline=(255, 0, 0))
    img.save(os.path.join(save_file_path, image_index[idx] + '.jpg'))  

你可能感兴趣的:(深度学习)