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

Specify the class for detection on pre-trained YOLOv8 #982

Closed
1 task done
turinaf opened this issue Feb 15, 2023 · 7 comments
Closed
1 task done

Specify the class for detection on pre-trained YOLOv8 #982

turinaf opened this issue Feb 15, 2023 · 7 comments
Labels
question Further information is requested

Comments

@turinaf
Copy link

turinaf commented Feb 15, 2023

Search before asking

Question

I wanted to use the yolov8 pre-trained model to detect only certain classes, not all the classes on which the model is trained.
I know we can do this on yolov5 to specify the class. I couldn't do the same with yolov8.

model = torch.hub.load("ultralytics/yolov5", 'custom', path='yolov5s.pt')
model.classes = [0]  # Only person
model.conf = 0.5

Is there something similar for YOLOv8?

Additional

No response

@turinaf turinaf added the question Further information is requested label Feb 15, 2023
@Laughing-q
Copy link
Member

@turinaf

from ultralytics import YOLO
model = YOLO(f"yolov8n.pt")
model.predict(source="ultralytics/assets/", save=True, classes=[0,1])

@turinaf
Copy link
Author

turinaf commented Feb 16, 2023

@Laughing-q hi from Chengdu,
Thank you!

@turinaf turinaf closed this as completed Feb 16, 2023
@kosongdansatu
Copy link

@turinaf

from ultralytics import YOLO
model = YOLO(f"yolov8n.pt")
model.predict(source="ultralytics/assets/", save=True, classes=[0,1])

where this code replace on yolov8?

@kosongdansatu
Copy link

I'm Running this code from vscode how to select Specify class?

@glenn-jocher
Copy link
Member

@kosongdansatu to select specific classes while using YOLOv8 in Visual Studio Code, you can add the "classes" parameter to the predict function, and set it to be a list of integers representing the classes you want to detect. For example, if you only want to detect objects from classes 0 and 1, you can set classes=[0, 1].

Here's an example code snippet:

from ultralytics import YOLO

model = YOLO("yolov8.pt")

# Detect objects from classes 0 and 1 only
classes = [0, 1]

# Set the confidence threshold
conf_thresh = 0.5

# Set the source of the input data (e.g., image file, video file, or folder containing images)
source = "path/to/your/data"

# Call the predict function with the specified parameters
results = model.predict(source=source, save=True, classes=classes, conf=conf_thresh)

Please note that you need to replace "path/to/your/data" with the actual path to your data. Additionally, you can adjust the value of the "conf_thresh" parameter to modify the sensitivity of the model.

@kosongdansatu
Copy link

thank you soo much glenn

@glenn-jocher
Copy link
Member

@kosongdansatu you're welcome! If you have any further questions or concerns about YOLOv8, don't hesitate to ask. We're always here to help.

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

4 participants