hub icon indicating copy to clipboard operation
hub copied to clipboard

How to deploy yolov5.pt trained from Hub?

Open zerolovesea opened this issue 2 years ago β€’ 2 comments

Search before asking

Question

I'm trying to use detect.py from yolov5 offical github with the weight file trained by Hub.

I'm not sure if i have to use the ultralystic.yolo instead of detect.py to deploy this model?

It rasie an error like below, i printed out the detection output after scale_box function:

detect: weights=['/home/user/leansight/BehaviorDetector/train/ultra_mask.pt'], source=/home/user/leansight/source_videos/source_1713261840000.jpg, data=data/trilights.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 πŸš€ 2024-2-7 Python-3.10.13 torch-1.12.1+cu116 CUDA:0 (Tesla T4, 14910MiB)

YOLOv5s6u summary (fused): 253 layers, 15253432 parameters, 0 gradients, 24.2 GFLOPs
names: {0: '-', 1: 'Mask'}
det: tensor([[0.00000e+00, 0.00000e+00, 1.07000e+02, 1.43000e+02, 6.37971e+04, 5.07800e+03],
        [0.00000e+00, 0.00000e+00, 4.90000e+01, 4.20000e+01, 1.80220e+04, 6.34000e+02],
        [2.60000e+01, 0.00000e+00, 5.30000e+01, 1.30000e+01, 6.05300e+03, 5.03900e+03],
        [1.20000e+01, 0.00000e+00, 2.40000e+01, 0.00000e+00, 2.30786e+03, 4.75900e+03]], device='cuda:0')
c:634
Traceback (most recent call last):
  File "/home/user/leansight/BehaviorDetector/train/yolov5/detect.py", line 229, in <module>
    main(opt)
  File "/home/user/leansight/BehaviorDetector/train/yolov5/detect.py", line 223, in main
    run(**vars(opt))
  File "/home/user/leansight/miniconda3/envs/detector/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/user/leansight/BehaviorDetector/train/yolov5/detect.py", line 143, in run
    s += f"{n} {names[int(c)]}{'s' * (n > 1)}, "  # add to string
KeyError: 634

Additional

No response

zerolovesea avatar Apr 17 '24 03:04 zerolovesea

πŸ‘‹ Hello @zerolovesea, thank you for raising an issue about Ultralytics HUB πŸš€! Please visit our HUB Docs to learn more:

  • Quickstart. Start training and deploying YOLO models with HUB in seconds.
  • Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
  • Projects: Creating and Managing. Group your models into projects for improved organization.
  • Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
  • Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
  • Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
    • iOS. Learn about YOLO CoreML models accelerated on Apple's Neural Engine on iPhones and iPads.
    • Android. Explore TFLite acceleration on mobile devices.
  • Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.

If this is a πŸ› Bug Report, please provide screenshots and steps to reproduce your problem to help us get started working on a fix.

If this is a ❓ Question, please provide as much information as possible, including dataset, model, environment details etc. so that we might provide the most helpful response.

We try to respond to all issues as promptly as possible. Thank you for your patience!

github-actions[bot] avatar Apr 17 '24 03:04 github-actions[bot]

Hey there! It looks like the model you're trying to deploy has class labels that don't match with the labels defined in your data configuration file referred to as data/trilights.yaml. The KeyError: 634 suggests that the output tensor is attempting to access a class index 634, which is not present in your label set in the YAML file. 🧐

To resolve this issue, please ensure that the names list in your YAML configuration file includes all needed class indices that your model might output. This typically includes every class from 0 to n-1 if you have n classes. Double-check this mapping and update your YAML file accordingly!

Hope this helps! If the problem persists, reviewing the exact contents of your trilights.yaml and comparing them against your model’s class labels should provide further insight.

pderrenger avatar May 03 '24 09:05 pderrenger

πŸ‘‹ Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

  • Docs: https://docs.ultralytics.com
  • HUB: https://hub.ultralytics.com
  • Community: https://community.ultralytics.com

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 YOLO πŸš€ and Vision AI ⭐

github-actions[bot] avatar Jun 03 '24 00:06 github-actions[bot]