I am going to detect and track the objects in a video file using YOLOv8 and DeepSORT respectively by importing their packages. In the first iteration of the frame reading, everything is normal but, in the second iteration, Jupyter notebook kernel is dead at tracks = tracker.update_tracks(results, frame=frame)
line. What can be the reason?
Code is the following:
import torch
import cv2
import ultralytics
from deep_sort_realtime.deepsort_tracker import DeepSort
model = ultralytics.YOLO("yolov8m.pt")
tracker = DeepSort(max_age=50)
CONFIDENCE_THRESHOLD = 0.8
cap = cv2.VideoCapture('video.mp4')
while True:
ret, frame = cap.read()
if not ret:
break
detections = model(frame)[0]
results = []
for data in detection.boxes.data.tolist():
confidence = data[4]
if float(confidence) < CONFIDENCE_THRESHOLD:
continue
xmin, ymin, xmax, ymax = int(data[0]), int(data[1]), int(data[2]), int(data[3])
class_id = int(data[5])
results.append([[xmin, ymin, xmax - xmin, ymax - ymin], confidence, class_id])
tracks =tracker.update_tracks(results, frame=frame)
for track in tracks:
if not track.is_confirmed():
continue
bbox = track.to_tlbr()
track_id = track.track_id
class_name = track.get_class()
cv2.imshow("Frame", frame)
if cv2.waitKey(1) == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
The solution was upgrading the numpy
and scipy
to the latest version since, I was using the latest version of Jupyter Notebook.