yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

Onnx inference not working for image instance segmentation, maybe a bug in ONNX model?

Open V4A001 opened this issue 1 year ago • 4 comments

Search before asking

  • [X] I have searched the YOLOv5 issues and discussions and found no similar questions.

Question

I have trained my model with Yolov7 at github, but cannot run the inherence (predict.py) without issues when exported to ONNX. At Yolov5 the inference is also not working with my Pytorch .pt file however. Strange enough the .onnx given there runs with this Yolov5 version of segmentation.

I see in the onnx presented here, the input image is a fixed mask and not dynamic, where the other is dynamic with different batch size. What input and outputs to be used ? My own has various slides although the others are more dense. Is this caused by reparameterization ?

I get errors like: For my own .pt model: `PS D:\yolov5> python segment/predict.py --weights best.pt --source "d:\testimage.jpg" segment\predict: weights=['best.pt'], source=d:\testimage.jpg, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\predict-seg, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1, retina_masks=False YOLOv5 v7.0-47-g2370a55 Python-3.10.8 torch-1.13.0+cpu CPU

Traceback (most recent call last): File "D:\yolov5\segment\predict.py", line 284, in main(opt) File "D:\yolov5\segment\predict.py", line 279, in main run(**vars(opt)) File "C:\Users..\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "D:\yolov5\segment\predict.py", line 101, in run model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) File "D:\yolov5\models\common.py", line 345, in init model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse) File "D:\yolov5\models\experimental.py", line 79, in attempt_load ckpt = torch.load(attempt_download(w), map_location='cpu') # load File "C:..\lib\site-packages\torch\serialization.py", line 789, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "C:..\lib\site-packages\torch\serialization.py", line 1131, in _load result = unpickler.load() File "C:..\lib\site-packages\torch\serialization.py", line 1124, in find_class return super().find_class(mod_name, name) AttributeError: Can't get attribute 'MP' on <module 'models.common' from 'D:\yolov5\models\common.py'>My the .pt model in ONNX model: c, mh, mw = protos.shape # CHW ValueError: too many values to unpack (expected 3)The same happens for the ONNX model in this github:PS D:..yolov5> python segment/predict.py --weights yolov5s.onnx --source "D:..myimage.jpg" segment\predict: weights=['yolov5s.onnx'], source=D:..myimage.jpg, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\predict-seg, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1, retina_masks=False YOLOv5 v7.0-47-g2370a55 Python-3.10.8 torch-1.13.0+cpu CPU

Loading yolov5s.onnx for ONNX Runtime inference... Traceback (most recent call last): File "D:..yolov5\segment\predict.py", line 285, in main(opt) File "D:..yolov5\segment\predict.py", line 280, in main run(**vars(opt)) File "C:..\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "D:..yolov5\segment\predict.py", line 131, in run pred, proto = model(im, augment=augment, visualize=visualize)[:2] ValueError: not enough values to unpack (expected 2, got 1) PS D:..yolov5> `

I would suspect there is a error in the ONNX model in this project as well. But not 100% sure as my own is not working either, and the one of the other YoloV7 project runs here perfectly.

image

image

image

Additional

No response

V4A001 avatar Dec 23 '22 15:12 V4A001

👋 Hello @V4A001, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email [email protected].

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

github-actions[bot] avatar Dec 23 '22 15:12 github-actions[bot]

@V4A001 This repo only supports yolov5. Are you seeing this error on a yolov5 trained model?

AyushExel avatar Dec 25 '22 08:12 AyushExel

@AyushExel , yes, I see my code snippets above are glued together. I would suspect there is a error in the ONNX model in this project as well. But not 100% sure as my own is not working either, and the one of the other YoloV7 project runs here perfectly.

The same happens for the ONNX model in this github: PS D:..yolov5> python segment/predict.py --weights yolov5s.onnx --source "D:..myimage.jpg" The error is:

` ValueError: not enough values to unpack (expected 2, got 1) PS D:..yolov5> ``

V4A001 avatar Dec 30 '22 08:12 V4A001

you can try this pr https://github.com/ultralytics/yolov5/pull/9645 image

UNeedCryDear avatar Jan 04 '23 09:01 UNeedCryDear

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

  • Wiki – https://github.com/ultralytics/yolov5/wiki
  • Tutorials – https://docs.ultralytics.com/yolov5
  • Docs – https://docs.ultralytics.com

Access additional Ultralytics ⚡ resources:

  • Ultralytics HUB – https://ultralytics.com/hub
  • Vision API – https://ultralytics.com/yolov5
  • About Us – https://ultralytics.com/about
  • Join Our Team – https://ultralytics.com/work
  • Contact Us – https://ultralytics.com/contact

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

github-actions[bot] avatar Feb 04 '23 00:02 github-actions[bot]

Hi, I encountered similar problems. After conversion, the input and output parts of the model are not complete, thus not usable. Have you found a solution?

yiliu-coding avatar Jul 05 '23 10:07 yiliu-coding

@yiliu-coding have you verified the model conversion process and checked if the input and output parts of the model are correct? Double-checking these steps might help in resolving the issue. If you have any further information or specific errors/messages, please provide them so that we can assist you better.

glenn-jocher avatar Jul 05 '23 11:07 glenn-jocher