event driven system
This commit is contained in:
parent
0c5f56c8a6
commit
3a47920186
10 changed files with 782 additions and 253 deletions
|
|
@ -5,11 +5,10 @@ This script demonstrates:
|
|||
- Event-driven stream processing with StreamConnectionManager
|
||||
- Batched GPU inference with ModelController
|
||||
- Ping-pong buffer architecture for optimal throughput
|
||||
- Async/await pattern for multiple RTSP streams
|
||||
- Callback-based event-driven pattern for RTSP streams
|
||||
- Automatic PT to TensorRT conversion
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import os
|
||||
import torch
|
||||
|
|
@ -26,7 +25,7 @@ from services import (
|
|||
load_dotenv()
|
||||
|
||||
|
||||
async def main_single_stream():
|
||||
def main_single_stream():
|
||||
"""Single stream example with event-driven architecture."""
|
||||
print("=" * 80)
|
||||
print("Event-Driven GPU-Accelerated Object Tracking - Single Stream")
|
||||
|
|
@ -64,9 +63,9 @@ async def main_single_stream():
|
|||
print("\n[2/3] Initializing with PT model...")
|
||||
print("Note: First load will convert PT to TensorRT (3-5 minutes)")
|
||||
print("Subsequent loads will use cached TensorRT engine\n")
|
||||
|
||||
|
||||
try:
|
||||
await manager.initialize(
|
||||
manager.initialize(
|
||||
model_path=MODEL_PATH,
|
||||
model_id="detector",
|
||||
preprocess_fn=YOLOv8Utils.preprocess,
|
||||
|
|
@ -85,7 +84,7 @@ async def main_single_stream():
|
|||
# Connect stream
|
||||
print("\n[3/3] Connecting to stream...")
|
||||
try:
|
||||
connection = await manager.connect_stream(
|
||||
connection = manager.connect_stream(
|
||||
rtsp_url=STREAM_URL,
|
||||
stream_id="camera_1",
|
||||
buffer_size=30
|
||||
|
|
@ -110,7 +109,7 @@ async def main_single_stream():
|
|||
cv2.resizeWindow("Object Tracking", 1280, 720)
|
||||
|
||||
try:
|
||||
async for result in connection.tracking_results():
|
||||
for result in connection.tracking_results():
|
||||
result_count += 1
|
||||
|
||||
# Check if we've reached max frames
|
||||
|
|
@ -189,8 +188,8 @@ async def main_single_stream():
|
|||
if ENABLE_DISPLAY:
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
await connection.stop()
|
||||
await manager.shutdown()
|
||||
connection.stop()
|
||||
manager.shutdown()
|
||||
print("✓ Stopped")
|
||||
|
||||
# Final stats
|
||||
|
|
@ -199,7 +198,7 @@ async def main_single_stream():
|
|||
print(f"\nFinal: {result_count} results in {elapsed:.1f}s ({avg_fps:.1f} FPS)")
|
||||
|
||||
|
||||
async def main_multi_stream():
|
||||
def main_multi_stream():
|
||||
"""Multi-stream example with batched inference."""
|
||||
print("=" * 80)
|
||||
print("Event-Driven GPU-Accelerated Object Tracking - Multi-Stream")
|
||||
|
|
@ -245,7 +244,7 @@ async def main_multi_stream():
|
|||
# Initialize with PT model
|
||||
print("\n[2/3] Initializing with PT model...")
|
||||
try:
|
||||
await manager.initialize(
|
||||
manager.initialize(
|
||||
model_path=MODEL_PATH,
|
||||
model_id="detector",
|
||||
preprocess_fn=YOLOv8Utils.preprocess,
|
||||
|
|
@ -266,7 +265,7 @@ async def main_multi_stream():
|
|||
connections = {}
|
||||
for stream_id, rtsp_url in camera_urls:
|
||||
try:
|
||||
conn = await manager.connect_stream(
|
||||
conn = manager.connect_stream(
|
||||
rtsp_url=rtsp_url,
|
||||
stream_id=stream_id,
|
||||
buffer_size=30
|
||||
|
|
@ -295,7 +294,7 @@ async def main_multi_stream():
|
|||
# Simple approach: iterate over first connection's results
|
||||
# In production, you'd properly merge all result streams
|
||||
for conn in connections.values():
|
||||
async for result in conn.tracking_results():
|
||||
for result in conn.tracking_results():
|
||||
total_results += 1
|
||||
stream_id = result.stream_id
|
||||
|
||||
|
|
@ -322,8 +321,8 @@ async def main_multi_stream():
|
|||
print(f"{'=' * 80}")
|
||||
|
||||
for conn in connections.values():
|
||||
await conn.stop()
|
||||
await manager.shutdown()
|
||||
conn.stop()
|
||||
manager.shutdown()
|
||||
print("✓ Stopped")
|
||||
|
||||
# Final stats
|
||||
|
|
@ -335,6 +334,6 @@ async def main_multi_stream():
|
|||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "single":
|
||||
asyncio.run(main_single_stream())
|
||||
main_single_stream()
|
||||
else:
|
||||
asyncio.run(main_multi_stream())
|
||||
main_multi_stream()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue