How to increase the size of history_observations.
Closed this issue · 2 comments
Search before asking
- I have searched the Yolo Tracking issues and found no similar bug report.
Question
How to increase the size of history_observations. i have tried updating STrack.history_observations = deque([],maxlen = 100) changes are not reflecting in output. what to do?
from boxmot import BoTSORT
from boxmot.trackers.botsort.bot_sort import STrack
from collections import deque
Initialize the tracker
STrack.history_observations = deque([],maxlen=100)
tracker = BoTSORT(
model_weights = Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
device = 'cuda:0',
fp16 = False,
)
Initialize YOLO model
yolo_model = YOLOv10('/content/weights/yolov10b.pt')
Open the input video
input_video_path = '/content/5330828-hd_1920_1080_30fps.mp4'
vid = cv2.VideoCapture(input_video_path)
if not vid.isOpened():
print("Error: Could not open input video.")
exit()
Define the output video path
output_video_path = '/content/BoTSORT_output_tracking_video.mp4'
Create the video writer
out = create_video_writer(vid, output_video_path)
frame_count = 500
trail_path = {}
while frame_count:
frame_count -= 1
ret, im = vid.read()
if not ret:
break
try:
# Run the YOLO model on the frame
results = yolo_model(im)
# Convert the detections to the required format: N X (x, y, x, y, conf, cls)
dets = []
for result in results:
for detection in result.boxes.data.cpu().numpy():
x1, y1, x2, y2, conf, cls = detection
if int(cls)==0:
dets.append([x1, y1, x2, y2, conf, int(cls)])
dets = np.array(dets)
# Update tracker with detections
tracker.update(dets, im)
tracker.plot_results(im, show_trajectories = True)
# trail_hist
for a in tracker.active_tracks:
if a.cls == 0:
if len(a.history_observations)>2:
trail_path[a.id] = a.history_observations
# Write the frame to the output video
out.write(im)
except Exception as e:
print(f"An error occurred: {e}")
break
vid.release()
out.release()
cv2.destroyAllWindows()
print(f"Tracking video saved to {output_video_path}")
Isn't that MAX_AGE?
You can now use MAX_AGE
. I implemented dynamic deques based on this value 🚀 . Available in the new release!