Spaces:
Running
on
Zero
Running
on
Zero
Migrate to ZeroGPU and update requirements for compatibility
Browse files
app.py
CHANGED
@@ -16,8 +16,9 @@ model = YOLO('NailongKiller.yolo11n.pt').to(device)
|
|
16 |
|
17 |
@spaces.GPU # 使用装饰器标记需要 GPU 的函数
|
18 |
def predict(img):
|
19 |
-
|
20 |
-
|
|
|
21 |
return results[0].plot()
|
22 |
|
23 |
# Gradio 界面
|
@@ -44,9 +45,10 @@ async def detect_api(file: UploadFile = File(...)):
|
|
44 |
image = Image.open(io.BytesIO(contents))
|
45 |
image_np = np.array(image)
|
46 |
|
47 |
-
|
|
|
48 |
|
49 |
-
results = model.predict(
|
50 |
result = results[0]
|
51 |
|
52 |
detections = []
|
|
|
16 |
|
17 |
@spaces.GPU # 使用装饰器标记需要 GPU 的函数
|
18 |
def predict(img):
|
19 |
+
# 将 numpy 数组转换为 PyTorch 张量
|
20 |
+
img_tensor = torch.from_numpy(img).to(device)
|
21 |
+
results = model.predict(img_tensor)
|
22 |
return results[0].plot()
|
23 |
|
24 |
# Gradio 界面
|
|
|
45 |
image = Image.open(io.BytesIO(contents))
|
46 |
image_np = np.array(image)
|
47 |
|
48 |
+
# 将图像移动到 GPU
|
49 |
+
image_tensor = torch.from_numpy(image_np).to(device)
|
50 |
|
51 |
+
results = model.predict(image_tensor)
|
52 |
result = results[0]
|
53 |
|
54 |
detections = []
|