serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
11.82k stars 2.02k forks source link

i am using Rtx 3090 24 GB RAM the DeepFace utilize all the memmory of gpu how can i control its utilization #315

Closed Uzair1947 closed 3 years ago

serengil commented 3 years ago

Especially analyze method requires many complex models. unfortunately, nothing to do. I recommend you to use cpu.

Uzair1947 commented 3 years ago

ok thanks how can I shift the load to the CPU

serengil commented 3 years ago

import os os.environ["CUDA_VISIBLE_DEVICES"]=""

or

os.environ["CUDA_VISIBLE_DEVICES"]="-1"

12bitmisfit commented 3 years ago

I could be wrong but I think tensorflow by default allocates all available GPU memory.

This worked for me:

import tensorflow as tf
tf.config.set_visible_devices([], 'GPU')
gpus = tf.config.experimental.list_physical_devices('GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)
sharkykittens commented 2 years ago

I could be wrong but I think tensorflow by default allocates all available GPU memory.

This worked for me:

import tensorflow as tf
tf.config.set_visible_devices([], 'GPU')
gpus = tf.config.experimental.list_physical_devices('GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)

Thanks for this, I've seen other projects where tensorflow allocates all available memory as well, however when running your code deepface ended up not using gpu at all. I made just a small tweak to your code to get deepface to use gpu but not allocate all available memory:

import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.set_visible_devices(gpus, 'GPU')
for gpu in gpus:
    print(gpu)
    tf.config.experimental.set_memory_growth(gpu, True)