ultralytics/yolov5

Negative weights when using Macbook M1 with MPS

guybashan opened this issue ยท 4 comments

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Detection

Bug

Hi,

Indeed I am using the latest code from git (main branch).
I re-run the training using this:
/cam-analyzer/pytorch_metal_env/bin/python ../yolov5/train.py --img 416 --batch 16 --epochs 100 --data ../yolo_cfg/data.yaml --weights yolov5m.pt --device mps
I re-checked my "train" and "val" folders. They look ok and the files look fine. I created the labels using YoloLabel app (open source).
I run the detection using this command:
/cam-analyzer/pytorch_metal_env/bin/python detect.py --save-txt --save-conf --weights /Users/user/Documents/dev/yolo_model/cam_analyzer/weights/best.pt --source /Users/user/Documents/dev/yolo_images --conf 0.1 --project /Users/columbo/Documents/dev/yolo_results --name detections --device mps
I use M1 Max with 64GB memory
I enabled working with GPU

Environment

  • Yolo 5
  • Python 3.13.0

Minimal Reproducible Example

/cam-analyzer/pytorch_metal_env/bin/python detect.py --save-txt --save-conf --weights /Users/user/Documents/dev/yolo_model/cam_analyzer/weights/best.pt --source /Users/user/Documents/dev/yolo_images --conf 0.1 --project /Users/columbo/Documents/dev/yolo_results --name detections --device mps

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

๐Ÿ‘‹ Hello @guybashan, thank you for reaching out and using YOLOv5 ๐Ÿš€! This is an automated response to confirm that we've received your issue. One of our Ultralytics engineers will assist you soon.

It looks like you're encountering issues with negative weights while using YOLOv5 on a Macbook M1 with MPS. To help us investigate further, please make sure you've provided a minimum reproducible example of your issue. This will greatly assist our team in diagnosing and fixing the problem.

To ensure the correct setup, confirm that you have Python version 3.8.0 or higher installed, along with all dependencies from the requirements.txt file, and that you're running on a compatible environment.

If you have any questions about your custom training setup, it would also be helpful to include dataset image examples, training logs, and verify if you're following best training practices.

Additionally, we're excited to let you know about YOLOv8, our latest state-of-the-art object detection model designed for enhanced performance, accuracy, and usability. Stay tuned for updates and enhancements! ๐Ÿš€โœจ

Thank you for your patience and contribution to the YOLOv5 community! ๐Ÿ˜Š

@guybashan thank you for reporting this issue. Please ensure that your PyTorch version supports MPS on Mac M1 and try updating to the latest version if you haven't already. If the problem persists, consider running the training on a different device to isolate the issue.

@guybashan thank you for reporting this issue. Please ensure that your PyTorch version supports MPS on Mac M1 and try updating to the latest version if you haven't already. If the problem persists, consider running the training on a different device to isolate the issue.

@pderrenger thanks for your respond.
My PyTouch version does support MPS and I also ran a verification script to make sure of it.
Please note: when I switch to CPU, it all looks fine and I no longer have negative values.
Please also note: it doesn't seems to be related to the training process, since I used a model trained with MPS. When I ran it on MPS I got detections with negative value. When I ran it with CPU detection didn't have negative values.

@guybashan it seems like the issue might be specific to MPS execution. I recommend checking for any known issues with PyTorch MPS support or trying a different PyTorch version that might resolve this discrepancy.