Compare commits
6 Commits
4983c73388
...
630ad81d35
Author | SHA1 | Date |
---|---|---|
|
630ad81d35 | |
|
ec6d7d2995 | |
|
e791f2f18a | |
|
3795e41fd7 | |
|
de27fb8a81 | |
|
130f096cd5 |
|
@ -188,7 +188,10 @@ pip install -r requirements.txt
|
|||
**CUDA Execution Provider (Nvidia)**
|
||||
|
||||
1. Install [CUDA Toolkit 11.8.0](https://developer.nvidia.com/cuda-11-8-0-download-archive)
|
||||
2. Install dependencies:
|
||||
2. Install [cuDNN v8.9.7 for CUDA 11.x](https://developer.nvidia.com/rdp/cudnn-archive) (required for onnxruntime-gpu):
|
||||
- Download cuDNN v8.9.7 for CUDA 11.x
|
||||
- Make sure the cuDNN bin directory is in your system PATH
|
||||
3. Install dependencies:
|
||||
|
||||
```bash
|
||||
pip uninstall onnxruntime onnxruntime-gpu
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"Source x Target Mapper": "소스 x 타겟 매퍼",
|
||||
"select a source image": "소스 이미지 선택",
|
||||
"Preview": "미리보기",
|
||||
"select a target image or video": "타겟 이미지 또는 영상 선택",
|
||||
"save image output file": "이미지 출력 파일 저장",
|
||||
"save video output file": "영상 출력 파일 저장",
|
||||
"select a target image": "타겟 이미지 선택",
|
||||
"source": "소스",
|
||||
"Select a target": "타겟 선택",
|
||||
"Select a face": "얼굴 선택",
|
||||
"Keep audio": "오디오 유지",
|
||||
"Face Enhancer": "얼굴 향상",
|
||||
"Many faces": "여러 얼굴",
|
||||
"Show FPS": "FPS 표시",
|
||||
"Keep fps": "FPS 유지",
|
||||
"Keep frames": "프레임 유지",
|
||||
"Fix Blueish Cam": "푸른빛 카메라 보정",
|
||||
"Mouth Mask": "입 마스크",
|
||||
"Show Mouth Mask Box": "입 마스크 박스 표시",
|
||||
"Start": "시작",
|
||||
"Live": "라이브",
|
||||
"Destroy": "종료",
|
||||
"Map faces": "얼굴 매핑",
|
||||
"Processing...": "처리 중...",
|
||||
"Processing succeed!": "처리 성공!",
|
||||
"Processing ignored!": "처리 무시됨!",
|
||||
"Failed to start camera": "카메라 시작 실패",
|
||||
"Please complete pop-up or close it.": "팝업을 완료하거나 닫아주세요.",
|
||||
"Getting unique faces": "고유 얼굴 가져오는 중",
|
||||
"Please select a source image first": "먼저 소스 이미지를 선택해주세요",
|
||||
"No faces found in target": "타겟에서 얼굴을 찾을 수 없음",
|
||||
"Add": "추가",
|
||||
"Clear": "지우기",
|
||||
"Submit": "제출",
|
||||
"Select source image": "소스 이미지 선택",
|
||||
"Select target image": "타겟 이미지 선택",
|
||||
"Please provide mapping!": "매핑을 입력해주세요!",
|
||||
"At least 1 source with target is required!": "최소 하나의 소스와 타겟이 필요합니다!",
|
||||
"Face could not be detected in last upload!": "최근 업로드에서 얼굴을 감지할 수 없습니다!",
|
||||
"Select Camera:": "카메라 선택:",
|
||||
"All mappings cleared!": "모든 매핑이 삭제되었습니다!",
|
||||
"Mappings successfully submitted!": "매핑이 성공적으로 제출되었습니다!",
|
||||
"Source x Target Mapper is already open.": "소스 x 타겟 매퍼가 이미 열려 있습니다."
|
||||
}
|
|
@ -1,12 +1,129 @@
|
|||
import sys
|
||||
import importlib
|
||||
from typing import Set, Optional
|
||||
|
||||
# Define a whitelist of allowed modules that can be dynamically imported
|
||||
ALLOWED_MODULES: Set[str] = {
|
||||
'modules.processors.frame.blur',
|
||||
'modules.processors.frame.censor',
|
||||
'modules.processors.frame.crop',
|
||||
'modules.processors.frame.resize',
|
||||
'modules.processors.frame.rotate',
|
||||
# Add all legitimate processor modules that should be importable
|
||||
}
|
||||
|
||||
def safe_import_module(module_name: str) -> Optional[object]:
|
||||
"""
|
||||
Safely import a module by checking against a whitelist.
|
||||
|
||||
Args:
|
||||
module_name: The name of the module to import
|
||||
|
||||
Returns:
|
||||
The imported module or None if the module is not in the whitelist
|
||||
"""
|
||||
if module_name in ALLOWED_MODULES:
|
||||
return safe_import_module(module_name)
|
||||
else:
|
||||
# Log the attempt to import a non-whitelisted module
|
||||
print(f"Warning: Attempted to import non-whitelisted module: {module_name}")
|
||||
return None
|
||||
|
||||
import importlib
|
||||
from typing import Set, Optional
|
||||
|
||||
# Define a whitelist of allowed modules that can be dynamically imported
|
||||
ALLOWED_MODULES: Set[str] = {
|
||||
'modules.processors.frame.blur',
|
||||
'modules.processors.frame.censor',
|
||||
'modules.processors.frame.crop',
|
||||
'modules.processors.frame.resize',
|
||||
'modules.processors.frame.rotate',
|
||||
# Add all legitimate processor modules that should be importable
|
||||
}
|
||||
|
||||
def safe_import_module(module_name: str) -> Optional[object]:
|
||||
"""
|
||||
Safely import a module by checking against a whitelist.
|
||||
|
||||
Args:
|
||||
module_name: The name of the module to import
|
||||
|
||||
Returns:
|
||||
The imported module or None if the module is not in the whitelist
|
||||
"""
|
||||
if module_name in ALLOWED_MODULES:
|
||||
return safe_import_module(module_name)
|
||||
else:
|
||||
# Log the attempt to import a non-whitelisted module
|
||||
print(f"Warning: Attempted to import non-whitelisted module: {module_name}")
|
||||
return None
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from types import ModuleType
|
||||
from typing import Any, List, Callable
|
||||
from tqdm import tqdm
|
||||
|
||||
import modules
|
||||
import modules.globals
|
||||
import importlib
|
||||
from typing import Set, Optional
|
||||
|
||||
# Define a whitelist of allowed modules that can be dynamically imported
|
||||
ALLOWED_MODULES: Set[str] = {
|
||||
'modules.processors.frame.blur',
|
||||
'modules.processors.frame.censor',
|
||||
'modules.processors.frame.crop',
|
||||
'modules.processors.frame.resize',
|
||||
'modules.processors.frame.rotate',
|
||||
# Add all legitimate processor modules that should be importable
|
||||
}
|
||||
|
||||
def safe_import_module(module_name: str) -> Optional[object]:
|
||||
"""
|
||||
Safely import a module by checking against a whitelist.
|
||||
|
||||
Args:
|
||||
module_name: The name of the module to import
|
||||
|
||||
Returns:
|
||||
The imported module or None if the module is not in the whitelist
|
||||
"""
|
||||
if module_name in ALLOWED_MODULES:
|
||||
return safe_import_module(module_name)
|
||||
else:
|
||||
# Log the attempt to import a non-whitelisted module
|
||||
print(f"Warning: Attempted to import non-whitelisted module: {module_name}")
|
||||
return None
|
||||
|
||||
import importlib
|
||||
from typing import Set, Optional
|
||||
|
||||
# Define a whitelist of allowed modules that can be dynamically imported
|
||||
ALLOWED_MODULES: Set[str] = {
|
||||
'modules.processors.frame.blur',
|
||||
'modules.processors.frame.censor',
|
||||
'modules.processors.frame.crop',
|
||||
'modules.processors.frame.resize',
|
||||
'modules.processors.frame.rotate',
|
||||
# Add all legitimate processor modules that should be importable
|
||||
}
|
||||
|
||||
def safe_import_module(module_name: str) -> Optional[object]:
|
||||
"""
|
||||
Safely import a module by checking against a whitelist.
|
||||
|
||||
Args:
|
||||
module_name: The name of the module to import
|
||||
|
||||
Returns:
|
||||
The imported module or None if the module is not in the whitelist
|
||||
"""
|
||||
if module_name in ALLOWED_MODULES:
|
||||
return safe_import_module(module_name)
|
||||
else:
|
||||
# Log the attempt to import a non-whitelisted module
|
||||
print(f"Warning: Attempted to import non-whitelisted module: {module_name}")
|
||||
return None
|
||||
|
||||
|
||||
FRAME_PROCESSORS_MODULES: List[ModuleType] = []
|
||||
FRAME_PROCESSORS_INTERFACE = [
|
||||
|
@ -20,7 +137,7 @@ FRAME_PROCESSORS_INTERFACE = [
|
|||
|
||||
def load_frame_processor_module(frame_processor: str) -> Any:
|
||||
try:
|
||||
frame_processor_module = importlib.import_module(f'modules.processors.frame.{frame_processor}')
|
||||
frame_processor_module = safe_import_module(f'modules.processors.frame.{frame_processor}')
|
||||
for method_name in FRAME_PROCESSORS_INTERFACE:
|
||||
if not hasattr(frame_processor_module, method_name):
|
||||
sys.exit()
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
import sys
|
||||
import importlib
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from types import ModuleType
|
||||
from typing import Any, List, Callable
|
||||
from tqdm import tqdm
|
||||
|
||||
import modules
|
||||
import modules.globals
|
||||
|
||||
FRAME_PROCESSORS_MODULES: List[ModuleType] = []
|
||||
FRAME_PROCESSORS_INTERFACE = [
|
||||
'pre_check',
|
||||
'pre_start',
|
||||
'process_frame',
|
||||
'process_image',
|
||||
'process_video'
|
||||
]
|
||||
|
||||
|
||||
def load_frame_processor_module(frame_processor: str) -> Any:
|
||||
try:
|
||||
frame_processor_module = importlib.import_module(f'modules.processors.frame.{frame_processor}')
|
||||
for method_name in FRAME_PROCESSORS_INTERFACE:
|
||||
if not hasattr(frame_processor_module, method_name):
|
||||
sys.exit()
|
||||
except ImportError:
|
||||
print(f"Frame processor {frame_processor} not found")
|
||||
sys.exit()
|
||||
return frame_processor_module
|
||||
|
||||
|
||||
def get_frame_processors_modules(frame_processors: List[str]) -> List[ModuleType]:
|
||||
global FRAME_PROCESSORS_MODULES
|
||||
|
||||
if not FRAME_PROCESSORS_MODULES:
|
||||
for frame_processor in frame_processors:
|
||||
frame_processor_module = load_frame_processor_module(frame_processor)
|
||||
FRAME_PROCESSORS_MODULES.append(frame_processor_module)
|
||||
set_frame_processors_modules_from_ui(frame_processors)
|
||||
return FRAME_PROCESSORS_MODULES
|
||||
|
||||
def set_frame_processors_modules_from_ui(frame_processors: List[str]) -> None:
|
||||
global FRAME_PROCESSORS_MODULES
|
||||
current_processor_names = [proc.__name__.split('.')[-1] for proc in FRAME_PROCESSORS_MODULES]
|
||||
|
||||
for frame_processor, state in modules.globals.fp_ui.items():
|
||||
if state == True and frame_processor not in current_processor_names:
|
||||
try:
|
||||
frame_processor_module = load_frame_processor_module(frame_processor)
|
||||
FRAME_PROCESSORS_MODULES.append(frame_processor_module)
|
||||
if frame_processor not in modules.globals.frame_processors:
|
||||
modules.globals.frame_processors.append(frame_processor)
|
||||
except SystemExit:
|
||||
print(f"Warning: Failed to load frame processor {frame_processor} requested by UI state.")
|
||||
except Exception as e:
|
||||
print(f"Warning: Error loading frame processor {frame_processor} requested by UI state: {e}")
|
||||
|
||||
elif state == False and frame_processor in current_processor_names:
|
||||
try:
|
||||
module_to_remove = next((mod for mod in FRAME_PROCESSORS_MODULES if mod.__name__.endswith(f'.{frame_processor}')), None)
|
||||
if module_to_remove:
|
||||
FRAME_PROCESSORS_MODULES.remove(module_to_remove)
|
||||
if frame_processor in modules.globals.frame_processors:
|
||||
modules.globals.frame_processors.remove(frame_processor)
|
||||
except Exception as e:
|
||||
print(f"Warning: Error removing frame processor {frame_processor}: {e}")
|
||||
|
||||
def multi_process_frame(source_path: str, temp_frame_paths: List[str], process_frames: Callable[[str, List[str], Any], None], progress: Any = None) -> None:
|
||||
with ThreadPoolExecutor(max_workers=modules.globals.execution_threads) as executor:
|
||||
futures = []
|
||||
for path in temp_frame_paths:
|
||||
future = executor.submit(process_frames, source_path, [path], progress)
|
||||
futures.append(future)
|
||||
for future in futures:
|
||||
future.result()
|
||||
|
||||
|
||||
def process_video(source_path: str, frame_paths: list[str], process_frames: Callable[[str, List[str], Any], None]) -> None:
|
||||
progress_bar_format = '{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]'
|
||||
total = len(frame_paths)
|
||||
with tqdm(total=total, desc='Processing', unit='frame', dynamic_ncols=True, bar_format=progress_bar_format) as progress:
|
||||
progress.set_postfix({'execution_providers': modules.globals.execution_providers, 'execution_threads': modules.globals.execution_threads, 'max_memory': modules.globals.max_memory})
|
||||
multi_process_frame(source_path, frame_paths, process_frames, progress)
|
Loading…
Reference in New Issue