Spaces:
Running
on
Zero
Running
on
Zero
Migrate to ZeroGPU and update requirements for compatibility
Browse files- app.py +3 -3
- requirements.txt +3 -4
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from ultralytics import YOLO
|
3 |
from fastapi import FastAPI
|
4 |
from PIL import Image
|
5 |
-
import numpy as np
|
6 |
import torch
|
7 |
import spaces
|
8 |
|
@@ -15,8 +14,9 @@ model = YOLO('NailongKiller.yolo11n.pt').to(device)
|
|
15 |
|
16 |
@spaces.GPU
|
17 |
def predict(img):
|
18 |
-
|
19 |
-
|
|
|
20 |
results = model.predict(img_tensor)
|
21 |
return results[0].plot()
|
22 |
|
|
|
2 |
from ultralytics import YOLO
|
3 |
from fastapi import FastAPI
|
4 |
from PIL import Image
|
|
|
5 |
import torch
|
6 |
import spaces
|
7 |
|
|
|
14 |
|
15 |
@spaces.GPU
|
16 |
def predict(img):
|
17 |
+
# 使用 PIL 直接转换为 PyTorch 张量
|
18 |
+
img_resized = Image.fromarray(img).resize((640, 640))
|
19 |
+
img_tensor = torch.tensor(img_resized, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0).to(device)
|
20 |
results = model.predict(img_tensor)
|
21 |
return results[0].plot()
|
22 |
|
requirements.txt
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
torch
|
2 |
-
torchvision
|
3 |
ultralytics>=8.3.0
|
4 |
Pillow
|
5 |
fastapi
|
6 |
python-multipart
|
7 |
-
uvicorn
|
8 |
-
numpy
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
ultralytics>=8.3.0
|
4 |
Pillow
|
5 |
fastapi
|
6 |
python-multipart
|
7 |
+
uvicorn
|
|