Safety_Violation_CCTV_AI2 / tests /test_inference.py
PrashanthB461's picture
Update tests/test_inference.py
7a1e317 verified
import pytest
import numpy as np
from app import YOLOv8Model, preprocess_frame
import cv2
def test_yolo_model_initialization():
"""Test YOLO model can be initialized"""
try:
model = YOLOv8Model()
assert model.model is not None, "YOLO model should be initialized"
except Exception as e:
pytest.skip(f"Model initialization failed: {e}")
def test_preprocess_frame():
"""Test frame preprocessing"""
# Create a test frame
frame = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
processed = preprocess_frame(frame)
assert processed.shape == (640, 640, 3), "Processed frame should be 640x640x3"
assert processed.dtype == np.uint8, "Processed frame should be uint8"
def test_yolo_prediction():
"""Test YOLO prediction on dummy image"""
try:
model = YOLOv8Model()
# Create a dummy image
image = np.random.randint(0, 255, (640, 640, 3), dtype=np.uint8)
results = model.predict(image)
assert results is not None, "YOLO prediction should return results"
except Exception as e:
pytest.skip(f"YOLO prediction test failed: {e}")