未验证 提交 e2b98dc5 编写于 作者: Q qingqing01 提交者: GitHub

Add clipping before visulization in detection model. (#1415)

* Fix label lists for inference.
* Add clipping before visulization.
上级 e277fed6
...@@ -43,7 +43,7 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog ...@@ -43,7 +43,7 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog
The training is fine-tuned on the well-trained MobileNet-SSD model. So download model at first: The training is fine-tuned on the well-trained MobileNet-SSD model. So download model at first:
```bash ```
wget http://paddlemodels.bj.bcebos.com/ssd_mobilenet_v1_pascalvoc.tar.gz wget http://paddlemodels.bj.bcebos.com/ssd_mobilenet_v1_pascalvoc.tar.gz
``` ```
...@@ -111,7 +111,7 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog ...@@ -111,7 +111,7 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog
Users can evaluate the converted model by: Users can evaluate the converted model by:
```bash ```
python main_quant.py \ python main_quant.py \
--data_dir=$PascalVOC_DIR$ \ --data_dir=$PascalVOC_DIR$ \
--mode='test' \ --mode='test' \
...@@ -121,10 +121,11 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog ...@@ -121,10 +121,11 @@ A Python transpiler is used to rewrite Fluid training program or evaluation prog
You also can check the 8-bit model by the inference scripts You also can check the 8-bit model by the inference scripts
```bash ```
python main_quant.py \ python main_quant.py \
--mode='infer' \ --mode='infer' \
--init_model=$MobileNet_SSD_8BIT_MODEL$ \ --init_model=$MobileNet_SSD_8BIT_MODEL$ \
--confs_threshold=0.5 \
--image_path='/data/PascalVOC/VOCdevkit/VOC2007/JPEGImages/002271.jpg' --image_path='/data/PascalVOC/VOCdevkit/VOC2007/JPEGImages/002271.jpg'
``` ```
See 002271.jpg for the visualized image with bbouding boxes. See 002271.jpg for the visualized image with bbouding boxes.
......
...@@ -85,11 +85,11 @@ def draw_bounding_box_on_image(image_path, nms_out, confs_threshold, ...@@ -85,11 +85,11 @@ def draw_bounding_box_on_image(image_path, nms_out, confs_threshold,
im_width, im_height = image.size im_width, im_height = image.size
for dt in nms_out: for dt in nms_out:
category_id, score, xmin, ymin, xmax, ymax = dt.tolist() if dt[1] < confs_threshold:
if score < confs_threshold:
continue continue
category_id = dt[0]
bbox = dt[2:] bbox = dt[2:]
xmin, ymin, xmax, ymax = bbox xmin, ymin, xmax, ymax = clip_bbox(dt[2:])
(left, right, top, bottom) = (xmin * im_width, xmax * im_width, (left, right, top, bottom) = (xmin * im_width, xmax * im_width,
ymin * im_height, ymax * im_height) ymin * im_height, ymax * im_height)
draw.line( draw.line(
...@@ -104,6 +104,14 @@ def draw_bounding_box_on_image(image_path, nms_out, confs_threshold, ...@@ -104,6 +104,14 @@ def draw_bounding_box_on_image(image_path, nms_out, confs_threshold,
image.save(image_name) image.save(image_name)
def clip_bbox(bbox):
xmin = max(min(bbox[0], 1.), 0.)
ymin = max(min(bbox[1], 1.), 0.)
xmax = max(min(bbox[2], 1.), 0.)
ymax = max(min(bbox[3], 1.), 0.)
return xmin, ymin, xmax, ymax
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
......
...@@ -227,8 +227,8 @@ def infer(args, data_args): ...@@ -227,8 +227,8 @@ def infer(args, data_args):
executor=exe, executor=exe,
model_filename='__model__') model_filename='__model__')
print(np.array(fluid.global_scope().find_var('conv2d_20.w_0').get_tensor())) #print(np.array(fluid.global_scope().find_var('conv2d_20.w_0').get_tensor()))
print(np.max(np.array(fluid.global_scope().find_var('conv2d_20.w_0').get_tensor()))) #print(np.max(np.array(fluid.global_scope().find_var('conv2d_20.w_0').get_tensor())))
infer_reader = reader.infer(data_args, image_path) infer_reader = reader.infer(data_args, image_path)
data = infer_reader() data = infer_reader()
data = data.reshape((1,) + data.shape) data = data.reshape((1,) + data.shape)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册