yehengchen / Object-Detection-and-Tracking

Object Detection and Multi-Object Tracking
MIT License
1.85k stars 753 forks source link

How to track more than once classes at the same? #54

Open MuhammadAsadJaved opened 4 years ago

MuhammadAsadJaved commented 4 years ago

Hi, 1- Is it possible to track more than one classes at the same time? for example my model is trained on 6 classes how i can track all classes at the same time?

I am able to track one class successfully but unable to track all. I have tried this method if predicted_class != 'person' and predicted_class != 'car': print(predicted_class) continue

but it's tracking same by default class.

2-If we track more than one classes , will it effect the speed?

MuhammadAsadJaved commented 4 years ago

I tried to make changes but it show the wrong names of classes. trackError

then i change coco_classes.txt names according to my model names but still printing wrong names. trackerro2

yehengchen commented 4 years ago

@MuhammadAsadJaved

  1. The original project only supports one class (Person) multi-object tracking.
  2. It is possible to track more than one class, and speed will be slower than one class tracking.

I will fix the printing bug as soon. Thank you for your interest.

MuhammadAsadJaved commented 4 years ago

OK. Thank you for your response.

On Sun, May 31, 2020 at 6:07 PM Bobby Chen notifications@github.com wrote:

@MuhammadAsadJaved https://github.com/MuhammadAsadJaved

  1. The original project only supports one class (Person) multi-object tracking.
  2. It is possible to track more than one class, and speed will be slower than one class tracking.

I will fix the printing bug as soon. Thank you for your interest.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yehengchen/Object-Detection-and-Tracking/issues/54#issuecomment-636449666, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4GR5FVJ4G2MMLKLHNXFNLRUIT65ANCNFSM4M37J6SA .

BoHuang-ecr commented 4 years ago

我也有同样的问题。 因为我看你在做NMS的时候,是不管物体类别,把所用检测结果放进去做的。 这样可以分别对各个类别的物体做NMS。

detector_results_pd = {'boxes': boxes, 'confidences': confidences, 'classIDs': classIDs}
detector_results_pd = pd.DataFrame(detector_results_pd)

    dets = []
    # filter each category for NMS
    for uni_id in np.unique(classIDs):
        uni_detector_results_pd = detector_results_pd[detector_results_pd.classIDs == uni_id]
        uni_boxes = uni_detector_results_pd['boxes'].tolist()
        uni_confidences = uni_detector_results_pd['confidences'].tolist()
        uni_classIDs = uni_detector_results_pd['classIDs'].tolist()

        # apply non-maxima suppression to suppress weak, overlapping bounding boxes
        idxs = cv2.dnn.NMSBoxes(uni_boxes, uni_confidences, args["confidence"], args["threshold"])

那同时检测各个类别的物体要怎么实现呢? 分别把物体送进sort 做update吗? 还有一个问题就是,现在做关联的时候,是没有考虑物体类别的。我们要需要在算法里实现,如果物体类别不同,就算IOU大于阙值,也不添加关联吗?

BoHuang-ecr commented 4 years ago

one more question: can we do Sort.update() if there is no detection in frames: I got this error:

t/sort.py", line 208, in update trk.update(dets[d,:][0]) IndexError: too many indices for array

yehengchen commented 4 years ago

@BoHuang-ecr 是的,首先多类别检测不是问题,问题在于跟踪器,检测后需要将不同类别分别送进不同跟踪器,若不考虑精度的话把不同类别先归类后送入同一个跟踪器是可以实现的。

BoHuang-ecr commented 4 years ago

@BoHuang-ecr 是的,首先多类别检测不是问题,问题在于跟踪器,检测后需要将不同类别分别送进不同跟踪器,若不考虑精度的话把不同类别先归类后送入同一个跟踪器是可以实现的。

感谢你的回答。

  1. 如果把不同类别的物体分别送入跟踪器,那每一个物体就要定义一个实例instance:
    
    tracker_person = Sort()
    tracker_car = Sort()
    ....
    ```这样的话,代码好像比较冗长。
  2. 我可能对代码理解还不够,如果把所有物体送进一个追踪器,为什么精度会下降呢?
  3. 还有一个问题困扰我想确认一下, tracks = tracker.update(dets) 这个tracks 返回的其实一堆bounding boxes,这个bounding boxes的位置,是当前时间点t的检测结果?还是检测结果与kalman filter预测值,通过卡尔曼增益的融合值?
BoHuang-ecr commented 4 years ago

@BoHuang-ecr 是的,首先多类别检测不是问题,问题在于跟踪器,检测后需要将不同类别分别送进不同跟踪器,若不考虑精度的话把不同类别先归类后送入同一个跟踪器是可以实现的。

这个问题解决了吗? 我试了一下,对于每一个类别的物体,单独用一个tracker来跟踪。 但不知道为什么,最后得到的结果和每次只跟踪一个物体结果不一样。 我有一个tracker_collections=[] 对于每个物体我有一个实例: tracker_collections = [tracker_person, tracker_car, ...] github主有时间做一下测试吗?

fanshu4869 commented 4 years ago

@MuhammadAsadJaved

  1. The original project only supports one class (Person) multi-object tracking.
  2. It is possible to track more than one class, and speed will be slower than one class tracking.

I will fix the printing bug as soon. Thank you for your interest.

请问如何同时跟踪人与车辆?要修改代码吗

MuhammadAsadJaved commented 4 years ago

@MuhammadAsadJaved

  1. The original project only supports one class (Person) multi-object tracking.
  2. It is possible to track more than one class, and speed will be slower than one class tracking.

I will fix the printing bug as soon. Thank you for your interest.

请问如何同时跟踪人与车辆?要修改代码吗

您已成功完成此代码,还是在寻求帮助?

fanshu4869 commented 4 years ago

@MuhammadAsadJaved

  1. The original project only supports one class (Person) multi-object tracking.
  2. It is possible to track more than one class, and speed will be slower than one class tracking.

I will fix the printing bug as soon. Thank you for your interest.

请问如何同时跟踪人与车辆?要修改代码吗

您已成功完成此代码,还是在寻求帮助?

I want to track person and car at the same time,how to do this?

MuhammadAsadJaved commented 4 years ago

@fanshu4869

1- Uncomment the line number 122 ~ 124 of yolo.py (https://github.com/yehengchen/Object-Detection-and-Tracking/blob/master/OneStage/yolo/deep_sort_yolov3/yolo.py#L122) and comment out line 126 ~128.

Run the project and try, if there is any problem then

2- Remove the --class argument (https://github.com/yehengchen/Object-Detection-and-Tracking/blob/master/OneStage/yolo/deep_sort_yolov3/main.py#L27) and try again.

sharmarochan commented 4 years ago

In main.py do following changes:

enumrate on tracker.tracks and fetch the corresponding ids from class_names.


  for count,track in enumerate(tracker.tracks):
            if not track.is_confirmed() or track.time_since_update > 1:
                continue
            #boxes.append([track[0], track[1], track[2], track[3]])
            # print(class_names[count])
            indexIDs.append(int(track.track_id))
            counter.append(int(track.track_id))
            bbox = track.to_tlbr()
            color = [int(c) for c in COLORS[indexIDs[i] % len(COLORS)]]

            cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])),(color), 3)
            cv2.putText(frame,str(track.track_id),(int(bbox[0]), int(bbox[1] -50)),0, 5e-3 * 150, (color),2)
            if len(class_names) > 0:
                try:
                    class_name = class_names[count]
                    cv2.putText(frame, str(class_names[count]),(int(bbox[0]), int(bbox[1] -20)),0, 5e-3 * 150, (color),2)
                except:
                    pass