ultralytics / hub

Ultralytics HUB tutorials and support
https://hub.ultralytics.com
GNU Affero General Public License v3.0
107 stars 11 forks source link

How to deploy yolov5.pt trained from Hub? #646

Open zerolovesea opened 4 weeks ago

zerolovesea commented 4 weeks ago

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

github-actions[bot] commented 4 weeks ago

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

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!

pderrenger commented 1 week ago

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.