Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error : Input type (torch.FloatTensor) and weight type (torch.HalfTensor) should be the same #101

Closed
niharpatel1999 opened this issue Jun 16, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@niharpatel1999
Copy link

I trained my yolov5l model on Colab and updated the last.pt file to run inference on the local machine. But it shows the following error
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.HalfTensor) should be the same
while executing
python detect.py --weights weights/last.pt --img 416 --conf 0.4 --source ../test --device cpu

@niharpatel1999 niharpatel1999 added the bug Something isn't working label Jun 16, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Jun 16, 2020

Hello @niharpatel1999, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

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 model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

@glenn-jocher
Copy link
Member

@niharpatel1999 ok thanks for the bug report. I will try to reproduce.

@glenn-jocher
Copy link
Member

I used our colab notebook to train a model for 3 epochs, then used last.pt to run inference. No problem at all, everything works fine.

Screen Shot 2020-06-16 at 10 26 41 AM

@niharpatel1999
Copy link
Author

niharpatel1999 commented Jun 16, 2020 via email

@glenn-jocher
Copy link
Member

@niharpatel1999 ah, ok I see. I will try to reproduce your use case here.

@glenn-jocher
Copy link
Member

@niharpatel1999 I repeated your steps, everything works fine for me. I don't see any problems. You may want to repeat your steps with the latest version of the repo, perhaps your bug has already been resolved.

You can also run models on cpu in colab like this by the way:
python detect.py --device cpu

@niharpatel1999
Copy link
Author

niharpatel1999 commented Jun 16, 2020 via email

@deeppatel4557
Copy link

@glenn-jocher, I am @niharpatel1999 teammate the weights tensor in our case is of the type torch.HalfTensor because we have trained it on GPU so there is an error of Input type torch.FloatTensor and weight type of torch.HalfTensor should be the same. we resolved that error just by changing one line of code in detect.py. Line number 23 has model.to(device).eval() to model.to(device).float().eval() by doing this we resolved the error by changing the type of weight tensor to float.It executed successfully on the CPU.Thanks for your support.

@glenn-jocher
Copy link
Member

This should have been resolved in recent commits. Please git pull and try again.

@rubysiu
Copy link

rubysiu commented Mar 4, 2022

@deeppatel4557 Thank you very much. Your proposal is very helpful to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants