PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.57k stars 2.86k forks source link

[BUG]量化训练后动转静导出模型无法正确推理 #4205

Closed CharlesYXW closed 2 years ago

CharlesYXW commented 2 years ago

您好, 我在对模型进行量化训练后,使用命令:

python tools/infer.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/quant/ppyolo_r50vd_qat_pact.yml -o weights=output/ppyolo_r50vd_qat_pact/best_model.pdparams --infer_dir=demo/testdata/1

能够正确进行预测推理。

然而进行动转静导出:

python tools/export_model.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml --slim_config configs/slim/quant/ppyolo_r50vd_qat_pact.yml -o weights=output/ppyolo_r50vd_qat_pact/best_model.pdparams

之后 使用命令 python deploy/python/infer.py --model_dir=output_inference/ppyolo_r50vd_qat_pact --image_dir=demo/testdata/1

却无法对图片进行预测,也没有报错,输出的图像中没有预测的标签和边框。

-----------  Running Arguments -----------
batch_size: 1
camera_id: -1
cpu_threads: 1
device: gpu
enable_mkldnn: False
image_dir: demo/testdata/1
image_file: None
model_dir: output_inference/ppyolo_r50vd_qat_pact
output_dir: output
reid_batch_size: 50
reid_model_dir: None
run_benchmark: False
run_mode: fluid
save_images: False
save_mot_txts: False
threshold: 0.5
trt_calib_mode: False
trt_max_shape: 1280
trt_min_shape: 1
trt_opt_shape: 640
use_dark: True
use_gpu: False
video_file: None
------------------------------------------
-----------  Model Configuration -----------
Model Arch: YOLO
Transform Order:
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
Found 10 inference images in total.
save result to: output/b5.jpg
save result to: output/b2.jpg
save result to: output/b3.jpg
save result to: output/b9.jpg
save result to: output/b8.jpg
save result to: output/b6.jpg
save result to: output/b4.jpg
[WARNNING] No object detected.
save result to: output/b7.jpg
save result to: output/b1.jpg
save result to: output/b0.jpg
------------------ Inference Time Info ----------------------
total_time(ms): 1849.3999999999999, img_num: 10
average latency time(ms): 184.94, QPS: 5.407159
preprocess_time(ms): 27.70, inference_time(ms): 157.20, postprocess_time(ms): 0.00

使用命令:python deploy/python/infer.py --model_dir=output_inference/ppyolo_r50vd_qat_pact --video_file=demo/1.mp4 对视频进行测试时,报如下错误

-----------  Model Configuration -----------
Model Arch: YOLO
Transform Order:
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
frame_count 1786
detect frame:1
detect frame:2
detect frame:3
detect frame:4
detect frame:5
detect frame:6
detect frame:7
detect frame:8
detect frame:9
[WARNNING] No object detected.
Traceback (most recent call last):
  File "deploy/python/infer.py", line 669, in <module>
    main()
  File "deploy/python/infer.py", line 626, in main
    predict_video(detector, FLAGS.camera_id)
  File "deploy/python/infer.py", line 582, in predict_video
    im = visualize_box_mask(
  File "/root/Downloads/paddle-detection1/deploy/python/visualize.py", line 46, in visualize_box_mask
    im = draw_box(im, results['boxes'], labels, threshold=threshold)
  File "/root/Downloads/paddle-detection1/deploy/python/visualize.py", line 129, in draw_box
    expect_boxes = (np_boxes[:, 1] > threshold) & (np_boxes[:, 0] > -1)
IndexError: index 1 is out of bounds for axis 1 with size 0
qingqing01 commented 2 years ago

GPU上量化推理,需要设置run_mode为trt_int8 ,参考文档: https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.2/deploy/python/README.md#2-%E5%9F%BA%E4%BA%8Epython%E7%9A%84%E9%A2%84%E6%B5%8B

CharlesYXW commented 2 years ago

使用命令:python deploy/python/infer.py --model_dir=output_inference/ppyolo_r50vd_qat_pact --device='GPU' --video_file=demo/1.mp4 --run_mode=trt_int8

进行对量化模型推理时依然报错:

-----------  Running Arguments -----------
batch_size: 1
camera_id: -1
cpu_threads: 1
device: GPU
enable_mkldnn: False
image_dir: None
image_file: None
model_dir: output_inference/ppyolo_r50vd_qat_pact
output_dir: output
reid_batch_size: 50
reid_model_dir: None
run_benchmark: False
run_mode: trt_int8
save_images: False
save_mot_txts: False
threshold: 0.5
trt_calib_mode: False
trt_max_shape: 1280
trt_min_shape: 1
trt_opt_shape: 640
use_dark: True
use_gpu: False
video_file: demo/1.mp4
------------------------------------------
-----------  Model Configuration -----------
Model Arch: YOLO
Transform Order: 
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
Traceback (most recent call last):
  File "deploy/python/infer.py", line 667, in <module>
    main()
  File "deploy/python/infer.py", line 596, in main
    detector = Detector(
  File "deploy/python/infer.py", line 78, in __init__
    self.predictor, self.config = load_predictor(
  File "deploy/python/infer.py", line 454, in load_predictor
    predictor = create_predictor(config)
ValueError: (InvalidArgument) Pass tensorrt_subgraph_pass has not been registered. Please use the paddle inference library compiled with tensorrt or disable the tensorrt engine in inference configuration! 
  [Hint: Expected Has(pass_type) == true, but received Has(pass_type):0 != true:1.] (at /paddle/paddle/fluid/framework/ir/pass.h:216)

看样子是说没用能编译TensorRT的推理库,我的Paddle版本2.1.3,cuda 11.0 ,TensorRT 7.2.3 ,在https://paddleinference.paddlepaddle.org.cn/user_guides/download_lib.html 中并没有找到cuda11.0能用的,请问如何解决

qingqing01 commented 2 years ago

参考安装页面下面 tensorrt联编 提示:

https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html

图片
paddle-bot-old[bot] commented 2 years ago

Since this issue has not been updated for more than three months, it will be closed, if it is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. It is recommended to pull and try the latest code first. 由于该问题超过三个月未更新,将会被关闭,若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。

aileenfun commented 2 years ago

你好,我也遇到了同样的问题。 平台是Win 10,rtx2060 现在我还没有做tensorRT联编,先尝试使用CPU进行推理,但是结果相同,没有报错,但是同样检测不到任何东西。

请问如果想用CPU进行部署的话,需要怎么调参数?

python tools/export_model.py -c configs/yolov3/yolov3_bamboo2.yml --output_dir=./inference_model -o weights=output/yolov3_bamboo2/best_model.pdparams

python deploy/python/infer.py --device=CPU --model_dir=./inference_model/yolov3_bamboo2 --image_file=./dataset/bamboo/testimg/1.jpg

Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed
in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
  'nearest': Image.NEAREST,
Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed
 in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
  'bilinear': Image.BILINEAR,
Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed
in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
  'bicubic': Image.BICUBIC,
Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in P
illow 10 (2023-07-01). Use Resampling.BOX instead.
  'box': Image.BOX,
Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed
in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
  'lanczos': Image.LANCZOS,
Q:\paddletest\venv\lib\site-packages\paddle\vision\transforms\functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed
in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
  'hamming': Image.HAMMING
-----------  Running Arguments -----------
action_file: None
batch_size: 1
camera_id: -1
cpu_threads: 1
device: CPU
enable_mkldnn: False
enable_mkldnn_bfloat16: False
image_dir: None
image_file: ./dataset/bamboo/testimg/1.jpg
model_dir: ./inference_model/yolov3_bamboo2
output_dir: output
random_pad: False
reid_batch_size: 50
reid_model_dir: None
run_benchmark: False
run_mode: paddle
save_images: False
save_mot_txt_per_img: False
save_mot_txts: False
scaled: False
threshold: 0.5
tracker_config: None
trt_calib_mode: False
trt_max_shape: 1280
trt_min_shape: 1
trt_opt_shape: 640
use_dark: True
use_gpu: False
video_file: None
window_size: 50
------------------------------------------
-----------  Model Configuration -----------
Model Arch: YOLO
Transform Order:
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
[WARNNING] No object detected.
save result to: output\1.jpg
Test iter 0
------------------ Inference Time Info ----------------------
total_time(ms): 1339.2, img_num: 1
average latency time(ms): 1339.20, QPS: 0.746714
preprocess_time(ms): 120.50, inference_time(ms): 1218.70, postprocess_time(ms): 0.00