1adrianb / face-alignment

:fire: 2D and 3D Face alignment library build using pytorch
https://www.adrianbulat.com
BSD 3-Clause "New" or "Revised" License
7.05k stars 1.34k forks source link

Memory leak #136

Closed ierezell closed 5 years ago

ierezell commented 5 years ago

System : Linux (Archlinux) Package : Installed from pip (pip install face-alignement)

Code (inside a pytorch Dataset):

import cv2
import numpy as np
import glob
from face_alignment import FaceAlignment, LandmarksType
face_landmarks = FaceAlignment(LandmarksType._2D, device='cpu')

mp4files = glob.glob(f"./dataset/mp4/*/*/*")
for file in mp4files:
    video = cv2.VideoCapture(file)
    _, gt_im = video.read()
    # landmarks = face_landmarks.get_landmarks_from_image(gt_im)[0]
    video.release()

mp4files correspond to the videos of the dataset VoxCeleb2.

Expected behaviour : Load landmarks normally Real behaviour : Ram keep increasing more and more until process is killed

Everything before works fine and ram is okay, problem arise when loading landmarks.

ierezell commented 5 years ago

Fixed by leaving torch.set_grad_enabled() to True in api.py l.181 (commit 01b75a9)

I don't know why pytorch don't like to have other network inside a dataloader...

Plus : cannot use num_workers in the pytorch dataLoader. Because the loader create multiple threads to load faster --> each thread will call the facealignement network and try to put images to GPU in parrallel which causes troubles.

Anyway with default behaviour (no thread, data loaded in the main process) everything is okay.

Thanks a lot for this beautiful and so usefull Api !

marisancans commented 4 years ago

Im also getting this problem, installed it from conda