Spaces:
Paused
Paused
Update SwitcherAI/processors/frame/modules/face_swapper.py
Browse files
SwitcherAI/processors/frame/modules/face_swapper.py
CHANGED
|
@@ -20,10 +20,10 @@ EMBEDDING_CONVERTER = None
|
|
| 20 |
THREAD_LOCK = threading.Lock()
|
| 21 |
NAME = 'FACEFUSION.FRAME_PROCESSOR.FACE_SWAPPER'
|
| 22 |
|
| 23 |
-
# Model configurations
|
| 24 |
MODEL_CONFIGS = {
|
| 25 |
'inswapper_128': {
|
| 26 |
-
'url': 'https://
|
| 27 |
'path': '../.assets/models/inswapper_128.onnx',
|
| 28 |
'type': 'inswapper',
|
| 29 |
'size': (128, 128),
|
|
@@ -32,7 +32,7 @@ MODEL_CONFIGS = {
|
|
| 32 |
'requires_converter': False
|
| 33 |
},
|
| 34 |
'inswapper_128_fp16': {
|
| 35 |
-
'url': 'https://
|
| 36 |
'path': '../.assets/models/inswapper_128_fp16.onnx',
|
| 37 |
'type': 'inswapper',
|
| 38 |
'size': (128, 128),
|
|
@@ -41,15 +41,15 @@ MODEL_CONFIGS = {
|
|
| 41 |
'requires_converter': False
|
| 42 |
},
|
| 43 |
'simswap_256': {
|
| 44 |
-
'url': 'https://
|
| 45 |
'path': '../.assets/models/simswap_256.onnx',
|
| 46 |
'type': 'simswap',
|
| 47 |
'size': (256, 256),
|
| 48 |
'mean': [0.485, 0.456, 0.406],
|
| 49 |
'standard_deviation': [0.229, 0.224, 0.225],
|
| 50 |
'requires_converter': True,
|
| 51 |
-
'converter_url': 'https://
|
| 52 |
-
'converter_path': '../.assets/models/
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
|
@@ -136,6 +136,40 @@ def get_frame_processor() -> Any:
|
|
| 136 |
|
| 137 |
except Exception as e:
|
| 138 |
print(f"❌ Failed to load {model_name}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
continue
|
| 140 |
|
| 141 |
if FRAME_PROCESSOR is None:
|
|
|
|
| 20 |
THREAD_LOCK = threading.Lock()
|
| 21 |
NAME = 'FACEFUSION.FRAME_PROCESSOR.FACE_SWAPPER'
|
| 22 |
|
| 23 |
+
# Model configurations with working public URLs
|
| 24 |
MODEL_CONFIGS = {
|
| 25 |
'inswapper_128': {
|
| 26 |
+
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx',
|
| 27 |
'path': '../.assets/models/inswapper_128.onnx',
|
| 28 |
'type': 'inswapper',
|
| 29 |
'size': (128, 128),
|
|
|
|
| 32 |
'requires_converter': False
|
| 33 |
},
|
| 34 |
'inswapper_128_fp16': {
|
| 35 |
+
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128_fp16.onnx',
|
| 36 |
'path': '../.assets/models/inswapper_128_fp16.onnx',
|
| 37 |
'type': 'inswapper',
|
| 38 |
'size': (128, 128),
|
|
|
|
| 41 |
'requires_converter': False
|
| 42 |
},
|
| 43 |
'simswap_256': {
|
| 44 |
+
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models/simswap_256.onnx',
|
| 45 |
'path': '../.assets/models/simswap_256.onnx',
|
| 46 |
'type': 'simswap',
|
| 47 |
'size': (256, 256),
|
| 48 |
'mean': [0.485, 0.456, 0.406],
|
| 49 |
'standard_deviation': [0.229, 0.224, 0.225],
|
| 50 |
'requires_converter': True,
|
| 51 |
+
'converter_url': 'https://github.com/facefusion/facefusion-assets/releases/download/models/arcface_w600k_r50.onnx',
|
| 52 |
+
'converter_path': '../.assets/models/arcface_w600k_r50.onnx'
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
|
|
|
| 136 |
|
| 137 |
except Exception as e:
|
| 138 |
print(f"❌ Failed to load {model_name}: {e}")
|
| 139 |
+
|
| 140 |
+
# If protobuf parsing failed, delete the corrupted file and try to re-download
|
| 141 |
+
if "INVALID_PROTOBUF" in str(e) or "Protobuf parsing failed" in str(e):
|
| 142 |
+
print(f"🗑️ Deleting corrupted {model_name} file...")
|
| 143 |
+
try:
|
| 144 |
+
if model_path_obj.exists():
|
| 145 |
+
model_path_obj.unlink()
|
| 146 |
+
print(f"📥 Re-downloading {model_name}...")
|
| 147 |
+
|
| 148 |
+
download_directory_path = resolve_relative_path('../.assets/models')
|
| 149 |
+
if isinstance(download_directory_path, str):
|
| 150 |
+
download_directory_path = Path(download_directory_path)
|
| 151 |
+
download_directory_path.mkdir(parents=True, exist_ok=True)
|
| 152 |
+
|
| 153 |
+
download_urls = [temp_config['url']]
|
| 154 |
+
if temp_config.get('requires_converter', False):
|
| 155 |
+
download_urls.append(temp_config['converter_url'])
|
| 156 |
+
|
| 157 |
+
conditional_download(str(download_directory_path), download_urls)
|
| 158 |
+
|
| 159 |
+
# Try loading again after re-download
|
| 160 |
+
if model_path_obj.exists() and model_path_obj.stat().st_size > 1024:
|
| 161 |
+
print(f"🔄 Retrying {model_name} after re-download...")
|
| 162 |
+
FRAME_PROCESSOR = insightface.model_zoo.get_model(
|
| 163 |
+
str(model_path_obj),
|
| 164 |
+
providers=SwitcherAI.globals.execution_providers
|
| 165 |
+
)
|
| 166 |
+
# If successful, update the global setting and break
|
| 167 |
+
SwitcherAI.globals.face_swapper_model = model_name
|
| 168 |
+
print(f"✅ Successfully loaded face swap model: {model_name}")
|
| 169 |
+
break
|
| 170 |
+
except Exception as retry_error:
|
| 171 |
+
print(f"❌ Retry failed for {model_name}: {retry_error}")
|
| 172 |
+
|
| 173 |
continue
|
| 174 |
|
| 175 |
if FRAME_PROCESSOR is None:
|