You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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.
Search before asking
Question
When creating yolov5 pretrained models in my own project, there are two ways:
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)torch.load
andattempt_download
functions to load yolov5 released pretrained weights to the initialized yolov5, but the pretrained weight saved the whole model instead juststate_dict
. also will cause an error:No module named 'models' #22Additional
If releasing the
state_dict
weights would be greatThe text was updated successfully, but these errors were encountered: