ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.75k stars 16.34k forks source link

RuntimeError: Cannot find callable custom_yolov5s in hubconf #5657

Closed I-am-vishalmaurya closed 2 years ago

I-am-vishalmaurya commented 2 years ago

RuntimeError: Cannot find callable custom_yolov5s in hubconf Screenshot 2021-11-15 200447

Originally posted by @I-am-vishalmaurya in https://github.com/ultralytics/yolov5/issues/1787#issuecomment-968971941

glenn-jocher commented 2 years ago

@I-am-vishalmaurya your command is incorrect so an error is the expected result. See PyTorch Hub tutorial to get started using YOLOv5 PyTorch Hub models:

YOLOv5 Tutorials

github-actions[bot] commented 2 years ago

👋 Hello @I-am-vishalmaurya, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

I-am-vishalmaurya commented 2 years ago

import torch

Model

model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom this is the code for loading the custom file right?

glenn-jocher commented 2 years ago

@I-am-vishalmaurya yes

I-am-vishalmaurya commented 2 years ago

Screenshot 2021-11-15 202903 After reading some documentation I have reached here.

I-am-vishalmaurya commented 2 years ago

and to clone the repository I have used this

clone YOLOv5 repository

!git clone https://github.com/ultralytics/yolov5 # clone repo %cd yolov5 !git reset --hard 886f1c03d839575afecb059accf74296fad395b6

I-am-vishalmaurya commented 2 years ago

Okay I have resolved this issue

sharmas1ddharth commented 2 years ago

Okay I have resolved this issue

How did you do this can you please share with me.

glenn-jocher commented 2 years ago

@sharmas1ddharth 👋 Hello! Thanks for asking about handling inference results. YOLOv5 🚀 PyTorch Hub models allow for simple model loading and inference in a pure python environment without using detect.py.

Simple Inference Example

This example loads a pretrained YOLOv5s model from PyTorch Hub as model and passes an image for inference. 'yolov5s' is the YOLOv5 'small' model. For details on all available models please see the README. Custom models can also be loaded, including custom trained PyTorch models and their exported variants, i.e. ONNX, TensorRT, TensorFlow, OpenVINO YOLOv5 models.

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # or yolov5m, yolov5l, yolov5x, etc.
# model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/best.pt')  # custom trained model

# Images
im = 'https://ultralytics.com/images/zidane.jpg'  # or file, Path, URL, PIL, OpenCV, numpy, list

# Inference
results = model(im)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.

results.xyxy[0]  # im predictions (tensor)
results.pandas().xyxy[0]  # im predictions (pandas)
#      xmin    ymin    xmax   ymax  confidence  class    name
# 0  749.50   43.50  1148.0  704.5    0.874023      0  person
# 2  114.75  195.75  1095.0  708.0    0.624512      0  person
# 3  986.00  304.00  1028.0  420.0    0.286865     27     tie

See YOLOv5 PyTorch Hub Tutorial for details.

Good luck 🍀 and let us know if you have any other questions!

sharmas1ddharth commented 2 years ago

@sharmas1ddharth 👋 Hello! Thanks for asking about handling inference results. YOLOv5 🚀 PyTorch Hub models allow for simple model loading and inference in a pure python environment without using detect.py.

Simple Inference Example

This example loads a pretrained YOLOv5s model from PyTorch Hub as model and passes an image for inference. 'yolov5s' is the YOLOv5 'small' model. For details on all available models please see the README. Custom models can also be loaded, including custom trained PyTorch models and their exported variants, i.e. ONNX, TensorRT, TensorFlow, OpenVINO YOLOv5 models.

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # or yolov5m, yolov5l, yolov5x, etc.
# model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/best.pt')  # custom trained model

# Images
im = 'https://ultralytics.com/images/zidane.jpg'  # or file, Path, URL, PIL, OpenCV, numpy, list

# Inference
results = model(im)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.

results.xyxy[0]  # im predictions (tensor)
results.pandas().xyxy[0]  # im predictions (pandas)
#      xmin    ymin    xmax   ymax  confidence  class    name
# 0  749.50   43.50  1148.0  704.5    0.874023      0  person
# 2  114.75  195.75  1095.0  708.0    0.624512      0  person
# 3  986.00  304.00  1028.0  420.0    0.286865     27     tie

See YOLOv5 PyTorch Hub Tutorial for details.

Good luck 🍀 and let us know if you have any other questions!

Thank you so much @glenn-jocher it's working

RAJ-DSML commented 5 months ago

@glenn-jocher 👋 Hi, I'm trying to perform this same thing as @I-am-vishalmaurya
Capture

but I got this error: raise RuntimeError(f'Cannot find callable {model} in hubconf') RuntimeError: Cannot find callable yolov3 in hubconf

Are these steps essential for the code to work?

$ git clone https://github.com/ultralytics/yolov5 $ cd yolov5 $ pip install -r requirements.txt

glenn-jocher commented 5 months ago

@RAJ-DSML hey there! It looks like you're trying to load a model that isn't directly available via the YOLOv5 PyTorch Hub. The error you're seeing is because yolov3 isn't a model option in the YOLOv5 repository. You'll want to use one of the available YOLOv5 models (yolov5s, yolov5m, yolov5l, yolov5x) or a custom model if you have trained one.

Here's a quick example of how to load a YOLOv5 model:

import torch

# Load YOLOv5s model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

And yes, cloning the repository and installing requirements are essential steps to ensure all dependencies are correctly set up for running YOLOv5 models. Make sure you have the latest version of the repository and have installed all necessary packages from requirements.txt. 😊