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

Yolov5 : Where is the ModelClass ???? #6135

Closed
1 task done
Lee-jaehyun opened this issue Dec 30, 2021 · 2 comments
Closed
1 task done

Yolov5 : Where is the ModelClass ???? #6135

Lee-jaehyun opened this issue Dec 30, 2021 · 2 comments
Labels
question Further information is requested Stale

Comments

@Lee-jaehyun
Copy link

Search before asking

Question

Hello, Everyone!!

I have a question, so I'm writing.

In general, there are two cases when loading a trained model in PyTorch.

  1. model = torch.hub.load(~~~, 'custom', path='bset.pt' , source = 'local')
    torch.save(model, "./aaa.pt")

    yolo_model = torch.load("aaa.pt") ==> This method saves and loads the entire model.

  2. model = torch.hub.load(~~~, 'custom', path='bset.pt' , source = 'local')
    torch.save(model.state_dict(), "./aaa.pt")

In the above case, we know that the learned weights are loaded after defining the model class.

In general, PyTorch uses it like this:
model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))

How to load state_dict in YOLO???

I wonder where the model class definition is.

I'm curious about loading the model with the load_state_dict method.

Additional

Help me, plz

@Lee-jaehyun Lee-jaehyun added the question Further information is requested label Dec 30, 2021
@iumyx2612
Copy link
Contributor

iumyx2612 commented Dec 30, 2021

Search before asking

Question

Hello, Everyone!!

I have a question, so I'm writing.

In general, there are two cases when loading a trained model in PyTorch.

  1. model = torch.hub.load(~~~, 'custom', path='bset.pt' , source = 'local')
    torch.save(model, "./aaa.pt")
    yolo_model = torch.load("aaa.pt") ==> This method saves and loads the entire model.
  2. model = torch.hub.load(~~~, 'custom', path='bset.pt' , source = 'local')
    torch.save(model.state_dict(), "./aaa.pt")

In the above case, we know that the learned weights are loaded after defining the model class.

In general, PyTorch uses it like this: model = TheModelClass(*args, **kwargs) model.load_state_dict(torch.load(PATH))

How to load state_dict in YOLO???

I wonder where the model class definition is.

I'm curious about loading the model with the load_state_dict method.

Additional

Help me, plz

YOLOv5 save the whole model, not just the weights and biases, see here
if you want to load the state_dict, check here
the reason for saving the model like that can be found here
if you want to know about the Model and how it's construct, check models/yolo.py, line 309

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2022

👋 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:

Access additional Ultralytics ⚡ resources:

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 ⭐!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants