diff scripts/dltrack.py @ 1219:8a626226793e

update where optimization uses either nomad-parameter file depending on optimizing 1 or 2 steps
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 19 Jun 2023 17:09:56 -0400
parents
children 5a207c838323
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/dltrack.py	Mon Jun 19 17:09:56 2023 -0400
@@ -0,0 +1,27 @@
+#! /usr/bin/env python3
+# from https://docs.ultralytics.com/modes/track/
+import sys, argparse
+
+from trafficintelligence.moving import cocoUserTypeNames
+from ultralytics import YOLO
+
+parser = argparse.ArgumentParser(description='The program tracks objects following the ultralytics yolo executable.')#, epilog = 'Either the configuration filename or the other parameters (at least video and database filenames) need to be provided.')
+parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)')
+# detect model
+# tracker model
+parser.add_argument('--display', dest = 'display', help = 'show the results (careful with long videos, risk of running out of memory)', action = 'store_true')
+args = parser.parse_args()
+
+# Load a model
+model = YOLO('/home/nicolas/Research/Data/classification-models/yolov8x.pt ') # seg yolov8x-seg.pt
+# seg could be used on cropped image... if can be loaded and kept in memory
+# model = YOLO('/home/nicolas/Research/Data/classification-models/yolo_nas_l.pt ') # AttributeError: 'YoloNAS_L' object has no attribute 'get'
+
+# Track with the model
+if args.display:
+    results = model.track(source=args.videoFilename, tracker="/home/nicolas/Research/Data/classification-models/bytetrack.yaml", classes=list(cocoUserTypeNames.keys()), show=True) # , save_txt=True 
+else:
+    results = model.track(source=args.videoFilename, tracker="/home/nicolas/Research/Data/classification-models/bytetrack.yaml", classes=list(cocoUserTypeNames.keys()), stream=True)
+    for result in results:
+        for box in result.boxes:
+            print(box.xyxy)