I am trying to use Pytorch
and YOLOv5
to detect objects in multiple images and count them. My problem now is that if I have for example a frame rate of 15fps, the same objects can be recognized in the image, but they were only recognized for example a little bit in the front of the image (other coordinates) or the Objects have the same coordinates as before. Currently, only how many objects are detected in an image is counted. How can I exclude these objects or compare whether the objects have already been detected?
My Code so far:
counts = {"cars" : 0 , "trucks" : 0}
class_mappings = {2.0: "cars", 7.0: "trucks"}
def predict():
img = Image.open("test.jpeg")
result = model(img)
labels = dict(Counter(result[:, -1].tolist()))
for k, v in class_mappings.items():
counts[v] += labels.get(k, 0)
This Code above is extracting the labels of detected objects from the Tensor and count them in a counter variable.