Explicitly clear model and release GPU memory.
(self)
| 88 | self.birefnet.half() |
| 89 | |
| 90 | def cleanup(self): |
| 91 | """Explicitly clear model and release GPU memory.""" |
| 92 | # Delete the model reference |
| 93 | if hasattr(self, "birefnet"): |
| 94 | del self.birefnet |
| 95 | |
| 96 | # Clear Python garbage |
| 97 | import gc |
| 98 | |
| 99 | gc.collect() |
| 100 | |
| 101 | # Clear PyTorch CUDA cache |
| 102 | if torch.cuda.is_available(): |
| 103 | torch.cuda.empty_cache() |
| 104 | torch.cuda.ipc_collect() |
| 105 | |
| 106 | def process(self, input_path, alpha_output_dir=None, dilate_radius=0, on_frame_complete=None): |
| 107 | """ |