yolov5
yolov5 copied to clipboard
RuntimeError: result type Float can't be cast to the desired output type long int
Search before asking
- [X] I have searched the YOLOv5 issues and found no similar bug report.
YOLOv5 Component
No response
Bug
Today, it threw an error while running train.py as follows. Before this, I successfully completed the training process. I have not made any changes to the document.
Traceback (most recent call last):
File "train.py", line 650, in
Environment
YOLOv5 š v6.1-11-g63ddb6f0 torch 1.12.0+cu102 GPU
colab
Python:3.8
GPU:Tesla P100 16280MiB
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
- [ ] Yes I'd like to help by submitting a PR!
š Hello @happylulu666, 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):
-
Google Colab and Kaggle notebooks with free GPU:
- Google Cloud Deep Learning VM. See GCP Quickstart Guide
- Amazon Deep Learning AMI. See AWS Quickstart Guide
-
Docker Image. See Docker Quickstart Guide
Status
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.
@happylulu666 this is an incompatibility of older versions of YOLOv5 with torch 1.12. Updating YOLOv5 will resolve this.
To update YOLOv5:
-
Git ā
git pull
from within youryolov5/
directory orgit clone https://github.com/ultralytics/yolov5
again -
PyTorch Hub ā Force-reload
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
-
Notebooks ā View updated notebooks
-
Docker ā
sudo docker pull ultralytics/yolov5:latest
to update your image
thank you
git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5
this does not solve the problem, still getting same error
been using the same script in Colab, and this issue only start from yesterday
@yuhe0925 this issue has been resolved in master, please update your code and make sure you are using the latest compatible version of torch==1.11.0. If this doesn't resolve your issue then please submit a minimum reproducible example to help us investigate.
How to create a Minimal, Reproducible Example
When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
- ā Minimal ā Use as little code as possible to produce the problem
- ā Complete ā Provide all parts someone else needs to reproduce the problem
- ā Reproducible ā Test the code you're about to provide to make sure it reproduces the problem
For Ultralytics to provide assistance your code should also be:
- ā
Current ā Verify that your code is up-to-date with GitHub master, and if necessary
git pull
orgit clone
a new copy to ensure your problem has not already been solved in master. - ā Unmodified ā Your problem must be reproducible using official YOLOv5 code without changes. Ultralytics does not provide support for custom code ā ļø.
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the š Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.
Thank you! š
I had the same issue and since I have made a lot of changes to the base code I couldn't pull master branch, thanks to glenn's comment I solved this error by editing the requirements.txt file and setting torch version to == 1.7.0 and it solved the issue
I had the same issue and since I have made a lot of changes to the base code I couldn't pull master branch, thanks to glenn's comment I solved this error by editing the requirements.txt file and setting torch version to == 1.7.0 and it solved the issue
I got the same issue and setup torch to version 1.7.0 solved it. Thanks dude....
My same issue was resolved by changing requirement.txt file . Torch version >1.7.0 when changed to ==1.7.0 resolved the issue.
My same issue was resolved by changing requirement.txt file . Torch version >1.7.0 when changed to ==1.7.0 resolved the issue.
I tried this method, but it showed that No matching distribution found for torch==1.7.0
Did u check it in Requirement.txt?
On Sun, Jul 17, 2022 at 4:13 PM GongZu @.***> wrote:
My same issue was resolved by changing requirement.txt file . Torch version >1.7.0 when changed to ==1.7.0 resolved the issue.
I tried this method, but it showed that No matching distribution found for torch==1.7.0
ā Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov5/issues/8405#issuecomment-1186485226, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALTFBVIWXEB6FTRLNEI24VLVUPTD7ANCNFSM52IJGYNA . You are receiving this because you commented.Message ID: @.***>
@happylulu666 @yuhe0925 @hoseinhamzei @happylulu666 @oki-aryawan @molua @mishi-sarfraz good news š! This issue should now be fixed ā in PR #8067 from June 1st. To receive this update:
-
Git ā
git pull
from within youryolov5/
directory orgit clone https://github.com/ultralytics/yolov5
again -
PyTorch Hub ā Force-reload
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
-
Notebooks ā View updated notebooks
-
Docker ā
sudo docker pull ultralytics/yolov5:latest
to update your image
Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 š!
Thanks for Glenn's kind reply and useful advice! I would also like to thank the friends who have the same problems as me for discussing this.
I have the same issue on Windows, so I uninstalled torch (1.12) and tried installing 1.7.0, but that doesn't match with my CUDA 11.3. I then safely moved to Linux , where I have torch 1.12 and CUDA 10.2.
I have the same issue on Windows, so I uninstalled torch (1.12) and tried installing 1.7.0, but that doesn't match with my CUDA 11.3. I then safely moved to Linux , where I have torch 1.12 and CUDA 10.2.
I'm having the same issue as well. Torch version 1.7.0 is not compatible with CUDA 11.3.
Bug
File "train.py", line 642, in
Environment Python: 3.8 CUDA: 11.3 Torch version: 1.12.1 Windows: 11
Note I'm running the code in Jupyter and also have updated YOLOv5. But still facing the bug errors as shown above. Really need help with these issues :(
@owentamin1996 update your YOLOv5 code, it's out of date. To update:
-
Git ā
git pull
from within youryolov5/
directory orgit clone https://github.com/ultralytics/yolov5
again -
PyTorch Hub ā Force-reload
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
-
Notebooks ā View updated notebooks
-
Docker ā
sudo docker pull ultralytics/yolov5:latest
to update your image
Simply use, install torch==1.11, torchvision==0.12, torchtext==0.12, torchaudio==0.11 Compatible versions for torch 1.11 No error will be reflected.
I have solved the issue by downgrading Torch version to 1.10.1. However, another problem arise in which the value for P,R and other relevant metrics are all zero. Iām using CUDA 11.3 for running the code.
@happylulu666 this is an incompatibility of older versions of YOLOv5 with torch 1.12. Updating YOLOv5 will resolve this.
To update YOLOv5:
- Git ā
git pull
from within youryolov5/
directory orgit clone https://github.com/ultralytics/yolov5
again- PyTorch Hub ā Force-reload
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
- Notebooks ā View updated notebooks
![]()
![]()
- Docker ā
sudo docker pull ultralytics/yolov5:latest
to update your image![]()
I have done this but still getting the same error "RuntimeError: result type Float can't be cast to the desired output type long int"
@lucysumi š hi, thanks for letting us know about this possible problem with YOLOv5 š. We've created a few short guidelines below to help users provide what we need in order to start investigating a possible problem.
How to create a Minimal, Reproducible Example
When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
- ā Minimal ā Use as little code as possible to produce the problem
- ā Complete ā Provide all parts someone else needs to reproduce the problem
- ā Reproducible ā Test the code you're about to provide to make sure it reproduces the problem
For Ultralytics to provide assistance your code should also be:
- ā
Current ā Verify that your code is up-to-date with GitHub master, and if necessary
git pull
orgit clone
a new copy to ensure your problem has not already been solved in master. - ā Unmodified ā Your problem must be reproducible using official YOLOv5 code without changes. Ultralytics does not provide support for custom code ā ļø.
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the š Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.
Thank you! š
Seeing same error, here are my versions
Type "help", "copyright", "credits" or "license" for more information.
>>> import yolov5
>>> yolov5.__version__
'6.1.8'
>>> import torch
>>> torch.__version__
'1.12.1+cu116'
@apiszcz yolov5 pip package has nothing to do with Ultralytics. To use correct code install using git clone commands in readme.
will do/try next, thank you. git clone update worked! I guess i need to do that more frequently. Thank you for yv5 and the fast response.
š 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 ā!
This may also have something to do with the version of onnxruntime, which was resolved when I went back to onnxruntime1.10.0
š 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 ā!
In loss.py (line 173 ), gain = torch.ones(7, device=targets.device) ā gain = torch.ones(7, device=targets.device).long()
In loss.py (line 173 ), gain = torch.ones(7, device=targets.device) ā gain = torch.ones(7, device=targets.device).long()
Thank you. You are right
@Tefor @liyanluo is this a change that we should apply to master, or are you applying this as a patch to older code?
'gain = torch.ones(7, device=targets.device).long()' worked for me. Thank you @Tefor