Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leakage in .predict - Repeatedly calling .predict(...) results in memory leak #39

Open
rhiskey opened this issue Feb 3, 2022 · 0 comments

Comments

@rhiskey
Copy link

rhiskey commented Feb 3, 2022

Im trying to call face_detector.predict(rgb_img, thresh) just about 100 times/second and each time it causes memory increment just around 1.3-8.0 Mb.

    def crop_faces_from_numpy_image(self, numpy_rgb):
        bboxes = self.face_detector.predict(numpy_rgb, self.thresh)
        cropped_images_array = []

        for bbox in bboxes:
            xc = bbox[0]
            yc = bbox[1]
            w = bbox[2]
            h = bbox[3]

            face = self.cv2_image[yc - h:yc + h, xc - w:xc + w]
            if len(face) > 0:
                resized = cv2.resize(face, dim)
                cropped_images_array.append(resized)

        return cropped_images_array
    def numpy_image_from_bytes(self, data):
        cv2img = cv2.imdecode(np.frombuffer(data, np.uint8), -1)
        self.cv2_image = cv2img
        np_rgb = cv2.cvtColor(cv2img.copy(), cv2.COLOR_BGR2RGB)
        return np_rgb
Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
    23    796.0 MiB    796.0 MiB           1   @profile
    24                                         def crop_and_save(barr_img):
    25    797.3 MiB      1.3 MiB           1       np_arr = fd_worker.numpy_image_from_bytes(barr_img)
    26    805.3 MiB      8.0 MiB           1       cropped_arr = fd_worker.crop_faces_from_numpy_image(np_arr) - here is leakage
    27    805.5 MiB      0.2 MiB           1       fd_worker.save_images(cropped_arr)
    28    805.5 MiB      0.0 MiB           1       del np_arr
    29    805.5 MiB      0.0 MiB           1       del cropped_arr
    30    805.5 MiB      0.0 MiB           1       gc.collect()

Python 3.8

@rhiskey rhiskey changed the title Memory leakage in .predict Memory leakage in .predict - Repeatedly calling .predict(...) results in memory leak Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant