vukasin-stanojevic / BoostTrack

MIT License
65 stars 5 forks source link

How to run this model on a single video? #1

Closed hopeSerendipity closed 2 months ago

hopeSerendipity commented 4 months ago

I want to make a test of the sota model on my video,could you help me with this because you didn't mention it on the readme.

changpowei commented 2 months ago

Same question as @hopeSerendipity! How to test the algorithm on my own video? Thx

vukasin-stanojevic commented 2 months ago

Hello, Check the lines 159-171 from main.py: ` pred = det(img, tag) start_time = time.time()

if pred is None: continue

targets = tracker.update(pred, img, np_img[0].numpy(), tag) tlwhs, ids, confs = utils.filter_targets(targets, args.aspect_ratio_thresh, args.min_box_area)

total_time += time.time() - start_time frame_count += 1

results[video_name].append((frame_id, tlwhs, ids, confs)) ` The lines 159, 165, and 166 are particularly important. To run on your video you would have to pass the frame (img variable) of your video in line 159 and after the line 166 add some visualisation (in my tests I used cv2 library, cv2.rectangle(...)). All the data you need is in tlshs and ids.

In case you want to test the post-processed results you could just run the algorithm once and then use generated results from _post_gbi folder to draw the bounding boxes, IDs, etc...

Generated txt files are formatted by instructions from the MOT Challenge website. <frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z>

I Hope this helps!

@changpowei @hopeSerendipity

alaap001 commented 2 months ago

Thanks a lot @vukasin-stanojevic , it would be great if we get an inference script that we can run out of the box on any video.

I modified the script as you pointed out and used it with yolov10.

but I got this error:

0: 736x1280 2 persons, 79.9ms
Speed: 5.5ms preprocess, 79.9ms inference, 86.0ms postprocess per image at shape (1, 3, 736, 1280)
(2, 6)
4998

0: 736x1280 3 persons, 42.3ms
Speed: 5.3ms preprocess, 42.3ms inference, 0.7ms postprocess per image at shape (1, 3, 736, 1280)
(3, 6)
An error occurred: ERROR: The number of cached embeddings don't match the number of detections.
Was the detector model changed? Delete cache if so.
Traceback (most recent call last):
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/boosttracktest.py", line 182, in <module>
    targets = tracker.update(filtered_dets, im, im, '')
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/tracker/boost_track.py", line 227, in update
    dets_embs = self.embedder.compute_embedding(img_numpy, dets[:, :4], tag)
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/tracker/embedding.py", line 108, in compute_embedding
    raise RuntimeError(
RuntimeError: ERROR: The number of cached embeddings don't match the number of detections.
Was the detector model changed? Delete cache if so.
None
Tracking video saved to OutsideWarehouse3_D20240611_T1048245_AXIS_out.mp4

For reference this is the code snippet:

dets = np.array(dets)

        filtered_dets = filter_detections(dets, threshold=0.97)
        print(filtered_dets.shape)

        if len(dets.shape)>1:
            # tracks = tracker.update(filtered_dets, im)
            # tracks, kf_predictions = tracker.update(filtered_dets, im)
            targets = tracker.update(filtered_dets, im, im, '')
            tlwhs, ids, confs = utils.filter_targets(targets, 5,10)

your help would be much appreciated.

So main issue is that detector now detected 3 objects, previously there were 2 so emb couldn't be compared. This is strange as new objects will come always.

Also even if objs number was same we get:

Traceback (most recent call last):
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/boosttracktest.py", line 187, in <module>
    targets = tracker.update(filtered_dets, im, im, '')
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/tracker/boost_track.py", line 235, in update
    matched, unmatched_dets, unmatched_trks = associate(
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/tracker/assoc.py", line 160, in associate
    return linear_assignment(detections, trackers, iou_matrix, cost_matrix, iou_threshold, emb_cost)
  File "/media/alaap/PF_bkp1/videos/tracking testing/BoostTrack/tracker/assoc.py", line 85, in linear_assignment
    if d not in matched_indices[:, 0]:
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
vukasin-stanojevic commented 2 months ago

@alaap001, there should be no problem with the detector. You probably "confused" it somehow by specifying same paths for different videos. Anyway, if there is any problem with the detector cache, you could simply clear the cache folder and comment the lines 176-177 from main.py to forbid further caching of the results.

alaap001 commented 2 months ago

I got it to work, I by mistake sent numpy image instead of tensor.

mrigankEvig commented 2 months ago

I got it to work, I by mistake sent numpy image instead of tensor.

hi can you please share how you got it to work on yolov10...