Spaces:
Sleeping
Sleeping
File size: 2,252 Bytes
bc611ff b99fd7c 9093750 b99fd7c eedca6c b99fd7c 9093750 8ead15f 9093750 eedca6c 8ead15f eedca6c 9093750 b99fd7c 9093750 eedca6c 9093750 bc611ff eedca6c bc611ff eedca6c bc611ff 9093750 eedca6c bc611ff eedca6c 9093750 b99fd7c | 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import os
import gradio as gr
import numpy as np
import cv2
from my_models import YOLOV5CLIPModel, YOLOV8CLIPModel
def annotated_image(
image: np.ndarray, label: str, conf: float, bbox: list
) -> np.ndarray:
line_thickness = max(1, int(0.005 * max(image.shape[:2])))
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
image = cv2.rectangle(
image,
(bbox[0], bbox[1]),
(bbox[2], bbox[3]),
(255, 0, 0),
thickness=line_thickness,
)
image = cv2.putText(
image,
f"{label} {conf:.2f}",
(bbox[0], max(bbox[1] - 2 * line_thickness, 0)),
cv2.FONT_HERSHEY_SIMPLEX,
thickness=max(line_thickness // 2, 1),
lineType=cv2.LINE_AA,
color=(0, 0, 0),
fontScale=max(0.5, 0.1 * line_thickness),
)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
return image
def detect_mosquito(image):
label, conf, bbox = YOLOV8CLIPModel().predict(image)
return annotated_image(image, label, conf, bbox)
description = """# [Mosquito Alert Competition 2023](https://www.aicrowd.com/challenges/mosquitoalert-challenge-2023) - 7th Place Solution
Welcome to my Hugging Face Space showcasing the performance of our model.
This competition focused on detecting and classifying various mosquito species.
The target species were:
- **Aedes aegypti** - Species
- **Aedes albopictus** - Species
- **Anopheles** - Genus
- **Culex** - Genus (Species classification is challenging, so it is provided at the genus level)
- **Culiseta** - Genus
- **Aedes japonicus/Aedes koreicus** - Species complex (Differentiating between these two species is particularly challenging).
> ***Note:** Only one mosquito will be annotated even if there are multiple mosquitoes in the image.*
## Experiment Details
All the details regarding the experiments and source code for the models can be found in the [GitHub repository](https://github.com/HCA97/Mosquito-Classifiction/tree/main).
"""
iface = gr.Interface(
fn=detect_mosquito,
description=description,
inputs=gr.Image(),
outputs=gr.Image(),
allow_flagging="never",
examples=[os.path.join("examples", f) for f in os.listdir("examples")],
cache_examples=True,
)
iface.launch()
|