Hakureirm commited on
Commit
6136f56
·
1 Parent(s): 0ce6f4c

Migrate to ZeroGPU and update requirements for compatibility

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -16,8 +16,9 @@ model = YOLO('NailongKiller.yolo11n.pt').to(device)
16
 
17
  @spaces.GPU # 使用装饰器标记需要 GPU 的函数
18
  def predict(img):
19
- img = img.to(device)
20
- results = model.predict(img)
 
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
- image_np = torch.from_numpy(image_np).to(device)
 
48
 
49
- results = model.predict(image_np)
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 = []