Spaces:
Running
on
Zero
Running
on
Zero
add zeroGPU support
Browse filesis this implementation correct?
@atalaydenknalbant
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import sahi.utils
|
| 3 |
from sahi import AutoDetectionModel
|
| 4 |
import sahi.predict
|
|
@@ -39,6 +41,7 @@ sahi.utils.file.download_from_url(
|
|
| 39 |
# Global model variable
|
| 40 |
model = None
|
| 41 |
|
|
|
|
| 42 |
def load_yolo_model(model_name, confidence_threshold=0.5):
|
| 43 |
"""
|
| 44 |
Loads a YOLOv11 detection model.
|
|
@@ -53,11 +56,12 @@ def load_yolo_model(model_name, confidence_threshold=0.5):
|
|
| 53 |
global model
|
| 54 |
model_path = model_name
|
| 55 |
model = AutoDetectionModel.from_pretrained(
|
| 56 |
-
model_type="ultralytics", model_path=model_path, device=
|
| 57 |
confidence_threshold=confidence_threshold, image_size=IMAGE_SIZE
|
| 58 |
)
|
| 59 |
return model
|
| 60 |
|
|
|
|
| 61 |
def sahi_yolo_inference(
|
| 62 |
image,
|
| 63 |
yolo_model_name,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
|
| 4 |
import sahi.utils
|
| 5 |
from sahi import AutoDetectionModel
|
| 6 |
import sahi.predict
|
|
|
|
| 41 |
# Global model variable
|
| 42 |
model = None
|
| 43 |
|
| 44 |
+
@spaces.GPU(duration=60)
|
| 45 |
def load_yolo_model(model_name, confidence_threshold=0.5):
|
| 46 |
"""
|
| 47 |
Loads a YOLOv11 detection model.
|
|
|
|
| 56 |
global model
|
| 57 |
model_path = model_name
|
| 58 |
model = AutoDetectionModel.from_pretrained(
|
| 59 |
+
model_type="ultralytics", model_path=model_path, device=None, # auto device selection
|
| 60 |
confidence_threshold=confidence_threshold, image_size=IMAGE_SIZE
|
| 61 |
)
|
| 62 |
return model
|
| 63 |
|
| 64 |
+
@spaces.GPU(duration=60)
|
| 65 |
def sahi_yolo_inference(
|
| 66 |
image,
|
| 67 |
yolo_model_name,
|