mikel-brostrom / boxmot

BoxMOT: pluggable SOTA tracking modules for segmentation, object detection and pose estimation models
GNU Affero General Public License v3.0
6.79k stars 1.72k forks source link

(OCSORT, DeepOCSORT) shape specs not match doc function #1568

Closed boschmonart closed 3 months ago

boschmonart commented 3 months ago

Search before asking

Yolo Tracking Component

Tracking

Bug

hi, i'm using OCSORT. Doc for update says

          dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],...]

but then, checks

        assert dets.shape[1] == 6, "Unsupported 'dets' 2nd dimension lenght, valid lenghts is 6"

why? is the docString wrong, and the class should be passed? [x1,y1,x2,y2,score, class] or the shape check should be shape[1] == 6

thanks

Environment

yolov8

Minimal Reproducible Example

det = [[1,2,3,4,0.5]]
det = np.array(det)
# det.shape == 1, 5
 tracker = OCSORT(
        asso_func="centroid",
        # iou_threshold=0.3  # use this to set the centroid threshold that match your use-case best
    )
tracker.update(det, frame)
mikel-brostrom commented 3 months ago

The example:

import cv2
import numpy as np
from pathlib import Path

from boxmot import DeepOCSORT

tracker = DeepOCSORT(
    model_weights=Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
    device='mps',
    fp16=False,
)

vid = cv2.VideoCapture(0)

while True:
    ret, im = vid.read()

    # substitute by your object detector, output has to be N X (x, y, x, y, conf, cls)
    dets = np.array([[144, 212, 578, 480, 0.82, 0]])

    # Check if there are any detections
    if dets.size > 0:
        tracker.update(dets, im) # --> M X (x, y, x, y, id, conf, cls, ind)
    # If no detections, make prediction ahead
    else:   
        dets = np.empty((0, 6))  # empty N X (x, y, x, y, conf, cls)
        tracker.update(dets, im) # --> M X (x, y, x, y, id, conf, cls, ind)
    tracker.plot_results(im, show_trajectories=True)

    # break on pressing q or space
    cv2.imshow('BoxMOT detection', im)     
    key = cv2.waitKey(1) & 0xFF
    if key == ord(' ') or key == ord('q'):
        break

vid.release()
cv2.destroyAllWindows()

works fine for me 😄 . det = [[1,2,3,4,0.5]] should be det = [[1,2,3,4,0,5]]?

iuiu34 commented 3 months ago

cool, yepp, that works.

thanks for the quick response

Then my issue would be with doc string of the func for both DeepOCSort & OCSORT

current

        """
        Params:
          dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],...]
        Requires: this method must be called once for each frame even with empty detections
        (use np.empty((0, 5)) for frames without detections).
        Returns the a similar array, where the last column is the object ID.
        NOTE: The number of objects returned may differ from the number of detections provided.
        """

desired

        """
        Params:
          dets - a numpy array of detections in the format [[x1,y1,x2,y2,score,class],[x1,y1,x2,y2,score,class],...]
        Requires: this method must be called once for each frame even with empty detections
        (use np.empty((0, 6)) for frames without detections).
        Returns the a similar array, where the last column is the object ID.
        NOTE: The number of objects returned may differ from the number of detections provided.
        """
mikel-brostrom commented 3 months ago

Will move out all the shape checks to the base class and correct this typo

github-actions[bot] commented 3 months ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!