jerpelhan commited on
Commit
ef5932e
·
1 Parent(s): f800f22

Remove CUDA post-processing outside the inference funciton

Browse files
Files changed (1) hide show
  1. demo_gradio.py +23 -5
demo_gradio.py CHANGED
@@ -88,11 +88,30 @@ def process_image_once(inputs, enable_mask):
88
  model.module.return_masks = enable_mask
89
  outputs, _, _, _, masks = model(img, bboxes)
90
 
91
- outputs[0]["pred_boxes"] = outputs[0]["pred_boxes"].cpu()
92
- outputs[0]["box_v"] = outputs[0]["box_v"].cpu()
93
- masks[0] = masks[0].cpu() if enable_mask else None
 
 
 
94
 
95
- return image, outputs, masks, img, scale, drawn_boxes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
 
98
  # -----------------------------
@@ -188,7 +207,6 @@ def post_process(image, outputs, masks, img, scale, drawn_boxes, enable_mask, th
188
  draw.rectangle([x1, y1, x2, y2], outline=box_rgb, width=box_width)
189
 
190
  # --- Exemplar boxes (user-drawn): keep clear but unobtrusive, no text ---
191
- # You can adjust these two colors if you want them to be more/less prominent.
192
  exemplar_outline = (255, 255, 255, 255) # white
193
  exemplar_inner = (0, 0, 0, 255) # black
194
  for box in drawn_boxes:
 
88
  model.module.return_masks = enable_mask
89
  outputs, _, _, _, masks = model(img, bboxes)
90
 
91
+ # ------------------------------------------------------------------
92
+ # ZeroGPU requirement: return ONLY CPU-native objects to main process.
93
+ # Do NOT return CUDA tensors, and avoid returning output dicts that may
94
+ # contain additional CUDA tensors beyond pred_boxes/box_v.
95
+ # ------------------------------------------------------------------
96
+ out0 = outputs[0]
97
 
98
+ pred_boxes_cpu = out0["pred_boxes"].detach().float().cpu()
99
+ box_v_cpu = out0["box_v"].detach().float().cpu()
100
+
101
+ outputs_cpu = [{
102
+ "pred_boxes": pred_boxes_cpu,
103
+ "box_v": box_v_cpu,
104
+ }]
105
+
106
+ if enable_mask and masks is not None and masks[0] is not None:
107
+ masks_cpu = [masks[0].detach().float().cpu()]
108
+ else:
109
+ masks_cpu = [None]
110
+
111
+ # img is only used for shape in post_process, so return a CPU tensor
112
+ img_cpu = img.detach().cpu()
113
+
114
+ return image, outputs_cpu, masks_cpu, img_cpu, float(scale), drawn_boxes
115
 
116
 
117
  # -----------------------------
 
207
  draw.rectangle([x1, y1, x2, y2], outline=box_rgb, width=box_width)
208
 
209
  # --- Exemplar boxes (user-drawn): keep clear but unobtrusive, no text ---
 
210
  exemplar_outline = (255, 255, 255, 255) # white
211
  exemplar_inner = (0, 0, 0, 255) # black
212
  for box in drawn_boxes: