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

Inconvenient to integrate yolov5 to my project #11671

Closed
1 task done
bot66 opened this issue Jun 7, 2023 · 3 comments
Closed
1 task done

Inconvenient to integrate yolov5 to my project #11671

bot66 opened this issue Jun 7, 2023 · 3 comments
Labels
question Further information is requested

Comments

@bot66
Copy link

bot66 commented Jun 7, 2023

Search before asking

Question

When creating yolov5 pretrained models in my own project, there are two ways:

  1. use torch.hub.load to create pretrained models, but this method will create package conflicts. see this issue:ModuleNotFoundError: No module named 'utils.datasets'; 'utils' is not a package #6048 (comment)
  2. copy the yolov5 model class code to my project and initialize an instance, then use the torch.load and attempt_download functions to load yolov5 released pretrained weights to the initialized yolov5, but the pretrained weight saved the whole model instead just state_dict. also will cause an error:No module named 'models' #22

Additional

If releasing the state_dict weights would be great

@bot66 bot66 added the question Further information is requested label Jun 7, 2023
@lucastack
Copy link

Hi @bot66!

Both problems are related to the absence of modules needed. Basically, you need to know how to build your model by importing the corresponding class.

Do the following in your project root folder, let's say its called project/

  • git clone https://github.com/ultralytics/yolov5.git. Now you should have project/yolov5.
  • Install requirements.
  • import classes changing the root folder. Here's an example test.py file located in project/test.py
import sys        
from pathlib import Path
import os
FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] / "yolov5"  # your new YOLOv5 root directory
if str(ROOT) not in sys.path:
    sys.path.append(str(ROOT))  # add ROOT to PATH
ROOT = Path(os.path.relpath(ROOT, Path.cwd()))  # relative

from yolov5.models.common import DetectMultiBackend

model = DetectMultiBackend() # here you pass your arguments

Hope it helps

Regards!

@glenn-jocher
Copy link
Member

Hello @lucastack!

Thank you for reaching out to us. We understand that integrating YOLOv5 to your project can be inconvenient due to some package conflicts and errors.

We suggest that you import the necessary classes after building your model by changing the root folder. You can do this by cloning the YOLOv5 repository, installing the requirements, and updating the path to include the new YOLOv5 root directory. Then import the desired classes as shown in the example test.py file provided in our documentation.

We hope this helps. Please don't hesitate to reach out if you have further queries.

Best regards!

@bot66
Copy link
Author

bot66 commented Jun 7, 2023

@lucastack @glenn-jocher Thank you everyone, I will try.

@bot66 bot66 closed this as completed Jun 7, 2023
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