PaddleSlim icon indicating copy to clipboard operation
PaddleSlim copied to clipboard

修改过的yolov5s模型如何使用paddleslim

Open stdio159 opened this issue 1 year ago • 4 comments

请问修改过的yolov5s模型导出了onnx模型之后如何使用paddleslim,我这边会报错,自动化压缩工具ACT(Auto Compression Toolkit) Fail to generate inference model! Problem happend while export inference model from python code 'D:\pro\PaddleSlim-develop\best_infer\onnx2paddle_0\x2paddle_code.py';

===================Error Information=============== 2023-04-02 21:17:13,787-WARNING: In transformed code:

File "D:\pro\PaddleSlim-develop\./best_infer\onnx2paddle_0\x2paddle_code.py", line 677, in forward
    x2paddle__model_2_cv1_act_Sigmoid_output_0 = self.sigmoid2(x2paddle__model_2_cv1_conv_Conv_output_0)
    x2paddle__model_2_cv2_act_Sigmoid_output_0 = self.sigmoid3(x2paddle__model_2_cv2_conv_Conv_output_0)
    x2paddle__model_21_m_blocks_blocks_1_Concat_output_0 = paddle.reshape(x=x2paddle__model_21_m_blocks_blocks_1_Concat_output_0, shape=[-1, 36, 36, -1, 4])
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    x2paddle__model_21_m_blocks_blocks_1_Constant_2_output_0_zeros = paddle.zeros_like(x=x2paddle__model_21_m_blocks_blocks_1_Constant_2_output_0)
    x2paddle__model_21_m_blocks_blocks_1_ScatterND_output_0_input_inner_indices = paddle.scatter_nd_add(x=x2paddle__model_21_m_blocks_blocks_1_Constant_2_output_0_zeros, index=x2paddle__model_21_m_blocks_blocks_1_Concat_output_0, updates=x2paddle__model_21_m_blocks_blocks_1_Reshape_1_output_0)

File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\site-packages\paddle\tensor\manipulation.py", line 3645, in reshape
    attrs["shape"] = get_attr_shape(shape)
File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\site-packages\paddle\tensor\manipulation.py", line 3607, in get_attr_shape
    assert unk_dim_idx == -1, (

AssertionError: Only one dimension value of 'shape' in reshape can be -1. But received shape[3] is also -1.

    # N = x.shape()[2]              # N is an int. (NOT recommend under @to_static)
    N = paddle.shape(x)[2]          # N is a Tensor. (Recommend)
    z = paddle.reshape([N, -1, 4])  # z.shape is [-1, -1, 4]

If your target shape in Reshape represents dynamic shape, please turn it into a Tensor under @to_static. See above example for details.

2023-04-02 21:17:13,790-ERROR: x2paddle threw an exception, you can ask for help at: https://github.com/PaddlePaddle/X2Paddle/issues

stdio159 avatar Apr 02 '23 13:04 stdio159

Evaluation stage, Run batch:|████████████████████████████████████████| 2273/2273 loading annotations into memory... Done (t=0.16s) creating index... index created! Traceback (most recent call last): File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\runpy.py", line 87, in run_code exec(code, run_globals) File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy_main.py", line 39, in cli.main() File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main run() File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="main") File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "c:\Users\WANGWEI.vscode\extensions\ms-python.python-2023.6.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "example/auto_compression/pytorch_yolo_series/run.py", line 149, in main() File "example/auto_compression/pytorch_yolo_series/run.py", line 137, in main ac.compress() File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 593, in compress self.single_strategy_compress(strategy, config, strategy_idx, File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 775, in single_strategy_compress test_program_info = self._start_train( File "C:\Users\WANGWEI\anaconda3\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 822, in _start_train metric = self.eval_function( File "example/auto_compression/pytorch_yolo_series/run.py", line 80, in eval_function map_res = coco_metric(anno_file, bboxes_list, bbox_nums_list, image_id_list) File "D:\pro\PaddleSlim-develop\example/auto_compression/pytorch_yolo_series\post_process.py", line 196, in coco_metric results += _get_det_res(bboxes, bbox_nums, image_id, clsid2catid) File "D:\pro\PaddleSlim-develop\example/auto_compression/pytorch_yolo_series\post_process.py", line 222, in _get_det_res category_id = label_to_cat_id_map[int(num_id)] KeyError: 39 怎么解决

stdio159 avatar Apr 03 '23 03:04 stdio159

同问

bigbeef avatar Apr 27 '23 10:04 bigbeef

同问

目前我也没有解决,社区还没人回复,尝试其他的方案吧。

stdio159 avatar Apr 27 '23 11:04 stdio159

看起来像是修改之后的后处理和示例代码里的不太一样,可以提供下修改之后的模型吗?

ceci3 avatar Feb 06 '24 06:02 ceci3