Merge remote-tracking branch 'origin/dev' into feat/tracker
This commit is contained in:
commit
9631a71073
7 changed files with 701 additions and 230 deletions
|
@ -13,6 +13,7 @@ import concurrent.futures
|
|||
from ultralytics import YOLO
|
||||
from urllib.parse import urlparse
|
||||
from .database import DatabaseManager
|
||||
from .model_registry import get_shared_model, release_shared_model
|
||||
from datetime import datetime
|
||||
|
||||
# Create a logger specifically for this module
|
||||
|
@ -98,13 +99,11 @@ def load_pipeline_node(node_config: dict, mpta_dir: str, redis_client, db_manage
|
|||
logger.error(f"Model file {model_path} not found. Current directory: {os.getcwd()}")
|
||||
logger.error(f"Directory content: {os.listdir(os.path.dirname(model_path))}")
|
||||
raise FileNotFoundError(f"Model file {model_path} not found.")
|
||||
logger.info(f"Loading model for node {node_config['modelId']} from {model_path}")
|
||||
model = YOLO(model_path)
|
||||
if torch.cuda.is_available():
|
||||
logger.info(f"CUDA available. Moving model {node_config['modelId']} to GPU VRAM")
|
||||
model.to("cuda")
|
||||
else:
|
||||
logger.info(f"CUDA not available. Using CPU for model {node_config['modelId']}")
|
||||
|
||||
# Use shared model registry to prevent duplicate loading
|
||||
model_id = node_config['modelId']
|
||||
logger.info(f"Getting shared model for node {model_id} from {model_path}")
|
||||
model = get_shared_model(model_id, model_path)
|
||||
|
||||
# Prepare trigger class indices for optimization
|
||||
trigger_classes = node_config.get("triggerClasses", [])
|
||||
|
@ -1138,6 +1137,17 @@ def is_camera_active(camera_id, model_id):
|
|||
|
||||
return session_state.get("active", True)
|
||||
|
||||
def cleanup_pipeline_node(node: dict):
|
||||
"""Clean up a pipeline node and release its model reference."""
|
||||
if node and "modelId" in node:
|
||||
model_id = node["modelId"]
|
||||
logger.info(f"🧹 Cleaning up pipeline node: {model_id}")
|
||||
release_shared_model(model_id)
|
||||
|
||||
# Recursively clean up branches
|
||||
for branch in node.get("branches", []):
|
||||
cleanup_pipeline_node(branch)
|
||||
|
||||
def cleanup_camera_stability(camera_id):
|
||||
"""Clean up stability tracking data when a camera is disconnected."""
|
||||
global _camera_stability_tracking
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue