ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.2k stars 16.43k forks source link

ONNX benchmark error #10629

Closed mwitiderrick closed 1 year ago

mwitiderrick commented 1 year ago
cd yolov5
python benchmarks.py --weights yolov5s.onnx --img 640

I have this error benchmarking onnx

benchmarks: weights=yolov5s.onnx, imgsz=640, batch_size=1, data=/content/yolov5/data/coco128.yaml, device=, half=False, test=False, pt_only=False, hard_fail=False
YOLOv5 🚀 v7.0-53-g65071da Python-3.8.16 torch-1.13.0+cu116 CPU

Traceback (most recent call last):
  File "benchmarks.py", line 169, in <module>
    main(opt)
  File "benchmarks.py", line 164, in main
    test(**vars(opt)) if opt.test else run(**vars(opt))
  File "benchmarks.py", line 65, in run
    model_type = type(attempt_load(weights, fuse=False))  # DetectionModel, SegmentationModel, etc.
  File "/content/yolov5/models/experimental.py", line 79, in attempt_load
    ckpt = torch.load(attempt_download(w), map_location='cpu')  # load
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 795, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 1002, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '\x08'.
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-12-d8bb9c5b22bb> in <module>
----> 1 get_ipython().run_cell_magic('bash', '', 'cd yolov5\npython benchmarks.py --weights yolov5s.onnx --img 640\n')

3 frames
<decorator-gen-103> in shebang(self, line, cell)

/usr/local/lib/python3.8/dist-packages/IPython/core/magics/script.py in shebang(self, line, cell)
    243             sys.stderr.flush()
    244         if args.raise_error and p.returncode!=0:
--> 245             raise CalledProcessError(p.returncode, cell, output=out, stderr=err)
    246 
    247     def _run_script(self, p, cell, to_close):

CalledProcessError: Command 'b'cd yolov5\npython benchmarks.py --weights yolov5s.onnx --img 640\n'' returned non-zero exit status 1.
white_check_mark
eyes
raised_hands

But this one works

%%bash
cd yolov5
python benchmarks.py --weights yolov5s.pt --img 640
github-actions[bot] commented 1 year ago

👋 Hello @mwitiderrick, 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 support@ultralytics.com.

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.

AI-Expert-04 commented 1 year ago

Onnx is not available for benchmarking.

python benchmarks.py --weights yolov5s.pt --img 640

` benchmarks: weights=/content/yolov5/yolov5s.pt, imgsz=640, batch_size=1, data=/content/yolov5/data/coco128.yaml, device=cpu, half=False, test=False Checking setup... YOLOv5 🚀 v6.1-135-g7926afc torch 1.10.0+cu111 CPU Setup complete ✅ (8 CPUs, 51.0 GB RAM, 41.5/166.8 GB disk)

Benchmarks complete (241.20s) Format mAP@0.5:0.95 Inference time (ms) 0 PyTorch 0.4623 127.61 1 TorchScript 0.4623 131.23 2 ONNX 0.4623 69.34 3 OpenVINO 0.4623 66.52 4 TensorRT NaN NaN 5 CoreML NaN NaN 6 TensorFlow SavedModel 0.4623 123.79 7 TensorFlow GraphDef 0.4623 121.57 8 TensorFlow Lite 0.4623 316.61 9 TensorFlow Edge TPU NaN NaN 10 TensorFlow.js NaN NaN ` Looking at the results above, you can see that onnx was used in Benchmarks complete.

Export ONNX for up to 3x CPU speed

mwitiderrick commented 1 year ago

Thanks

github-actions[bot] commented 1 year ago

👋 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:

Access additional Ultralytics ⚡ resources:

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 ⭐!

glenn-jocher commented 1 year ago

@mwitiderrick you're welcome! If you need any further assistance or have more questions, feel free to ask. Your feedback and contributions help improve the YOLOv5 experience for the entire community. Happy coding!