Skip to content

How do make edits to detect only person #436

Answered by zhiqwang
uzumakinaruto19 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @vipinap123 ,

If you don't want to retrain a human-only model, then you need to do a filter on the current output. In the coco dataset, the human label is 0, so you need to add a filter here and only output it if label==0. Such as belows:

import torch
from yolort.models import yolov5s

score_thresh = 0.55
img_h, img_w = 640, 640

model = yolov5s(pretrained=True, score_thresh=score_thresh, size=(img_h, img_w))
model = model.eval()
# Perform inference on an image tensor
out = model.predict("bus.jpg")[0]

keep = torch.where(out["labels"] == 0)
out_person = {}
for k, v in out.items():
    out_person[k] = v[keep]

And then the out_person is all you need here.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zhiqwang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants