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

Custom object detection model example #1169

Closed TuanBao0711 closed 1 year ago

TuanBao0711 commented 1 year ago

Search before asking

Question

I am trying custom object detection model example with on base of you file but not work

tracker = DeepOCSORT( model_weights=Path('osnet_x0_25_msmt17.pt'), # which ReID model to use device='cuda:0', fp16=True, )

vid = cv2.VideoCapture(0) color = (0, 0, 255) # BGR thickness = 2 fontscale = 0.5

Model = YOLO('yolov8n.pt')

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

results = Model(im)

for result in results:
    for r in result.boxes.data.tolist():

        dets = np.array(results)

        tracks = tracker.update(dets, im) # --> (x, y, x, y, id, conf, cls, ind)

        xyxys = tracks[:, 0:4].astype('int') # float64 to int
        ids = tracks[:, 4].astype('int') # float64 to int
        confs = tracks[:, 5]
        clss = tracks[:, 6].astype('int') # float64 to int
        inds = tracks[:, 7].astype('int') # float64 to int

=> Traceback (most recent call last): File "C:\Users\TuanBao\yolo_tracking\main.py", line 35, in dets = np.array(results) ValueError: setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 32. How Can I fix that, thanks

TuanBao0711 commented 1 year ago

I tried many ways such as delete "dets = np.array(results)" or modify some codes, but not work :((

chenke225 commented 1 year ago
            results = Model(im)
            for result in results:
                boxes = result.boxes.xyxy
                confs = result.boxes.conf
                cls = result.boxes.cls
                # convert PyTorch to NumPy
                boxes_np = boxes.cpu().numpy()
                confs_np = confs.cpu().numpy()
                cls_np = cls.cpu().numpy()
                detection_results = np.column_stack((boxes_np, confs_np, cls_np))
            tracks = tracker.update(detection_results, im) # --> (x, y, x, y, id, conf, cls, ind)
mikel-brostrom commented 1 year ago

If you are using a Yolov8 custom model you can use track.py under the examples folder

TuanBao0711 commented 1 year ago
            results = Model(im)
            for result in results:
                boxes = result.boxes.xyxy
                confs = result.boxes.conf
                cls = result.boxes.cls
                # convert PyTorch to NumPy
                boxes_np = boxes.cpu().numpy()
                confs_np = confs.cpu().numpy()
                cls_np = cls.cpu().numpy()
                detection_results = np.column_stack((boxes_np, confs_np, cls_np))
            tracks = tracker.update(detection_results, im) # --> (x, y, x, y, id, conf, cls, ind)

thanks you, it work ^^

TuanBao0711 commented 1 year ago

If you are using a Yolov8 custom model you can use track.py under the examples folder

Sure, I could run the track.py file, however I would like to see your code and customize the code to use algorithms like bytrack, strongsort, or ocsort in my project. Is that allowed? :((

github-actions[bot] commented 1 year 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!