未验证 提交 1353aa5d 编写于 作者: S shangliang Xu 提交者: GitHub

[TIPC] add kl quant txt (#6237)

上级 3d45bee1
......@@ -152,11 +152,17 @@ class Detector(object):
def postprocess(self, inputs, result):
# postprocess output of predictor
np_boxes_num = result['boxes_num']
if np_boxes_num[0] <= 0:
print('[WARNNING] No object detected.')
result = {'boxes': np.zeros([0, 6]), 'boxes_num': [0]}
result = {k: v for k, v in result.items() if v is not None}
return result
out_result = {k: [] for k, v in result.items() if v is not None}
idx = 0
for num_box in np_boxes_num:
for k, v in out_result.items():
v.append(result[k][idx:idx + num_box])
idx += num_box
if num_box == 0:
print('[WARNNING] No object detected.')
out_result = {k: np.concatenate(v) for k, v in out_result.items()}
out_result['boxes_num'] = result['boxes_num']
return out_result
def filter_box(self, result, threshold):
np_boxes_num = result['boxes_num']
......@@ -307,7 +313,7 @@ class Detector(object):
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
out_path = os.path.join(self.output_dir, video_out_name)
fourcc = cv2.VideoWriter_fourcc(* 'mp4v')
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
writer = cv2.VideoWriter(out_path, fourcc, fps, (width, height))
index = 1
while (1):
......
......@@ -687,7 +687,10 @@ class Trainer(object):
name, ext = os.path.splitext(image_name)
return os.path.join(output_dir, "{}".format(name)) + ext
def _get_infer_cfg_and_input_spec(self, save_dir, prune_input=True):
def _get_infer_cfg_and_input_spec(self,
save_dir,
prune_input=True,
kl_quant=False):
image_shape = None
im_shape = [None, 2]
scale_factor = [None, 2]
......@@ -768,6 +771,19 @@ class Trainer(object):
"image": InputSpec(
shape=image_shape, name='image')
}]
if kl_quant:
if self.cfg.architecture == 'PicoDet' or 'ppyoloe' in self.cfg.weights:
pruned_input_spec = [{
"image": InputSpec(
shape=image_shape, name='image'),
"scale_factor": InputSpec(
shape=scale_factor, name='scale_factor')
}]
elif 'tinypose' in self.cfg.weights:
pruned_input_spec = [{
"image": InputSpec(
shape=image_shape, name='image')
}]
return static_model, pruned_input_spec
......@@ -811,8 +827,9 @@ class Trainer(object):
break
# TODO: support prune input_spec
kl_quant = True if hasattr(self.cfg.slim, 'ptq') else False
_, pruned_input_spec = self._get_infer_cfg_and_input_spec(
save_dir, prune_input=False)
save_dir, prune_input=False, kl_quant=kl_quant)
self.cfg.slim.save_quantized_model(
self.model,
......
......@@ -115,8 +115,7 @@ class YOLOv3(BaseArch):
self.inputs['im_shape'], self.inputs['scale_factor'])
else:
bbox, bbox_num = self.yolo_head.post_process(
yolo_head_outs, self.inputs['im_shape'],
self.inputs['scale_factor'])
yolo_head_outs, self.inputs['scale_factor'])
output = {'bbox': bbox, 'bbox_num': bbox_num}
return output
......
......@@ -366,7 +366,7 @@ class PPYOLOEHead(nn.Layer):
}
return out_dict
def post_process(self, head_outs, img_shape, scale_factor):
def post_process(self, head_outs, scale_factor):
pred_scores, pred_dist, anchor_points, stride_tensor = head_outs
pred_bboxes = batch_distance2bbox(anchor_points,
pred_dist.transpose([0, 2, 1]))
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c test_tipc/configs/keypoint/tinypose_128x96.
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c test_tipc/configs/keypoint/tinypose_128x96.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c test_tipc/configs/keypoint/tinypose_128x96.yml --slim_config configs/slim/post_quant/tinypose_128x96_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/keypoint_infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco
distill_export:null
export1:null
export_onnx:null
kl_quant_export:tools/post_quant.py -c configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/picodet_l_640_
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_l_640_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_l_640_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/more_config/pi
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_lcnet_1_5x_416_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_lcnet_1_5x_416_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/picodet_m_416_
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_m_416_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_m_416_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/more_config/pi
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_mobilenetv3_large_1x_416_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_mobilenetv3_large_1x_416_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/more_config/pi
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_r18_640_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_r18_640_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/picodet_s_320_
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_s_320_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/picodet_s_320_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/picodet/legacy_model/more_config/pi
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_shufflenetv2_1x_416_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/picodet/legacy_model/more_config/picodet_shufflenetv2_1x_416_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -35,8 +35,8 @@ export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_mbv3_large_coco.yml --slim_config configs/slim/post_quant/ppyolo_mbv3_large_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolo_mbv3_small_coco.yml -
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_mbv3_small_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_mbv3_small_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolo_r18vd_coco.yml --slim
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_r18vd_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_r18vd_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -35,8 +35,8 @@ export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/post_quant/ppyolo_r50vd_dcn_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolo_tiny_650e_coco.yml --
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_tiny_650e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolo_tiny_650e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolov2_r101vd_dcn_365e_coc
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolov2_r101vd_dcn_365e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolov2_r101vd_dcn_365e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -33,10 +33,10 @@ fpgm_export:tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml
distill_export:null
export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml --slim_config _template_kl_quant -o
kl_quant_export:tools/post_quant.py -c configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -35,8 +35,8 @@ export1:null
export2:null
kl_quant_export:tools/post_quant.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --slim_config configs/slim/post_quant/yolov3_darknet53_ptq.yml -o
##
infer_mode:norm
infer_quant:False
infer_mode:norm|kl_quant
infer_quant:False|True
inference:./deploy/python/infer.py
--device:gpu|cpu
--enable_mkldnn:False
......
......@@ -81,6 +81,10 @@ elif [ ${MODE} = "paddle2onnx_infer" ];then
${python} -m pip install onnx onnxruntime
elif [ ${MODE} = "serving_infer" ];then
unset https_proxy http_proxy
# download coco lite data
wget -nc -P ./dataset/coco/ https://paddledet.bj.bcebos.com/data/tipc/coco_tipc.tar --no-check-certificate
cd ./dataset/coco/ && tar -xvf coco_tipc.tar && mv -n coco_tipc/* .
rm -rf coco_tipc/ && cd ../../
else
# download coco lite data
wget -nc -P ./dataset/coco/ https://paddledet.bj.bcebos.com/data/tipc/coco_tipc.tar --no-check-certificate
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册