bgslibrary
bgslibrary copied to clipboard
Memory leak - Python Wrapper
I tested the python wrapper with Demo.py, but change the video source and noticed that the memory doesn't stop growing. Even with the example video there is a memory leak, I tested it with differents algorithms and some results. Any suggestion to fix this? I used openCV 3.1, python 2.7 and Ubuntu 14.04 for these tests.
Thanks.
Hi @rlifz , Sorry for my long delayed feedback, I was in a very busy time. Thanks for reporting this issue. I will check this, and I let you updated if I have something new in my side. Best
I am also noticing a memory leak. Testing with SubSENSE. What information can I provide to help diagnose? I was running a 30 second test video. Low quality, so 500MB is a lot of data.
I am still investigating this, I actually think its in the opencv passing, not the bgslibrary, will confirm.
I've looked this a couple different ways, I think it is BGSLibrary. It appears that it is the .apply method for the background subtractor classes. I can confirm it happens with both SubSense and LOBSTER. Memory grows as the loop continues, not releasing previous frames? Compared to cv2.createBackgroundSubtractorMOG2, the .apply method in libbgs.SuBSENSE() uses 4x memory very quickly and continues to rise until I kill it.
I also noticed the memory leak and I don't think it is related to specific models. The input frame is not released and the memory grows by frame sizes.
Same here. This is unusable in its current form - I quickly run out of memory (16GB) and start swapping. If it helps, I'm running boost from 11/19 (commit 81dcc8f) and the most recet bgs library code from 8/27 (commit e246604).
If it makes testing easier, I've attached my test script. Change the input file name in line 12 and run -> no memory leak. Uncomment line 30 *bgs.apply) and run -> memory leak.
#!/usr/bin/env python3
import cv2 import sys import numpy as np import libbgs
if name == 'main':
bgs = libbgs.FrameDifference()
camera = cv2.VideoCapture('fixed.mp4')
if not camera.isOpened():
print("Couldn't open video")
sys.exit()
count = 0
out = None
while True:
ok, output = camera.read()
if not ok: break
print(count)
count += 1
if out is None:
h, w = output.shape[:2]
out = cv2.VideoWriter('out.mp4', 0x00000021, camera.get(cv2.CAP_PROP_FPS), (w, h), True)
mask = np.empty(output.shape[:2], np.uint8)
#mask = bgs.apply(output)
# model = bgs.getBackgroundModel()
#output[mask == 0] = 0
out.write(output)
if out: out.release()
camera.release()
cv2.destroyAllWindows()
This change fixes the memory leak in the python wrapper:
https://github.com/lgov/bgslibrary/commit/76693035e5db2f26f5c3f264f5811300b0c8c168
I have tested it on hours of video and it certainly solves this particular problem, but I don't know boost::python well know to be sure that it's complete.
Thanks!
On Sat, Jan 27, 2018 at 1:29 PM, Lieven Govaerts [email protected] wrote:
This change fixes the memory leak in the python wrapper:
lgov/bgslibrary@7669303 https://github.com/lgov/bgslibrary/commit/76693035e5db2f26f5c3f264f5811300b0c8c168
I have tested it on hours of video and it certainly solves this particular problem, but I don't know boost::python well know to be sure that it's complete.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andrewssobral/bgslibrary/issues/72#issuecomment-361016660, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJwrBDqOCId5lwF13AVV_g4iU4kRIBbks5tO5UcgaJpZM4Ngd9M .
-- Ben Weinstein, Ph.D. Postdoctoral Fellow Oregon State University http://benweinstein.weebly.com/
Can confirm. No more memory leak. Tested with openCV3 and Python3. Thank you!
Thank you very much @lgov ! I applied a patch from your branch to fix the memory leak. I let this issue open to check for OpenCV 2.
Thank you very much @lgov the device is TX2 with OpenCV3.3 + OpenCV-contrib