Spaces:
Sleeping
Sleeping
Merge branch 'main' into python-processing-test
Browse files- services/multi_tracker.py +8 -2
- services/single_tracker.py +7 -1
- test/test_cv.py +2 -0
- test/test_inference.py +21 -0
- test/test_thread.py +24 -0
- test/test_ws.py +17 -0
services/multi_tracker.py
CHANGED
|
@@ -3,6 +3,7 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import logging
|
| 5 |
from ultralytics import YOLO
|
|
|
|
| 6 |
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
|
@@ -11,8 +12,13 @@ class MultiTracker:
|
|
| 11 |
logger.info("Initializing Multi Tracker (Group Centroid)")
|
| 12 |
|
| 13 |
# Determine paths
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
try:
|
| 18 |
self.model = YOLO(detector_model_path)
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import logging
|
| 5 |
from ultralytics import YOLO
|
| 6 |
+
from pathlib import Path
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
|
|
| 12 |
logger.info("Initializing Multi Tracker (Group Centroid)")
|
| 13 |
|
| 14 |
# Determine paths
|
| 15 |
+
|
| 16 |
+
# Get the directory containing the current script (server.py)
|
| 17 |
+
base_dir = Path(__file__).parent.parent
|
| 18 |
+
|
| 19 |
+
# Go up one level (to afs/), then into Model/
|
| 20 |
+
detector_model_path = base_dir.parent / "Model" / "yolov8n-face.pt"
|
| 21 |
+
print(detector_model_path,"de")
|
| 22 |
|
| 23 |
try:
|
| 24 |
self.model = YOLO(detector_model_path)
|
services/single_tracker.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import cv2
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
| 5 |
import logging
|
| 6 |
from ultralytics import YOLO
|
| 7 |
from deepface import DeepFace
|
|
|
|
| 8 |
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
|
@@ -13,7 +15,11 @@ class SingleTracker:
|
|
| 13 |
logger.info("Initializing Single Tracker (Face Priority)")
|
| 14 |
|
| 15 |
# Configuration matches face_model.py
|
| 16 |
-
self.base_dir = "/Users/adisankarlalan/Documents/GitHub/afs-fl/Model"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
self.reference_video_path = os.path.join(self.base_dir, 'my_scan.mp4')
|
| 18 |
self.model_name = "ArcFace"
|
| 19 |
self.detector_model_path = os.path.join(self.base_dir, "yolov8n-face.pt")
|
|
|
|
| 1 |
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
import cv2
|
| 4 |
import pickle
|
| 5 |
import numpy as np
|
| 6 |
import logging
|
| 7 |
from ultralytics import YOLO
|
| 8 |
from deepface import DeepFace
|
| 9 |
+
from pathlib import Path
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
| 15 |
logger.info("Initializing Single Tracker (Face Priority)")
|
| 16 |
|
| 17 |
# Configuration matches face_model.py
|
| 18 |
+
# self.base_dir = "/Users/adisankarlalan/Documents/GitHub/afs-fl/Model"
|
| 19 |
+
base_dir = Path(__file__).parent
|
| 20 |
+
self.base_dir = base_dir.parent.parent / "Model"
|
| 21 |
+
print(self.base_dir,"base")
|
| 22 |
+
|
| 23 |
self.reference_video_path = os.path.join(self.base_dir, 'my_scan.mp4')
|
| 24 |
self.model_name = "ArcFace"
|
| 25 |
self.detector_model_path = os.path.join(self.base_dir, "yolov8n-face.pt")
|
test/test_cv.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
print(cv2.__version__)
|
test/test_inference.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from services.single_tracker import SingleTracker
|
| 2 |
+
import cv2
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
tracker = SingleTracker()
|
| 6 |
+
cap = cv2.VideoCapture("Model/my_scan.mp4")
|
| 7 |
+
frames = 0
|
| 8 |
+
|
| 9 |
+
print("Main User embeddings:", bool(tracker.main_user_embeddings))
|
| 10 |
+
print("Len:", len(tracker.main_user_embeddings))
|
| 11 |
+
|
| 12 |
+
while cap.isOpened() and frames < 10:
|
| 13 |
+
ret, frame = cap.read()
|
| 14 |
+
if not ret: break
|
| 15 |
+
|
| 16 |
+
res = tracker.process_frame(frame)
|
| 17 |
+
if res["boxes"]:
|
| 18 |
+
print(f"Frame {frames} Boxes: {len(res['boxes'])}")
|
| 19 |
+
else:
|
| 20 |
+
print(f"Frame {frames}: No Output. Err: {res.get('error')}")
|
| 21 |
+
frames += 1
|
test/test_thread.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from services.single_tracker import SingleTracker
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 3 |
+
import cv2
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
async def test():
|
| 7 |
+
tracker = SingleTracker()
|
| 8 |
+
frame = cv2.imread("Model/Adi.jpg")
|
| 9 |
+
if frame is None:
|
| 10 |
+
print("Failed to load image")
|
| 11 |
+
return
|
| 12 |
+
|
| 13 |
+
executor = ThreadPoolExecutor(max_workers=4)
|
| 14 |
+
|
| 15 |
+
def run_inference():
|
| 16 |
+
res = tracker.process_frame(frame)
|
| 17 |
+
print("Tracker Output:", res)
|
| 18 |
+
|
| 19 |
+
print("Running in executor...")
|
| 20 |
+
await asyncio.get_event_loop().run_in_executor(executor, run_inference)
|
| 21 |
+
print("Done")
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
asyncio.run(test())
|
test/test_ws.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import websockets
|
| 3 |
+
import json
|
| 4 |
+
import cv2
|
| 5 |
+
|
| 6 |
+
async def test():
|
| 7 |
+
async with websockets.connect("ws://localhost:8000/ws") as ws:
|
| 8 |
+
cap = cv2.VideoCapture("Model/my_scan.mp4")
|
| 9 |
+
for i in range(15):
|
| 10 |
+
ret, frame = cap.read()
|
| 11 |
+
if not ret: break
|
| 12 |
+
ret, buffer = cv2.imencode('.jpg', frame)
|
| 13 |
+
await ws.send(buffer.tobytes())
|
| 14 |
+
res = await ws.recv()
|
| 15 |
+
print("Received:", res)
|
| 16 |
+
|
| 17 |
+
asyncio.run(test())
|