INNER CODE UNIT · Python
detect_objects
virajmavani/semi-auto-image-annotation-tool · web/backend/main.py:255
async def detect_objects(request: DetectionRequest):
"""Run object detection on an image"""
async with _model_lock:
model = current_model
if model is None:
raise HTTPException(status_code=500, detail="Model not loaded")
try:
from torchvision.io.image import read_image
# Validate image path is inside an allowed directory
img_path = Path(request.image_path).resolve()
allowed_dirs = [UPLOAD_DIR.resolve()]
if current_dataset_dir:
allowed_dirs.append(Path(current_dataset_dir).resolve())
if not any(img_path.is_relative_to(d) for d in allowed_dirs):
raise HTTPException(status_code=400, detail="Image path is outside allowed directories")