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

Remove models and utils folders for detection #1155

Closed
fjsaezm opened this issue Oct 16, 2020 · 8 comments
Closed

Remove models and utils folders for detection #1155

fjsaezm opened this issue Oct 16, 2020 · 8 comments
Labels
question Further information is requested

Comments

@fjsaezm
Copy link

fjsaezm commented Oct 16, 2020

Hi there!

I have trained the model in my own dataset and the results are great! I'm quite happy with it!

Now I want to use the trained model in an app and, in order to save some space, I'd like to have only 1 scripts for it that does the job, and obviously the weights file.

However, if I delete the folders models and utils in order to do inference, I get errors trying to load the weights file with torch.

result = unpickler.load()
...
from utils.general import check_anchor_order, make_divisible, check_file
ModuleNotFoundError: No module named 'utils.general'

If I dont delete these folders, the model works perfectly fine.

Is there any way to save the weights or change any configuration so that I don't need to have these 2 folders where I want to make the inference?

Thank you!

@fjsaezm fjsaezm added the question Further information is requested label Oct 16, 2020
@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 16, 2020

@fjsaezm see export tutorial https://docs.ultralytics.com/yolov5 for standalone YOLOv5 inference.

@glenn-jocher
Copy link
Member

BTW, for pytorch inference, the module dependencies are required to be available in your system path. The folders do not need to be at a high level, but they do need to be present, just like you can not run torch commands without importing torch.

@fjsaezm
Copy link
Author

fjsaezm commented Oct 19, 2020

Ok, so I've assumed that these folders will have to be in my system.

So now, would It be possible to create a folder like "Resources" in which I will have

  • The two folders needed
  • The detect script

And call the detect function from outside this folder?

My current Folder distribution is:

  • Root
    • Folder1
      • Resources: the folder that contains what I mentioned before

Is it possible to call the detect function from a script located in "Root"? I'm trying to do it and I'm getting the exact same error that I mentioned above...

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 19, 2020

@fjsaezm you probably want to load YOLOv5 from torch hub, where pytorch automatically downloads the yolov5 repo and adds it to your sys path. You can run inference directly on a PIL image or cv2 image and everything is handled automatically.

The torch hub tutorial has recently been updated here: https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading

@fjsaezm
Copy link
Author

fjsaezm commented Oct 20, 2020

Thank you for your answer!

However, I think it doesnt solve my problem, since that loads a pretrained YOLOv5 and I'd like to use my own weights.

Is there any way to load my weights? Do I have to train it again after loading YOLOv5 from torch hub?

Thank you again!

@glenn-jocher
Copy link
Member

@fjsaezm you'd need to swap your model params in. There are many pytorch examples on the web for this.

@fjsaezm fjsaezm closed this as completed Oct 22, 2020
@MuhammadShifa
Copy link

Hello @fjsaezm !
Have you solved this issue, I am also facing the same issue. I want to combine pose estimation of yolov7 with custom yolov5 for object detection but facing model import issue as both have models folder in their repo. Can you help me please @glenn-jocher

@glenn-jocher
Copy link
Member

Hey @MuhammadShifa! We currently don't support YOLOv7 as it's not an official release. Regarding combining pose estimation with YOLOv5, you might want to consider creating a custom model that combines both functionalities. Feel free to check out the Ultralytics YOLOv5 documentation for guidance: https://docs.ultralytics.com/yolov5/ 🚀

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

No branches or pull requests

3 participants