File size: 920 Bytes
f10370d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# preload.py (Stored in ~/.deepface/weights/ directory)

import deepface
import os

print("--- Starting DeepFace Model Preloading ---")

# 1. Force download and initialization of FaceNet (for embeddings)
print("Loading FaceNet model (128-dimensional embeddings)...")
try:
    # Use dot notation for DeepFace submodules to avoid Pylance errors
    model_facenet = deepface.basemodels.FaceNet.loadModel() 
    print("✅ FaceNet loaded successfully.")
except Exception as e:
    print(f"❌ Error loading FaceNet: {e}")

# 2. Force download and initialization of MTCNN (CNN-based detection)
print("Loading MTCNN detector (CNN-based detection)...")
try:
    # Use dot notation for DeepFace submodules
    detector_mtcnn = deepface.detectors.FaceDetector.build_model('mtcnn') 
    print("✅ MTCNN loaded successfully.")
except Exception as e:
    print(f"❌ Error loading MTCNN: {e}")

print("--- Preloading Complete ---")