Spaces:
Sleeping
Sleeping
fix: fixing bugs, and make sure mlflow works fine
Browse files- api/routers/__pycache__/camera_stream.cpython-311.pyc +0 -0
- api/routers/__pycache__/dashboard_stream.cpython-311.pyc +0 -0
- api/routers/__pycache__/metrics.cpython-311.pyc +0 -0
- api/routers/camera_stream.py +16 -10
- contracts/__pycache__/camera_metadata.cpython-311.pyc +0 -0
- main.py +4 -3
- utils/__pycache__/experiment.cpython-311.pyc +0 -0
api/routers/__pycache__/camera_stream.cpython-311.pyc
CHANGED
|
Binary files a/api/routers/__pycache__/camera_stream.cpython-311.pyc and b/api/routers/__pycache__/camera_stream.cpython-311.pyc differ
|
|
|
api/routers/__pycache__/dashboard_stream.cpython-311.pyc
CHANGED
|
Binary files a/api/routers/__pycache__/dashboard_stream.cpython-311.pyc and b/api/routers/__pycache__/dashboard_stream.cpython-311.pyc differ
|
|
|
api/routers/__pycache__/metrics.cpython-311.pyc
CHANGED
|
Binary files a/api/routers/__pycache__/metrics.cpython-311.pyc and b/api/routers/__pycache__/metrics.cpython-311.pyc differ
|
|
|
api/routers/camera_stream.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
import asyncio
|
| 2 |
import itertools
|
| 3 |
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
|
|
|
| 4 |
from ai.contracts.detector import DetectionResults
|
| 5 |
-
from backend.api.routers.metrics import active_cameras, frame_processing_duration_seconds
|
| 6 |
from backend.contracts.camera_metadata import CameraMetadata, DetectionMetadata
|
| 7 |
import traceback
|
|
|
|
|
|
|
| 8 |
|
| 9 |
import cv2 as cv
|
| 10 |
import numpy as np
|
|
@@ -35,7 +38,11 @@ async def websocket_detect(websocket: WebSocket, camera_id:str):
|
|
| 35 |
logger.info(f"Client ID >>{camera_id}<< Connected...")
|
| 36 |
|
| 37 |
loop = asyncio.get_running_loop()
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
try:
|
| 41 |
# What are the info you aim to collect from the camera?
|
|
@@ -71,24 +78,19 @@ async def websocket_detect(websocket: WebSocket, camera_id:str):
|
|
| 71 |
|
| 72 |
image_array = await loop.run_in_executor(None, decode_frame)
|
| 73 |
decode_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 74 |
-
mlflow.log_metric("frame_processing_time", round(time.time() - t0, 3))
|
| 75 |
|
| 76 |
detection_task = loop.run_in_executor(None, run_detection, image_array)
|
| 77 |
safety_task = loop.run_in_executor(None, run_safety, image_array)
|
| 78 |
|
| 79 |
detections, safety_detection = await asyncio.gather(detection_task, safety_task)
|
| 80 |
detection_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 81 |
-
mlflow.log_metric("detection_duration_seconds", round(time.time() - t0, 3))
|
| 82 |
-
|
| 83 |
-
depth_points = await loop.run_in_executor(None, run_depth, image_array, boxes_center) if boxes_center else []
|
| 84 |
-
depth_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 85 |
-
mlflow.log_metric("depth_duration_seconds", round(time.time() - t0, 3))
|
| 86 |
|
| 87 |
# Profiling
|
| 88 |
frame_processing_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 89 |
logger.debug("Frame processed", camera_id=camera_id)
|
| 90 |
-
mlflow.log_metric("frame_processing duration time", round(time.time() - t0, 3))
|
| 91 |
-
|
| 92 |
|
| 93 |
boxes_center = []
|
| 94 |
boxes_center_ratio = []
|
|
@@ -99,6 +101,10 @@ async def websocket_detect(websocket: WebSocket, camera_id:str):
|
|
| 99 |
ycenter = (ymax + ymin) / 2
|
| 100 |
boxes_center.append((int(xcenter), int(ycenter)))
|
| 101 |
boxes_center_ratio.append(xcenter / image_array.shape[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
detection_metadata = [DetectionMetadata(depth=depth, xRatio=xRatio) for depth, xRatio in zip(depth_points, boxes_center_ratio)]
|
| 104 |
metadata = CameraMetadata(camera_id=camera_id, is_danger = True if safety_detection else False, detection_metadata=detection_metadata)
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import itertools
|
| 3 |
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
| 4 |
+
from pandas.core.frame import nested_data_to_arrays
|
| 5 |
from ai.contracts.detector import DetectionResults
|
| 6 |
+
from backend.api.routers.metrics import active_cameras, decode_duration_seconds, depth_duration_seconds, detection_duration_seconds, frame_processing_duration_seconds
|
| 7 |
from backend.contracts.camera_metadata import CameraMetadata, DetectionMetadata
|
| 8 |
import traceback
|
| 9 |
+
import mlflow
|
| 10 |
+
from backend.utils.experiment import log_config
|
| 11 |
|
| 12 |
import cv2 as cv
|
| 13 |
import numpy as np
|
|
|
|
| 38 |
logger.info(f"Client ID >>{camera_id}<< Connected...")
|
| 39 |
|
| 40 |
loop = asyncio.get_running_loop()
|
| 41 |
+
step_counter = itertools.count()
|
| 42 |
+
if mlflow.active_run():
|
| 43 |
+
mlflow.end_run()
|
| 44 |
+
run = mlflow.start_run(run_name=f'camera_{camera_id}', nested=True)
|
| 45 |
+
log_config()
|
| 46 |
|
| 47 |
try:
|
| 48 |
# What are the info you aim to collect from the camera?
|
|
|
|
| 78 |
|
| 79 |
image_array = await loop.run_in_executor(None, decode_frame)
|
| 80 |
decode_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 81 |
+
mlflow.log_metric("frame_processing_time", round(time.time() - t0, 3), next(step_counter))
|
| 82 |
|
| 83 |
detection_task = loop.run_in_executor(None, run_detection, image_array)
|
| 84 |
safety_task = loop.run_in_executor(None, run_safety, image_array)
|
| 85 |
|
| 86 |
detections, safety_detection = await asyncio.gather(detection_task, safety_task)
|
| 87 |
detection_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 88 |
+
mlflow.log_metric("detection_duration_seconds", round(time.time() - t0, 3), next(step_counter))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Profiling
|
| 91 |
frame_processing_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 92 |
logger.debug("Frame processed", camera_id=camera_id)
|
| 93 |
+
mlflow.log_metric("frame_processing duration time", round(time.time() - t0, 3), next(step_counter))
|
|
|
|
| 94 |
|
| 95 |
boxes_center = []
|
| 96 |
boxes_center_ratio = []
|
|
|
|
| 101 |
ycenter = (ymax + ymin) / 2
|
| 102 |
boxes_center.append((int(xcenter), int(ycenter)))
|
| 103 |
boxes_center_ratio.append(xcenter / image_array.shape[1])
|
| 104 |
+
|
| 105 |
+
depth_points = await loop.run_in_executor(None, run_depth, image_array, boxes_center) if boxes_center else []
|
| 106 |
+
depth_duration_seconds.labels(camera_id).observe(round(time.time() - t0, 3))
|
| 107 |
+
mlflow.log_metric("depth_duration_seconds", round(time.time() - t0, 3), next(step_counter))
|
| 108 |
|
| 109 |
detection_metadata = [DetectionMetadata(depth=depth, xRatio=xRatio) for depth, xRatio in zip(depth_points, boxes_center_ratio)]
|
| 110 |
metadata = CameraMetadata(camera_id=camera_id, is_danger = True if safety_detection else False, detection_metadata=detection_metadata)
|
contracts/__pycache__/camera_metadata.cpython-311.pyc
CHANGED
|
Binary files a/contracts/__pycache__/camera_metadata.cpython-311.pyc and b/contracts/__pycache__/camera_metadata.cpython-311.pyc differ
|
|
|
main.py
CHANGED
|
@@ -2,7 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
# from prometheus_client import metrics
|
| 3 |
from ai.depth.depth_anything import DepthAnything
|
| 4 |
from ai.detectors.yolo_detector import YOLO_Detector
|
| 5 |
-
from
|
| 6 |
from backend.api.routers.metrics import metrics_asgi_app
|
| 7 |
from infra.system_metrics import log_system_metrics
|
| 8 |
from backend.api.routers import camera_stream
|
|
@@ -12,7 +12,7 @@ from contextlib import asynccontextmanager
|
|
| 12 |
from infra.logger_structlog import StructLogger
|
| 13 |
import asyncio
|
| 14 |
import mlflow
|
| 15 |
-
from backend.utils.experiment import log_config
|
| 16 |
|
| 17 |
@asynccontextmanager
|
| 18 |
async def lifespan(app: FastAPI):
|
|
@@ -50,8 +50,9 @@ async def lifespan(app: FastAPI):
|
|
| 50 |
logger.warn("Shutting down the server....")
|
| 51 |
# You can remove connections and release gpu here .
|
| 52 |
|
|
|
|
| 53 |
mlflow.set_experiment("realtime-detection-system")
|
| 54 |
-
|
| 55 |
|
| 56 |
app = FastAPI(
|
| 57 |
title="Tracking System Backend",
|
|
|
|
| 2 |
# from prometheus_client import metrics
|
| 3 |
from ai.depth.depth_anything import DepthAnything
|
| 4 |
from ai.detectors.yolo_detector import YOLO_Detector
|
| 5 |
+
from config.settings import AppConfig
|
| 6 |
from backend.api.routers.metrics import metrics_asgi_app
|
| 7 |
from infra.system_metrics import log_system_metrics
|
| 8 |
from backend.api.routers import camera_stream
|
|
|
|
| 12 |
from infra.logger_structlog import StructLogger
|
| 13 |
import asyncio
|
| 14 |
import mlflow
|
| 15 |
+
from backend.utils.experiment import log_config
|
| 16 |
|
| 17 |
@asynccontextmanager
|
| 18 |
async def lifespan(app: FastAPI):
|
|
|
|
| 50 |
logger.warn("Shutting down the server....")
|
| 51 |
# You can remove connections and release gpu here .
|
| 52 |
|
| 53 |
+
mlflow.set_tracking_uri("sqlite:///config/logs/mlflow.db")
|
| 54 |
mlflow.set_experiment("realtime-detection-system")
|
| 55 |
+
mlflow.enable_system_metrics_logging()
|
| 56 |
|
| 57 |
app = FastAPI(
|
| 58 |
title="Tracking System Backend",
|
utils/__pycache__/experiment.cpython-311.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|