-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
Better way to deploy / ModuleNotFoundError #985
Comments
Hello @EvgeniiTitov, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , 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 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. |
@EvgeniiTitov the intended workflow is simply:
|
Hi @glenn-jocher, Thanks for your reply. Apologies if I misunderstood you, but I guess your reply doesn't really suggest how to use the model in other projects without facing the ModuleNotFound error. Thanks in advance! |
@EvgeniiTitov not sure I follow. Pytorch models in general require access to modules they use, this is not specific to YOLOv5. If you want to run a native pytorch model you must also make the modules it requires available to it. You can run this code without issue from yolov5/: import torch
model = torch.load('yolov5s.pt', map_location='cpu')['model'].float().eval()
img = torch.rand(1,3,640,640)
prediction = model(img)[0]
prediction.shape # torch.Size([1, 25200, 85]) |
Hi @glenn-jocher, Apologies for the confusion, I must have worded my question badly. Just to reiterate I am unable to initialize the v5s model trained on the custom dataset outside the v5 project cloned and used for training. Whenever I try to load my model either using the attempt_load() function provided by you guys or using the code snippet above I get the same error: I would love to know what is the correct way to overcome this problem to be able to initialize and use the trained model in another project with a different folder structure. Thank you a lot! |
Hi @glenn-jocher, I would much appreciate it if you could reply to the above question. Sorry for being a pain in the ssa. Thanks a lot! |
@EvgeniiTitov hey buddy. Unfortunately model portability has not been high on our priority list, so I don't have any easy answers for you. We've been focusing on debugging and validating basic functionality (train, test, inference), which seems to be going well, as the new bug reports seem to have fallen recently, so soon I think we can focus more on useability and address some of these portability concerns. In general, if you would like to access YOLOv5 functionality outside this repo, your options are:
|
@EvgeniiTitov also note that PyTorch Hub and the yolov5 pip package (pip install yolov5) are planned to allow for extreme ease of use, i.e.: from yolov5 import yolov5s
img = cv2.imread('image.jpg')
predictions = yolov5s(img) Of these two, PyTorch hub should be there much sooner, hopefully in the next week or two. To enable this to work with a custom trained model, a simple call to update the state_dicts() should suffice. |
I was facing the same issue but I tried a different way which was mentioned ultralytics github repo. |
❔Question
Hello
First of all, thanks for the great work guys.
I've recently trained the small model on a custom dataset and now we'd love to test it. However, we got stuck with the same issue that has already been asked at least 2 times (issues 22 and 131). Sadly, nobody really gave any concrete answers in those tickets, so I am opening a new one with the hope to get answers.
We copied some files from yolov5/models and yolov5/utils and rewrote the rest. Now when we attempt loading the model we get the error message - ModuleNotFoundError: No module names 'models.yolo'.
What would be the best way to solve the issue? @glenn-jocher mentioned in another ticket that the entire model gets saved intentionally so that people need just the weights file to initialize the model.
a) If let's say I initialize the trained model and then save only the statedict, does it mean I will need both the *.yaml and .pt files to initialize the model in another project?
b) I know there's also an option to torch.jit.trace the model, but it didn't work for me when I tried to do so because some tensors did not match. Has it worked for anyone? Is it even possible to trace 5v models? I believe tracing has its limitations.
c) There's an option to load yolov5 models from the torch hub. However is it possible to initialize it with custom weights and not the default one?
Thank you in advance.
E
The text was updated successfully, but these errors were encountered: