cristopher.salyrosas commited on
Commit
fa2b22b
·
1 Parent(s): f7440a1

reduceRAMusage

Browse files
Files changed (3) hide show
  1. app.py +8 -1
  2. facial_auth.py +1 -14
  3. packages.txt +0 -6
app.py CHANGED
@@ -19,8 +19,11 @@ import sys
19
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
20
 
21
  if sys.platform.startswith("linux"):
22
- # En la nube (Streamlit Cloud - Linux): Prevenir Segmentation Fault por choque de librerías CUDNN
23
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
 
 
 
24
  else:
25
  # En local (Windows): Permitir el uso de la GPU (RTX 3060) y prevenir crash silencioso de OpenMP
26
  os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
@@ -28,6 +31,10 @@ else:
28
  import tensorflow as tf
29
  import torch
30
 
 
 
 
 
31
  # Configurar TensorFlow para compartir la GPU de forma amigable con PyTorch (solo útil en local)
32
  gpus = tf.config.list_physical_devices('GPU')
33
  if gpus:
 
19
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
20
 
21
  if sys.platform.startswith("linux"):
22
+ # En la nube (Streamlit Cloud - Linux): Prevenir OOM (Out of Memory) y Segmentation Fault
23
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
24
+ os.environ["OMP_NUM_THREADS"] = "1"
25
+ os.environ["MKL_NUM_THREADS"] = "1"
26
+ os.environ["OPENBLAS_NUM_THREADS"] = "1"
27
  else:
28
  # En local (Windows): Permitir el uso de la GPU (RTX 3060) y prevenir crash silencioso de OpenMP
29
  os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
 
31
  import tensorflow as tf
32
  import torch
33
 
34
+ if sys.platform.startswith("linux"):
35
+ torch.set_num_threads(1)
36
+ cv2.setNumThreads(1)
37
+
38
  # Configurar TensorFlow para compartir la GPU de forma amigable con PyTorch (solo útil en local)
39
  gpus = tf.config.list_physical_devices('GPU')
40
  if gpus:
facial_auth.py CHANGED
@@ -33,20 +33,7 @@ class FacialAuthenticator:
33
  self.model_name = "Facenet"
34
  self.executor = ThreadPoolExecutor(max_workers=2)
35
 
36
- # Opcional: pre-crear embeddings si ya hay imágenes
37
- if DEEPFACE_AVAILABLE and os.listdir(self.db_path):
38
- try:
39
- # Pre-cargar representaciones (pkl)
40
- _ = DeepFace.find(
41
- img_path=np.zeros((224, 224, 3), dtype=np.uint8),
42
- db_path=self.db_path,
43
- model_name=self.model_name,
44
- detector_backend="opencv",
45
- enforce_detection=False,
46
- silent=True
47
- )
48
- except:
49
- pass
50
 
51
  def authenticate_async(self, frame_crop: np.ndarray, track, callback=None):
52
  """
 
33
  self.model_name = "Facenet"
34
  self.executor = ThreadPoolExecutor(max_workers=2)
35
 
36
+ # Eliminado el pre-calentamiento de DeepFace para evitar pico de memoria OOM en el arranque de Streamlit Cloud
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def authenticate_async(self, frame_crop: np.ndarray, track, callback=None):
39
  """
packages.txt CHANGED
@@ -1,6 +0,0 @@
1
- libgl1
2
- libglib2.0-0t64
3
- libsm6
4
- libxext6
5
- libxrender1
6
- ffmpeg