Instructions to use dataguychill/VioMobileNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use dataguychill/VioMobileNet with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("dataguychill/VioMobileNet") - Notebooks
- Google Colab
- Kaggle
File size: 1,827 Bytes
164cfb7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # main.py
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from inference import VideoProcessor
import threading
import queue
import asyncio
import json
app = FastAPI()
@app.websocket("/ws/inference")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
processor = VideoProcessor()
result_queue = queue.Queue()
try:
# 1. Nhận link RTSP từ Laptop
data = await websocket.receive_text()
config = json.loads(data)
rtsp_url = config.get("url")
print(f"Received request for: {rtsp_url}")
# 2. Chạy Model trong luồng riêng (Background Thread)
# Để không chặn WebSocket
process_thread = threading.Thread(
target=processor.start_processing,
args=(rtsp_url, result_queue)
)
process_thread.start()
# 3. Vòng lặp gửi kết quả về Laptop
while True:
# Kiểm tra queue xem có kết quả mới từ Model không
try:
# Non-blocking get
result = result_queue.get_nowait()
await websocket.send_json(result)
except queue.Empty:
# Nếu không có kết quả, ngủ xíu để đỡ tốn CPU
await asyncio.sleep(0.1)
# Kiểm tra nếu client ngắt kết nối thì dừng model
if not process_thread.is_alive():
await websocket.send_json({"status": "Processing finished"})
break
except WebSocketDisconnect:
print("Client disconnected")
processor.running = False # Ra lệnh dừng model
process_thread.join()
except Exception as e:
print(f"Error: {e}")
processor.running = False |