import supervision as sv import gradio as gr from ultralytics import YOLO import sahi import numpy as np # Images sahi.utils.file.download_from_url( "https://transform.roboflow.com/i4FKV5acvhPPX6jb5fqVRBP900D3/0fdc23d04956a472db0c768a33974f50/thumb.jpg", "t1.jpg", ) sahi.utils.file.download_from_url( "https://transform.roboflow.com/i4FKV5acvhPPX6jb5fqVRBP900D3/e11b147e2f547b8265eb8731299673f7/thumb.jpg", "t2.jpg", ) sahi.utils.file.download_from_url( "https://transform.roboflow.com/i4FKV5acvhPPX6jb5fqVRBP900D3/0fdc23d04956a472db0c768a33974f50/thumb.jpg", "t3.jpg", ) annotatorbbox = sv.BoxAnnotator() annotatormask=sv.MaskAnnotator() def yolov8_inference( image: gr.inputs.Image = None, conf_threshold: gr.inputs.Slider = 0.5, iou_threshold: gr.inputs.Slider = 0.45, ): image=image[:, :, ::-1].astype(np.uint8) model = YOLO("https://huggingface.co/spaces/devisionx/Sixth_Demo/blob/main/bestt_weight.pt") results = model(image,imgsz=640,conf=conf_threshold,iou=iou_threshold)[0] image=image[:, :, ::-1].astype(np.uint8) detections = sv.Detections.from_yolov8(results) annotated_image = annotatormask.annotate(scene=image, detections=detections) annotated_image = annotatorbbox.annotate(scene=annotated_image , detections=detections) return annotated_image ''' image_input = gr.inputs.Image() # Adjust the shape according to your requirements inputs = [ gr.inputs.Image(label="Input Image"), gr.Slider( minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold" ), gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"), ] outputs = gr.Image(type="filepath", label="Output Image") title = "Tennis Court Demo" ''' import os examples = [ ["t1.jpg", 0.25, 0.45], ["t2.jpg", 0.25, 0.45], ["t3.jpg", 0.25, 0.45], ] outputs_images = [ ["1.jpg"], # First example: an output image for the cat example ["2.jpg"] # Second example: an output image for the dog example ,["3.jpg"] ] readme_html = """
More details:
We present a demo for performing object segmentation with training a Yolov8-seg on wheel Image dataset. The model was trained on 696 training images and validated on 199 images.
Usage:
You can upload Tennis-Court images, and the demo will provide you with your segmented image.
Dataset:
The dataset contains 3,146 images and is formatted in COCO style. To facilitate usage with YOLOv8-seg, we have converted it into YOLOv8 format.
License: This dataset is made available under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
To access and download this dataset, please follow this link: Dataset Download
""" with gr.Blocks() as demo: gr.Markdown( """