| from ultralytics import YOLO |
| import cv2 |
| import numpy as np |
|
|
| |
| MIN_W, MIN_H = 60, 60 |
| MAX_W, MAX_H = 400, 400 |
|
|
| |
| model = YOLO('best (2).pt') |
| print("YOLO model loaded successfully.") |
| def predict_image(image_path): |
| |
| results = model(image_path, |
| conf=0.5, |
| iou=0.15, |
| max_det=300, |
| augment=True) |
|
|
| |
| if results[0].boxes: |
| b = results[0].boxes.xywh |
| w = b[:, 2] |
| h = b[:, 3] |
| |
| |
| keep = (w >= MIN_W) & (h >= MIN_H) & (w <= MAX_W) & (h <= MAX_H) |
| |
| |
| results[0].boxes = results[0].boxes[keep] |
| results[0].update() |
|
|
| |
| annotated_image = results[0].plot(labels=True, conf=True) |
| return annotated_image |
|
|
| import gradio as gr |
|
|
| |
| iface = gr.Interface(fn=predict_image, |
| inputs=gr.Image(type="filepath", label="Upload Image or Use Camera"), |
| outputs=gr.Image(type="numpy", label="Detected Objects"), |
| title="FAWDetect") |
|
|
| |
| iface.launch(debug=True) |