-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
51 lines (43 loc) · 2.07 KB
/
config.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Configuration file for 3D face reconstruction and editing pipeline.
Contains all paths and parameters used across the application.
"""
from pathlib import Path
import yaml
class Config:
def __init__(self,input_dir, output_dir):
# Directory paths
self.current_directory = Path.cwd()
self.input_dir = input_dir
self.output_dir = output_dir
# Model paths
self.psp_model_path = self.current_directory / "pretrained_models/restyle_pSp_ffhq.pt"
self.e4e_model_path = self.current_directory / "pretrained_models/restyle_e4e_ffhq.pt"
self.shape_predictor_path = self.current_directory / "pretrained_models/shape_predictor_68_face_landmarks.dat"
self.threeddfa_configs_path = self.current_directory / "ThreeDDFA_configs/mb1_120x120.yml"
# Load 3DDFA configs
self.threeddfa_config = self._load_threeddfa_config()
def _load_threeddfa_config(self):
"""Load and process 3DDFA configuration file."""
try:
with open(self.threeddfa_configs_path) as f:
cfg = yaml.safe_load(f)
return {
**cfg,
'checkpoint_fp': str(self.current_directory / cfg['checkpoint_fp']),
'bfm_fp': str(self.current_directory / cfg['bfm_fp'])
}
except Exception as e:
raise RuntimeError(f"Failed to load 3DDFA config: {str(e)}")
def get_output_paths(self):
"""Generate output file paths based on input image path."""
# Use the input_path to get the base name
base_name = self.input_dir.split("/")[-1].replace(".png", "")
# Define the output directory and ensure it exists
output_dir = Path(self.output_dir) # Convert to Path object
output_dir.mkdir(parents=True, exist_ok=True) # Create the directory if it does not exist
return {
'pose': output_dir / f"{base_name}_pose.png",
'uv_tex': output_dir / f"{base_name}_uv_tex.png",
'obj': output_dir / f"{base_name}_obj.obj"
}