Daankular commited on
Commit
5d73995
·
1 Parent(s): 62747da

Patch all-zero alpha: fallback to full-foreground instead of raising ValueError

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -227,6 +227,23 @@ def load_triposg():
227
  _ip_path.write_text(_ip_text2)
228
  print("[load_triposg] Patched image_process.py: empty contours guard")
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  # Safety net: patch inference_utils.py to make diso import optional.
231
  # Even if diso compiled with submodules, guard against any residual link errors.
232
  _iu_path = triposg_src / "triposg" / "inference_utils.py"
 
227
  _ip_path.write_text(_ip_text2)
228
  print("[load_triposg] Patched image_process.py: empty contours guard")
229
 
230
+ # Patch all-zero alpha guard: instead of raising ValueError("input image too small"),
231
+ # fall back to full-foreground alpha so the pipeline can continue with the whole image.
232
+ # Happens when RMBG produces a blank mask (e.g. remove_small_objects wipes everything).
233
+ _ip_text3 = _ip_path.read_text()
234
+ if "all_zero_alpha_guard" not in _ip_text3:
235
+ _ip_text3 = _ip_text3.replace(
236
+ ' if np.all(alpha==0):\n raise ValueError(f"input image too small")',
237
+ " if np.all(alpha==0): # all_zero_alpha_guard\n"
238
+ " h_full, w_full = alpha.shape[:2]\n"
239
+ " alpha = np.full((h_full, w_full), 255, dtype=np.uint8)\n"
240
+ " alpha_gpu = torch.ones(1, h_full, w_full, dtype=torch.float32,\n"
241
+ " device=rgb_image_gpu.device)\n"
242
+ " x, y, w, h = 0, 0, w_full, h_full",
243
+ )
244
+ _ip_path.write_text(_ip_text3)
245
+ print("[load_triposg] Patched image_process.py: all-zero alpha fallback")
246
+
247
  # Safety net: patch inference_utils.py to make diso import optional.
248
  # Even if diso compiled with submodules, guard against any residual link errors.
249
  _iu_path = triposg_src / "triposg" / "inference_utils.py"