alyaaa-25 commited on
Commit
ed837ac
·
verified ·
1 Parent(s): 0a514e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -298,6 +298,14 @@ def run_model(
298
  .numpy()
299
  )
300
 
 
 
 
 
 
 
 
 
301
  # --------------------------------------------------------
302
  # Back to EXACT original dimensions.
303
  # --------------------------------------------------------
@@ -610,6 +618,10 @@ def run_vitmatte_refine(
610
 
611
  alpha = out.alphas[0, 0].float().cpu().numpy()
612
 
 
 
 
 
613
  # ViTMatte processor pads to a stride-32 canvas internally;
614
  # resize back to the exact crop size.
615
  alpha = cv2.resize(
@@ -1593,7 +1605,7 @@ def finalize_alpha(alpha):
1593
  # ============================================================
1594
 
1595
 
1596
- @spaces.GPU(duration=180)
1597
  def remove_background(
1598
  image
1599
  ):
@@ -1858,4 +1870,4 @@ with gr.Blocks(
1858
 
1859
  demo.queue().launch(
1860
  css=css
1861
- )
 
298
  .numpy()
299
  )
300
 
301
+ # Free GPU memory immediately — with 3 models running back to
302
+ # back on ZeroGPU's shared allocation, not doing this can push
303
+ # peak memory over budget and cause a silent worker kill with
304
+ # no Python traceback.
305
+ del tensor, prediction
306
+ if DEVICE == "cuda":
307
+ torch.cuda.empty_cache()
308
+
309
  # --------------------------------------------------------
310
  # Back to EXACT original dimensions.
311
  # --------------------------------------------------------
 
618
 
619
  alpha = out.alphas[0, 0].float().cpu().numpy()
620
 
621
+ del inputs, out
622
+ if DEVICE == "cuda":
623
+ torch.cuda.empty_cache()
624
+
625
  # ViTMatte processor pads to a stride-32 canvas internally;
626
  # resize back to the exact crop size.
627
  alpha = cv2.resize(
 
1605
  # ============================================================
1606
 
1607
 
1608
+ @spaces.GPU(duration=280)
1609
  def remove_background(
1610
  image
1611
  ):
 
1870
 
1871
  demo.queue().launch(
1872
  css=css
1873
+ )