muk42 commited on
Commit
862e4d8
·
1 Parent(s): a0f7b41

wrap yolo pred with gpu

Browse files
Files changed (2) hide show
  1. app.py +1 -0
  2. inference_tab/inference_logic.py +6 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  # [DEBUG]
2
  #from osgeo import gdal
3
 
 
4
  import gradio as gr
5
  import logging
6
  from inference_tab import get_inference_widgets, run_inference
 
1
  # [DEBUG]
2
  #from osgeo import gdal
3
 
4
+
5
  import gradio as gr
6
  import logging
7
  from inference_tab import get_inference_widgets, run_inference
inference_tab/inference_logic.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import numpy as np
2
  from ultralytics import YOLO
3
  import os
@@ -52,7 +53,10 @@ def run_inference(image_path, gcp_path, city_name, score_th):
52
  else:
53
  yield msg, None
54
 
55
-
 
 
 
56
 
57
  def getBBoxes(image_path, tile_size=256, overlap=0.3, confidence_threshold=0.25):
58
  yield f"DEBUG: Received image_path: {image_path}"
@@ -82,7 +86,7 @@ def getBBoxes(image_path, tile_size=256, overlap=0.3, confidence_threshold=0.25)
82
  if tile.shape[0] < tile_size or tile.shape[1] < tile_size:
83
  continue
84
 
85
- results = model.predict(source=tile, imgsz=tile_size, conf=confidence_threshold, verbose=False)
86
 
87
  for result in results:
88
  boxes = result.boxes.xyxy.cpu().numpy()
 
1
+ import spaces
2
  import numpy as np
3
  from ultralytics import YOLO
4
  import os
 
53
  else:
54
  yield msg, None
55
 
56
+
57
+ @spaces.GPU
58
+ def yolo_pred(model,tile,tile_size,conf_threshold,verbose=False):
59
+ return model.predict(source=tile, imgsz=tile_size, conf=conf_threshold, verbose=verbose)
60
 
61
  def getBBoxes(image_path, tile_size=256, overlap=0.3, confidence_threshold=0.25):
62
  yield f"DEBUG: Received image_path: {image_path}"
 
86
  if tile.shape[0] < tile_size or tile.shape[1] < tile_size:
87
  continue
88
 
89
+ results = yolo_pred(model,tile,tile_size,confidence_threshold,verbose=False)
90
 
91
  for result in results:
92
  boxes = result.boxes.xyxy.cpu().numpy()