primerz commited on
Commit
be008fd
·
verified ·
1 Parent(s): 44cf7f3

Update models.py

Browse files
Files changed (1) hide show
  1. models.py +5 -63
models.py CHANGED
@@ -59,70 +59,12 @@ def download_model_with_retry(repo_id, filename, max_retries=None):
59
 
60
 
61
  def load_face_analysis():
62
- """Load face analysis model with intelligent provider selection."""
63
- print("Loading face analysis model...")
64
-
65
- # Determine provider preference from config
66
- prefer_cpu = FACE_DETECTION_CONFIG.get('prefer_cpu', True)
67
-
68
- if prefer_cpu:
69
- # CPU-first configuration for memory efficiency
70
- provider_configs = [
71
- (['CPUExecutionProvider'], -1, "CPU (memory efficient)"),
72
- (['CUDAExecutionProvider', 'CPUExecutionProvider'], 0, "GPU with CPU fallback"),
73
- (None, 0, "auto-detect")
74
- ]
75
- else:
76
- # GPU-first configuration for speed
77
- provider_configs = [
78
- (['CUDAExecutionProvider', 'CPUExecutionProvider'], 0, "GPU with CPU fallback"),
79
- (['CPUExecutionProvider'], -1, "CPU only"),
80
- (None, 0, "auto-detect")
81
- ]
82
-
83
- print(f" Provider preference: {'CPU (memory efficient)' if prefer_cpu else 'GPU (faster)'}")
84
-
85
- for providers, ctx_id, provider_desc in provider_configs:
86
- try:
87
- print(f" Attempting with {provider_desc}...")
88
-
89
- if providers:
90
- face_app = FaceAnalysis(
91
- name=FACE_DETECTION_CONFIG['model_name'],
92
- root='./models/insightface',
93
- providers=providers
94
- )
95
- else:
96
- # Let InsightFace choose providers automatically
97
- face_app = FaceAnalysis(
98
- name=FACE_DETECTION_CONFIG['model_name'],
99
- root='./models/insightface'
100
- )
101
-
102
- face_app.prepare(
103
- ctx_id=ctx_id,
104
- det_size=FACE_DETECTION_CONFIG['det_size']
105
- )
106
-
107
- # Test the model to ensure it works
108
- import numpy as np
109
- test_img = np.zeros((640, 640, 3), dtype=np.uint8)
110
- _ = face_app.get(test_img)
111
-
112
- print(f" [OK] Face analysis model loaded with {provider_desc}")
113
- return face_app, True
114
-
115
- except Exception as e:
116
- error_msg = str(e)[:200] if str(e) else "Unknown error"
117
- print(f" [INFO] {provider_desc} failed: {error_msg}")
118
- continue
119
-
120
- # All attempts failed
121
- print(" [WARNING] Face detection not available - all providers failed")
122
- print(" [INFO] Generation will continue without face preservation")
123
- print(" [TIP] Check that onnxruntime or onnxruntime-gpu is properly installed")
124
- return None, False
125
 
 
 
 
 
 
126
 
127
  def load_depth_detector():
128
  """Load Zoe Depth detector with optimized memory management."""
 
59
 
60
 
61
  def load_face_analysis():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ antelope_download = snapshot_download(repo_id="DIAMONIK7777/antelopev2", local_dir="/data/models/antelopev2")
64
+ face_app = FaceAnalysis(name='antelopev2', root='/data', providers=['CPUExecutionProvider'])
65
+ face_app.prepare(ctx_id=0, det_size=(640, 640))
66
+
67
+ return face_app, True
68
 
69
  def load_depth_detector():
70
  """Load Zoe Depth detector with optimized memory management."""