Skip to content

Exclude classes #131

Answered by SkalskiP
st43r asked this question in Q&A
May 24, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi, @st43r 👋🏻! You can use supervision to do that. UNWANTED_CLASSES is the list of class ids that you want to filter out.

import cv2
import torch
import numpy as np
import supervision as sv
from super_gradients.training import models

DEVICE = 'cuda' if torch.cuda.is_available() else "cpu"
MODEL_ARCH = 'yolo_nas_l'
UNWANTED_CLASSES = [1, 4, 8]

model = models.get(MODEL_ARCH, pretrained_weights="coco").to(DEVICE)

image = cv2.imread(SOURCE_IMAGE_PATH)

result = list(model.predict(image, conf=0.35))[0]
detections = sv.Detections.from_yolo_nas(result)
selection_mask = ~np.isin(detections.class_id, UNWANTED_CLASSES)
detections = detections[selection_mask]

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@st43r
Comment options

Answer selected by SkalskiP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants