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

Can't load self trained model for prediction #180

Closed
1 of 2 tasks
Melvin0419 opened this issue Aug 13, 2023 · 7 comments
Closed
1 of 2 tasks

Can't load self trained model for prediction #180

Melvin0419 opened this issue Aug 13, 2023 · 7 comments
Assignees
Labels
bug Something isn't working onsite The change was suggested during an initiative on a company onsite

Comments

@Melvin0419
Copy link

Search before asking

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

Notebook name

train-yolov8-object-detection-on-custom-dataset.ipynb

Bug

requirements: YOLOv8 requirement "models" not found, attempting AutoUpdate...
requirements: ❌ Command 'pip install "models" ' returned non-zero exit status 1.

ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ultralytics/nn/tasks.py in torch_safe_load(weight)
331 try:
--> 332 return torch.load(file, map_location='cpu') # load
333 except ModuleNotFoundError as e:

10 frames
ModuleNotFoundError: No module named 'models'

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/torch/serialization.py in find_class(self, mod_name, name)
1163 pass
1164 mod_name = load_module_mapping.get(mod_name, mod_name)
-> 1165 return super().find_class(mod_name, name)
1166
1167 # Load the data (which may in turn use persistent_load to load tensors)

ModuleNotFoundError: No module named 'models'


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

Environment

Google Colab

Minimal Reproducible Example

from ultralytics import YOLO

model = YOLO("best.pt")

Additional

I followed the tutorial on google colab, and i have successfully trained a model with my own dataset. I have tested the trained model, named "best.pt", and it also work pretty well. Then I downloaded the "best.pt" from google colab, and tried to load the model on local side. The script I used is:

from ultralytics import YOLO

model = YOLO("best.pt")

just the same as the script for prediction on DOCs , but i encountered the following error:

requirements: YOLOv8 requirement "models" not found, attempting AutoUpdate...
requirements: ❌ Command 'pip install "models" ' returned non-zero exit status 1.

ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ultralytics/nn/tasks.py in torch_safe_load(weight)
331 try:
--> 332 return torch.load(file, map_location='cpu') # load
333 except ModuleNotFoundError as e:

10 frames
ModuleNotFoundError: No module named 'models'

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/torch/serialization.py in find_class(self, mod_name, name)
1163 pass
1164 mod_name = load_module_mapping.get(mod_name, mod_name)
-> 1165 return super().find_class(mod_name, name)
1166
1167 # Load the data (which may in turn use persistent_load to load tensors)

ModuleNotFoundError: No module named 'models'


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

I found out that i can't load the best.pt model using the above code. Is there any adjustion I need to make? Thanks for reading.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@Melvin0419 Melvin0419 added the bug Something isn't working label Aug 13, 2023
@github-actions
Copy link

👋 Hello @Melvin0419, thank you for leaving an issue on Roboflow Notebooks.

🐞 Bug reports

If you are filing a bug report, please be as detailed as possible. This will help us more easily diagnose and resolve the problem you are facing. To learn more about contributing, check out our Contributing Guidelines.

If you require support with custom code that is not part of Roboflow Notebooks, please reach out on the Roboflow Forum or on the GitHub Discussions page associated with this repository.

💬 Get in touch

Do you have more questions about Roboflow that we haven't responded to yet? Feel free to ask them on the Roboflow Discuss forum. Our developer advocates and community team actively respond to questions there.

To ask questions about Notebooks, head over to the GitHub Discussions section of this repository.

@SkalskiP
Copy link
Collaborator

Hi, @Melvin0419 👋🏻! Did you train and load the model in the same notebook?

@SkalskiP SkalskiP self-assigned this Aug 13, 2023
@Melvin0419
Copy link
Author

Hi, @Melvin0419 👋🏻! Did you train and load the model in the same notebook?

Thanks for replying! No, I load the model in another notebook. I think that is the problem! But is there a way that i can load the model in another notebook? different from the notebook for training.

@SkalskiP
Copy link
Collaborator

You need to make sure that version of ultralytics is the same in training and loading notebook.

@Melvin0419
Copy link
Author

You need to make sure that version of ultralytics is the same in training and loading notebook.

Yes, both notebooks have the version ultralytics==8.0.20. And I have some updates! Previously, I chose the yolov8s as my model to train, and it cause an error when loading it into another notebook, But, if I trained the model using yolov8n, the trained model can be loaded into my loading notebook successfully, without showing the error I encountered when using yolov8s.

@SkalskiP
Copy link
Collaborator

Did you try to update the ultralytics version, and use something more recent?

@LinasKo
Copy link
Collaborator

LinasKo commented Oct 24, 2024

We've recently verified the required versions of yolov8 needed to train, validate, deploy and infer with the model. I'm closing this now. Do let us know if there's any further issues!

@LinasKo LinasKo closed this as completed Oct 24, 2024
@LinasKo LinasKo added the onsite The change was suggested during an initiative on a company onsite label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working onsite The change was suggested during an initiative on a company onsite
Projects
None yet
Development

No branches or pull requests

3 participants