Coder Social home page Coder Social logo

Inference on my pretrained model about yolov5 HOT 15 CLOSED

unrue avatar unrue commented on September 8, 2024
Inference on my pretrained model

from yolov5.

Comments (15)

glenn-jocher avatar glenn-jocher commented on September 8, 2024 2

@unrue you're welcome! Your solution looks good. The force_reload = True is usually not necessary but doesn't hurt. Feel free to remove it if your model loads successfully without it. If you have any more questions, feel free to ask.

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 8, 2024

@unrue this issue is due to using the torch.load method, that returns a dictionary rather than a model instance. Instead, load the model using model = torch.hub.load('ultralytics/yolov5', 'custom', path_or_model='weights/best.pt') for inference. This loads the best.pt and sets the model to eval mode. Further details can be found at https://docs.ultralytics.com/yolov5/.

from yolov5.

unrue avatar unrue commented on September 8, 2024

Thansk Glenn. I tried as suggested, but I get:

urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable>

I'm on a HPC machine, and compute nodes are not connected to internet. Why Yolo try to download something? The saved model is local. What I have to download? Thanks.

from yolov5.

enislalmi avatar enislalmi commented on September 8, 2024

@unrue If you are not specifying the data that you want to train, it probably is using as default coco datasets and it is trying to download it. Try specifying you data by using --data keyword.

from yolov5.

unrue avatar unrue commented on September 8, 2024

Ok, I solved:

model =torch.hub.load(os.getcwd(), 'custom',  source='local', path ='mymodel/best.pt', force_reload = True)
model.eval()

Not sure if force_reload is necessary, but it works.

Thanks.

from yolov5.

goldwater668 avatar goldwater668 commented on September 8, 2024

@glenn-jocher @unrue
FileNotFoundError: [Errno 2] No such file or directory: 'ultralytics/web/hubconf.py'
I reported the above error according to your configuration.

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 8, 2024

@goldwater668 Apologies for the confusion. The error you're encountering seems to be related to a file not being found in the specified location. Are you using the latest version of YOLOv5? It's possible that the file hubconf.py may not be present in the directory you specified. Can you confirm the version you are using?

from yolov5.

goldwater668 avatar goldwater668 commented on September 8, 2024

@glenn-jocher
If I don’t want to import so many files py and just want to use torch.load for model inference, what should I do?

from yolov5.

enislalmi avatar enislalmi commented on September 8, 2024

@goldwater668 You will need to clone the github repository, if you want to use yolov5 at its full features. Check the documentation below https://docs.ultralytics.com/yolov5/tutorials/train_custom_data/

from yolov5.

goldwater668 avatar goldwater668 commented on September 8, 2024

@glenn-jocher
I found the hubconf.py file and updated the code to the latest version. The following error was reported:
repo
File "/home/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/hub.py", line 566, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
File "/home/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/hub.py", line 595, in _load_local
model = entry(*args, **kwargs)
File "/media/EC3C5BDA3C5B9E80/win10/hrg/yolov5/runs/train/exp10/hubconf.py", line 83, in custom
return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
File "/media/EC3C5BDA3C5B9E80/win10/hrg/yolov5/runs/train/exp10/hubconf.py", line 33, in _create
from models.common import AutoShape, DetectMultiBackend
ModuleNotFoundError: No module named 'models'

from yolov5.

goldwater668 avatar goldwater668 commented on September 8, 2024

@glenn-jocher
Python>=3.7.0环境中安装requirements.txt,包括PyTorch>=1.7模型数据集会从最新的 YOLOv5版本自动下载。

pip install -r https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt
💡专业提示:不需要克隆https://github.com/ultralytics/yolov5 😃

If yolov5 is not cloned, an error will be reported. If it is cloned, an error will be reported.

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 8, 2024

@goldwater668! 根据你的反馈,我会为你提供一些建议。

首先,请确保安装的是最新版的 YOLOv5。如果你使用了 torch.hub.load,代替了 torch.load,那么确保你在调用时已经按照正确的方式设置了模型的路径。在最新版本中,你也许需要在调用模型之前对其进行解析。此外,可能需要对模型进行自动调整以适应预测输入。你可以查看我们的官方文档,里面提供了详细的使用指南和示例代码。

希望这些信息对你有所帮助。如果你需要更多帮助,欢迎回复我,我会尽力协助你解决问题。

from yolov5.

goldwater668 avatar goldwater668 commented on September 8, 2024

@glenn-jocher
Yes, the latest yolov5 version, the following is the version information:

Name: ultralytics
Version: 8.0.199
Summary: Ultralytics YOLOv8 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
Home-page: https://github.com/ultralytics/ultralytics
Author: Ultralytics
Author-email: [email protected]
License: AGPL-3.0
Location: /home/hjq/anaconda3/envs/yolov5/lib/python3.8/site-packages
Requires: matplotlib, numpy, opencv-python, pandas, pillow, psutil, py-cpuinfo, pyyaml, requests, scipy, seaborn, thop, torch, torchvision, tqdm
Required-by:

代码如下:
`import torch

model = torch.hub.load('./runs/train/exp10', 'custom', path='./runs/train/exp10/weights/best.pt', source='local') `

If yolov5 is not cloned, an error will be reported. If it is cloned, an error will be reported.

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 8, 2024

@goldwater668 Thanks for providing the version information and the code snippet. It seems your code is attempting to load the custom model from the local directory. If the model is not cloned, you may encounter errors related to module imports. If it is cloned, you may still face issues with the relative paths and module imports.

I suggest adhering to the recommended installation process and using the absolute path to load the model.

import torch

model = torch.hub.load('ultralytics/yolov5', 'custom', path='absolute/path/to/your/model/best.pt', source='local')

Make sure to replace 'absolute/path/to/your/model/best.pt' with the actual absolute path to your model file.

If you continue to experience issues, please let me know and provide the specific error messages for further assistance.

from yolov5.

github-actions avatar github-actions commented on September 8, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

from yolov5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.