-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
No module named 'models' #22
Comments
Hello @yxxxqqq, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Google Colab Notebook, Docker Image, and GCP 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:
For more information please visit https://www.ultralytics.com. |
@yxxxqqq thanks for your feedback. Yes you are correct, we use the current method, saving and loading the entire model. In the past we use the alternative method https://github.com/ultralytics/yolov3, of creating a model from a cfg file, and then replacing the random weights with the checkpoints weights using a state_dict(). This method caused two problems. The first is that initialization is slower, as a model is created with random weights, and then those random weights are replaced with the checkpoint weights, creating duplication of effort. The second, and main problem, was that a user was required to supply two items to load a model for inference or testing (the weights and cfg), instead of a single item. This places extra requirements on the user, and introduces a failure point during usage, as the user would often incorrectly match weights with incompatible cfg (i.e. yolov3-spp.pt with yolov3.cfg), leading to errors and confusion, and them raising issues and bug reports, using our time. So we view the current method as the lesser of two evils. The main downside we see are SourceChangeWarnings that are generated when the modules the model is built on are updated since it was created. |
@glenn-jocher Thanks for your reply! I have solved the 'SourceChangeWarnings' by the code you provided.
But the problems I said still exists:
|
@yxxxqqq the behavior you describe is the default behavior of all pytorch models. For self contained models that do not require any external dependencies or imports you would need to export to onnx or torchscript formats. An alternative solution is to integrate this repo with torch hub https://pytorch.org/hub/. |
@glenn-jocher Thank you very much ! |
@yxxxqqq we recently added support for PyTorch Hub. You may be able to use YOLOv5 in your own repository like this: import torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) |
@glenn-jocher wow, so great! thanks for your excellent work! |
@yxxxqqq you're welcome! |
I use your |
@elinor-lev no Original issue seems resolved, so I am closing this issue now. |
@yxxxqqq Hello, will you please explain in detail what you did to resolve the problem? |
@elinor-lev if you'd like to add verbose functionality to the hub loading, I don't have time to do this personally, but we are open to PRs! |
I do it dirty: copy dir models and utils and paste into target dir, this can work. |
@yxxxqqq Have you solved it? I have the same problem with NMS After NMS: |
@yxxxqqq if |
@glenn-jocher For the same image In detect.py When I used pred got 3 dims and after NMS I changed it to pred got 5 dims and after NMS Do I need to reshape the pred before NMS? |
@1chimaruGin torch hub model may be in training mode rather than eval mode. |
@glenn-jocher Got it! |
I comment this issue because I got the same problem. I just integrate the detect.py to an existing project but I got the error message that say
The previous message don't really explain how to fix this (Instead of using back the cfg file and so one). What is exactly the solution to this error message ? I use Pytorch 1.6 and Python 3.6 |
I faced the same problem when I use |
@1chimaruGin so you assume that every time we launch the script, it will download from the hub, so we need network access on the device that will execute the project ? If I change all the line from: to I got a SSL CERTIFICATE_VERIFY_FAILED, that I can easily correct. But the other problem, it that I'm using the exact same directory structure. So when I try to run the script it say it can't found utils.google_utils, which is normal because the path should be detector_files.ultralytics.yolov5.utils.google_utils |
Yeah It will download from the hub but for once. I mean in
|
@1chimaruGin Thanks, but if I run the detect.py without any changes in folders architecture it works, my need is to change the yolov5 folders architecture to fit a bigger project, so I need to change the imports to fit my architecture. Very strange that if I change the imports in all files, there is still a call to "models" which is wrong path ... I don't know where is this call. I will go deeper to find a solution, if @glenn-jocher has an idea how to fix this ? Thanks again for your help |
have you tried to add
to the file where the bug occurs? |
@Stephenfang51 only .autoshape() models can accept PIL images. The normal model you are using only accepts standard pytorch inputs. |
so should I convert PIL images to torch.tensor ? |
@Stephenfang51 yes you can do that, or you can convert your model into an .autoshape() model as the tutorial shows. model = model.autoshape() |
after your suggestion
|
anything wrong with my code ? I just gave up your yolov3 and try yolov5, still error
errors
|
@Stephenfang51 I'll try to produce an example using loading a 20-class VOC trained model. Remember if you are using YOLOv3, all older models trained with the archive branch are not forward compatible. To load a custom YOLOv3 model in PyTorch Hub, it must be trained with the new master branch that is YOLOv5 forward compatible. |
From ultralytics/yolov3: BRANCH NOTICE: The ultralytics/yolov3 repository is now divided into two branches:
$ git clone https://github.com/ultralytics/yolov3 # master branch (default)
$ git clone -b archive https://github.com/ultralytics/yolov3 # archive branch |
TODO: Simplify custom model loading, i.e. |
@Stephenfang51 I've updated YOLOv5 PyTorch Hub functionality to allow for much simpler loading of custom models of any architecture created with our YOLOv3/5 repos. Please git pull to receive the latest updates, and then try the new method (you may need to use Custom ModelsThis example loads a custom 20-class VOC-trained YOLOv5s model model = torch.hub.load('ultralytics/yolov5', 'custom', path_or_model='yolov5s_voc_best.pt', force_reload=True)
model = model.autoshape() # for PIL/cv2/np inputs and NMS |
I think the reason is the line
And of course I used the Yolov3 (master)which is compatible with your Yolov5. Thanks for your Help 👍 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello sir |
@Liaouzhe hello! The error message One possible solution is to ensure that the If you are still encountering the error after trying these solutions, please let me know and we can work together to further troubleshoot the issue. Thank you! |
@glenn-jocher The problem I am encountering now is adding the model I trained to the program, and the following error occurs, how can I solve it? |
@Liaouzhe hello! It seems like the image you are referring to is not accessible. If you could provide the error message as text, I would be happy to assist you in resolving the issue. Thank you! |
My environment and problem:
There is no problem for object detection, and it's a great job, thank you!
However, I want to use this repo as a detector in my project, which is the first stage. But I can't use 'torch.load()' to load the weights you provided, get the error as follows:
My solution
New problem
I don't know what's the problem it is? And I don't understand why you use this save method instead of another more flexible way? About my problem, do you have any good ideas? Thank you very much!
The text was updated successfully, but these errors were encountered: