Hi there, my name is Matheus.
- Ultralytics version: 8.3.93
- Python version: 3.10.12
I’m trying to do multiple object tracking (MOT) using a pretrained Ultralytics YOLO model and the ByteTrack algorithm on MOT20 Dataset. Furthermore, I also would like to evaluate the performance of this MOT task and predict the future positions of the tracked objects.
In a first approach, I used the model.track()
function as described on this official Ultralytics page. I was able to do the MOT task and write informations about the tracked objects into a MOT Challenge formatted file. However, I could not find a way to get the Kalman Filter predictions. How could I do this? Is it possible? See the code below:
import ultralytics
from ultralytics import YOLO
from pathlib import Path
print('Running Ultralytics YOLO tracking...')
results = model.track(source=source, # 'source' is a string containing the path for a directory of images
conf=confidence_threshold,
iou=iou_threshold,
imgsz=imgsz,
device=device,
stream_buffer=True,
stream=True,
persist=True,
classes=[1],
batch=32,
agnostic_nms=True,
tracker='bytetrack.yaml'
)
print('Writing MOT Challenge tracking file...')
with open('output.txt'), "w") as f:
for result in results:
result_to_device = result.to(device)
if result_to_device.boxes.id is not None:
boxes = result_to_device.boxes.xyxy
track_ids = result_to_device.boxes.id.int().tolist()
frame_id = int(Path(result_to_device.path).stem)
for box, track_id in zip(boxes, track_ids):
x1, y1, x2, y2 = box
bbox_left = x1
bbox_top = y1
width = x2 - x1
height = y2 - y1
f.write(f"{frame_id},{track_id},{bbox_left},{bbox_top},{width},{height},1,-1,-1,-1\n")
Then, aiming to access the Kalman Filter predictions used internally by the ByteTrack algorithm, I tried to use the BYTETracker class as described in detail on this official Ultralytics page. However, I encountered many problems (KeyError
, AttributeError
, and others) with this second approach and I wasn’t able to execute the code correctly. See the code below:
import ultralytics
from ultralytics import YOLO
from pathlib import Path
from types import SimpleNamespace
args = SimpleNamespace(track_buffer=30)
tracker = BYTETracker(args, frame_rate=25)
print('Running Ultralytics YOLO tracking...')
results = model(source=source, # 'source' is a string containing the path for a directory of images
conf=confidence_threshold,
iou=iou_threshold,
imgsz=imgsz,
device=device,
stream_buffer=True,
stream=True,
classes=[1],
batch=32,
agnostic_nms=True
)
for result in results:
result_to_device = result.to(device)
objects_in_this_frame = tracker.update(result_to_device.boxes)
if len(objects_in_this_frame) > 0 and objects_in_this_frame is not None:
tracked_objects.append(tracker.frame_id, objects_in_this_frame)
print('Writing MOT Challenge tracking file...')
with open(os.path.join(output, sequence_name+'.txt'), "w") as f:
for frame_id, track in tracked_objects:
min_x = track[0]
min_y = track[1]
max_x = track[2]
max_y = track[3]
track_id = track[4]
confidence = track[5]
class_label = track[6]
object_id = track[7]
width = max_x - min_x
height = max_y - min_y
f.write(f"{frame_id},{track_id},{min_x},{min_y},{width},{height},1,-1,-1,-1\n")
Could someone help me, please?
Thank you in advance.