pyramidbox_face_detection bigger input wrong bboxes coordinate
Created by: EthanZBY
!hub run pyramidbox_face_detection --input_path path_to_image
/home/aistudio/.paddlehub/modules/pyramidbox_face_detection/python/c0bea9f829808eae3a844e829d06a407.py
Bug 1st: When shrink is not equal to 1.0, then the coordinates of bboxes will be wrong fix: Should not should not be divided by shrink:
def postprocess(self, sign_name, data_out, data_info, **kwargs):
self.build_config(**kwargs)
self.visualization = True
if sign_name == "face_detection":
lod_tensor = data_out[0]
lod = lod_tensor.lod()[0]
results = np.array(data_out[0])
output = []
for index in range(len(lod) - 1):
result_i = results[lod[index]:lod[index + 1]]
shrink = data_info['image'][index]['shrink']
output_i = {
'path': data_info['image'][index]['path'],
'data': []
}
w = data_info['image'][index]['width']
h = data_info['image'][index]['height']
if np.prod(result_i.shape) <= 1:
print("No face detected in {}".format(data_info['image'][index]['path']))
else:
det_conf = result_i[:, 1]
det_xmin = w * result_i[:, 2] #/ shrink
det_ymin = h * result_i[:, 3] #/ shrink
det_xmax = w * result_i[:, 4] #/ shrink
det_ymax = h * result_i[:, 5] #/ shrink
dets = np.column_stack((det_xmin, det_ymin, det_xmax, det_ymax, det_conf))
keep_index = np.where(dets[:, 4] >= self.score_thresh)[0]
dets = dets[keep_index, :]
if dets.shape[0] != 0:
if self.visualization:
draw_bboxes(data_info['image'][index]['path'], dets[:, 0:4])
for dt in result_i:
dt_i = {}
if dt[1] < self.score_thresh:
continue
dt_i['left'] = float(dt[2])
dt_i['right'] = float(dt[4])
dt_i['top'] = float(dt[3])
dt_i['bottom'] = float(dt[5])
dt_i['confidence'] = float(dt[1])
output_i['data'].append(dt_i)
if len(output_i['data']) == 0:
print("No face detected in {}".format(data_info['image'][index]['path']))
output.append(output_i)
return output
Bug 2nd: Same as https://github.com/PaddlePaddle/models/issues/4082 fix: to add in get_shrink: elif max_shrink <= 0.1: max_shrink = 0.1