ouyanghaodong / DEYO

Implementation of paper - DEYO: DETR with YOLO for End-to-End Object Detection
GNU Affero General Public License v3.0
71 stars 5 forks source link

onnx 导出错误 #18

Open eamon-cai opened 5 months ago

eamon-cai commented 5 months ago

/content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/head.py:372: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if self.shape != shape: /content/drive/Shareddrives/train/DEYO-main/ultralytics/utils/tal.py:299: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results). for i, stride in enumerate(strides): /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/head.py:314: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect. dbox = dbox / torch.tensor(imgsz, device=dbox.device)[[1, 0, 1, 0]] /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/head.py:380: TracerWarning: Using len to get tensor shape might cause the trace to be incorrect. Recommended usage would be tensor.shape[0]. Passing a tensor of different shape might lead to errors or silently give incorrect results. bs = len(feats) /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/transformer.py:286: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert sum(s[0] s[1] for s in value_shapes) == len_v /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/transformer.py:297: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if num_points == 2: /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/transformer.py:301: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! elif num_points == 4: /content/drive/Shareddrives/train/DEYO-main/ultralytics/nn/modules/head.py:346: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect. y[..., :4] = y[..., :4] torch.tensor(imgsz, device=y.device)[[1, 0, 1, 0]] /usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_opset9.py:5859: UserWarning: Exporting aten::index operator of advanced indexing in opset 17 is achieved by combination of multiple ONNX operators, including Reshape, Transpose, Concat, and Gather. If indices include negative values, the exported graph will produce incorrect results. warnings.warn(

使用项目提供的导出脚本报错如上 全新环境

eamon-cai commented 5 months ago

不知道是否是提供的预训练模型问题 所以我尝试训练自己的数据集
105 topk_values, topk_indexes = torch.topk(scores.reshape(scores.shape[0], -1), num_select, dim=1) RuntimeError: selected index k out of range nc已经修改

ouyanghaodong commented 5 months ago

第一个是 warning 可以忽略,如果您修改了nc,您也需要修改 deyo_onnx.py 中的 nc:

截屏2024-05-02 10 34 09
eamon-cai commented 5 months ago

上面第一个是所有配置都默认没有修改 导出仓库自带的模型报错 导出时没有正常导出的日志 且文件无法用netron打开

后面的是我训练时报错 还未涉及到导出

ouyanghaodong commented 5 months ago

/root/DEYO-main/ultralytics/nn/modules/head.py:372: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if self.shape != shape: /root/DEYO-main/ultralytics/utils/tal.py:299: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results). for i, stride in enumerate(strides): /root/DEYO-main/ultralytics/nn/modules/head.py:314: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect. dbox = dbox / torch.tensor(imgsz, device=dbox.device)[[1, 0, 1, 0]] /root/DEYO-main/ultralytics/nn/modules/head.py:380: TracerWarning: Using len to get tensor shape might cause the trace to be incorrect. Recommended usage would be tensor.shape[0]. Passing a tensor of different shape might lead to errors or silently give incorrect results. bs = len(feats) /root/DEYO-main/ultralytics/nn/modules/transformer.py:286: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert sum(s[0] s[1] for s in value_shapes) == len_v /root/DEYO-main/ultralytics/nn/modules/transformer.py:297: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if num_points == 2: /root/DEYO-main/ultralytics/nn/modules/transformer.py:301: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! elif num_points == 4: /root/DEYO-main/ultralytics/nn/modules/head.py:346: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect. y[..., :4] = y[..., :4] torch.tensor(imgsz, device=y.device)[[1, 0, 1, 0]] /root/miniconda3/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py:5589: UserWarning: Exporting aten::index operator of advanced indexing in opset 16 is achieved by combination of multiple ONNX operators, including Reshape, Transpose, Concat, and Gather. If indices include negative values, the exported graph will produce incorrect results. warnings.warn( ============= Diagnostic Run torch.onnx.export version 2.0.0+cu118 ============= verbose: False, log level: Level.ERROR ======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ======================== 我使用仓库自带的模型并没有出现任何问题,这是我环境ONNX的版本信息: onnx 1.14.0 onnx-graphsurgeon 0.3.12 onnxruntime 1.16.3 使用netron也是正常打开的:

截屏2024-05-03 14 34 44
ouyanghaodong commented 5 months ago

除了修改data.yaml文件中的 nc,您再试试直接修改ultralytics/nn/modules/head.py中的 RTDETRDecoder 的 nc:

def __init__(
   self,
   nc=80,
   ch=(512, 1024, 2048),
   hd=64,  # hidden dim
   nq=100,  # num queries
   ndp=4,  # num decoder points
   nh=8,  # num head
   ndl=6,  # num decoder layers
   d_ffn=1024,  # dim of feedforward
   dropout=0.0,
   act=nn.ReLU(),
   eval_idx=-1,
   # Training args
   nd=100,  # num denoising
   label_noise_ratio=0.5,
   box_noise_scale=1.0,
   learnt_init_query=False,
):
eamon-cai commented 5 months ago

感谢解答 似乎是环境问题 安装onnx-graphsurgeon后一切就正常了