def predict(self,image):
im = Image.open(image)
im = im.resize((self.IMAGE_WIDTH,self.IMAGE_HEIGHT))
imgMat = np.array(im)
res = self.sess.run(self.fc_19, feed_dict = {self.x : [imgMat]})
res = np.reshape(res,[7,7,30])
boxes = []
print "i,j,c,p,confidence,x,y,w,h'"
for i in range(7):
for j in range(7):
c = np.argmax(res[i][j][:20])
if(res[i][j][c] > 0.5):
score_th = 0.5
responsible_box = 0
if res[i][j][28] < res[i][j][29]:
responsible_box = 1
if res[i][j][28 + responsible_box] > score_th:
w = res[i][j][22 + 4 * responsible_box]
h = res[i][j][23 + 4 * responsible_box]
size_threshold = 0.05
if w > size_threshold and h > size_threshold:
boxes.append([i,j,c,res[i][j][c],res[i][j][28+responsible_box],
res[i][j][20 + 4 * responsible_box],res[i][j][21 + 4 * responsible_box],
res[i][j][22 + 4 * responsible_box],res[i][j][23 + 4 * responsible_box]])
print boxes
draw = ImageDraw.Draw(im)
for box in boxes :
w = box[7] * self.IMAGE_WIDTH / 2
h = box[8] * self.IMAGE_HEIGHT / 2
print 'w = ', w, ' h = ', h
lx = (box[0] + box[5]) * self.GRID_SIZE - w
ly = (box[1] + box[6]) * self.GRID_SIZE - h
tx = (box[0] + box[5]) * self.GRID_SIZE + w
ty = (box[1] + box[6]) * self.GRID_SIZE + h
print(lx,ly,tx,ty)
draw.rectangle((lx,ly,tx,ty))
content = self.classes[box[2]] + ' p = ' + str(box[3])
draw.text((lx, ly), content, fill=(255, 255, 255))
im.show()
评论列表
文章目录