OPHoperHPO / image-background-remove-tool

✂️ Automated high-quality background removal framework for an image using neural networks. ✂️
https://carve.photos
Apache License 2.0
1.39k stars 272 forks source link

Memory Leak in Carvekit's Interface #150

Closed limenglian closed 6 months ago

limenglian commented 7 months ago

Description: When utilizing Carvekit's interface with the provided configuration settings, particularly during the execution of the interface.segmentation_pipeline() and interface.postprocessing_pipeline.matting_module() functions, there appears to be a memory leak issue. Despite repeated usage, memory consumption continues to increase, indicating a potential problem within the implementation of these functions.

Code Segment: interface = HiInterface( object_type="object", batch_size_seg=1, batch_size_matting=1, device='cuda', seg_mask_size=640, matting_mask_size=2048, trimap_prob_threshold=231, trimap_dilation=30, trimap_erosion_iters=5, fp16=True, )

images = [img1,img2] mask = interface.segmentation_pipeline(images) trimap1 = interface.trimap_generator(original_image=images[0], mask=mask[0]) trimap2 = interface.trimap_generator(original_image=images[1], mask=mask[1]) interface.postprocessing_pipeline.matting_module(images, [trimap1, trimap2])

Issue Details: The interface.segmentation_pipeline() and interface.postprocessing_pipeline.matting_module() functions exhibit abnormal memory behavior, wherein memory consumption steadily increases over time, suggesting a memory leak. This behavior is observed despite adhering to recommended usage patterns and configuration settings provided by Carvekit.

OPHoperHPO commented 7 months ago

Hi @limenglian

Can you provide more detailed reports about the memory consumption of this code snippet? I need to know the following:

  1. Timeframe of memory growth: When does the memory usage start to increase?
  2. Fluctuation after the first run: How much does the memory usage fluctuate after the code runs for the first time?
  3. Fluctuation on the nth iteration: Is there a noticeable pattern of memory fluctuation as the code runs multiple times? If so, at what iteration does it become apparent?
  4. Method with the issue: Which specific method within the code is causing this memory behavior?
  5. Can you provide images of what is causing this behavior?

The current information is too general and doesn't pinpoint the problematic area effectively. However, I will do some research on this issue on my end.