Upload 4 files
Browse files
processors/modules/age_modifier/choices.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Sequence, get_args
|
| 2 |
+
|
| 3 |
+
from facefusion.common_helper import create_int_range
|
| 4 |
+
from facefusion.processors.modules.age_modifier.types import AgeModifierModel
|
| 5 |
+
|
| 6 |
+
age_modifier_models : List[AgeModifierModel] = list(get_args(AgeModifierModel))
|
| 7 |
+
|
| 8 |
+
age_modifier_direction_range : Sequence[int] = create_int_range(-100, 100, 1)
|
processors/modules/age_modifier/core.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from argparse import ArgumentParser
|
| 2 |
+
from functools import lru_cache
|
| 3 |
+
from types import ModuleType
|
| 4 |
+
from typing import List
|
| 5 |
+
|
| 6 |
+
import cv2
|
| 7 |
+
import numpy
|
| 8 |
+
|
| 9 |
+
import facefusion.choices
|
| 10 |
+
import facefusion.jobs.job_manager
|
| 11 |
+
import facefusion.jobs.job_store
|
| 12 |
+
from facefusion import config, content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, inference_manager, logger, state_manager, translator, video_manager
|
| 13 |
+
from facefusion.common_helper import create_int_metavar, get_middle
|
| 14 |
+
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url
|
| 15 |
+
from facefusion.face_creator import scale_face
|
| 16 |
+
from facefusion.face_helper import merge_matrix, paste_back, scale_face_landmark_5, warp_face_by_face_landmark_5
|
| 17 |
+
from facefusion.face_masker import create_box_mask, create_occlusion_mask
|
| 18 |
+
from facefusion.face_selector import select_faces
|
| 19 |
+
from facefusion.filesystem import in_directory, is_image, is_video, resolve_relative_path, same_file_extension
|
| 20 |
+
from facefusion.processors.modules.age_modifier import choices as age_modifier_choices
|
| 21 |
+
from facefusion.processors.modules.age_modifier.types import AgeModifierDirection, AgeModifierInputs
|
| 22 |
+
from facefusion.processors.types import ProcessorOutputs
|
| 23 |
+
from facefusion.program_helper import find_argument_group
|
| 24 |
+
from facefusion.thread_helper import thread_semaphore
|
| 25 |
+
from facefusion.types import ApplyStateItem, Args, DownloadScope, Face, InferencePool, ModelOptions, ModelSet, ProcessMode, VisionFrame
|
| 26 |
+
from facefusion.vision import match_frame_color, read_static_image, read_static_video_frame
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@lru_cache()
|
| 30 |
+
def create_static_model_set(download_scope : DownloadScope) -> ModelSet:
|
| 31 |
+
return\
|
| 32 |
+
{
|
| 33 |
+
'fran':
|
| 34 |
+
{
|
| 35 |
+
'__metadata__':
|
| 36 |
+
{
|
| 37 |
+
'vendor': 'ry-lu',
|
| 38 |
+
'license': 'mit',
|
| 39 |
+
'year': 2024
|
| 40 |
+
},
|
| 41 |
+
'hashes':
|
| 42 |
+
{
|
| 43 |
+
'age_modifier':
|
| 44 |
+
{
|
| 45 |
+
'url': resolve_download_url('models-3.6.0', 'fran.hash'),
|
| 46 |
+
'path': resolve_relative_path('../.assets/models/fran.hash')
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
'sources':
|
| 50 |
+
{
|
| 51 |
+
'age_modifier':
|
| 52 |
+
{
|
| 53 |
+
'url': resolve_download_url('models-3.6.0', 'fran.onnx'),
|
| 54 |
+
'path': resolve_relative_path('../.assets/models/fran.onnx')
|
| 55 |
+
}
|
| 56 |
+
},
|
| 57 |
+
'templates':
|
| 58 |
+
{
|
| 59 |
+
'target': 'ffhq_512',
|
| 60 |
+
},
|
| 61 |
+
'sizes':
|
| 62 |
+
{
|
| 63 |
+
'target': (1024, 1024),
|
| 64 |
+
},
|
| 65 |
+
'mean': [ 0.0, 0.0, 0.0 ],
|
| 66 |
+
'standard_deviation': [ 1.0, 1.0, 1.0 ]
|
| 67 |
+
},
|
| 68 |
+
'styleganex_age':
|
| 69 |
+
{
|
| 70 |
+
'__metadata__':
|
| 71 |
+
{
|
| 72 |
+
'vendor': 'williamyang1991',
|
| 73 |
+
'license': 'S-Lab-1.0',
|
| 74 |
+
'year': 2023
|
| 75 |
+
},
|
| 76 |
+
'hashes':
|
| 77 |
+
{
|
| 78 |
+
'age_modifier':
|
| 79 |
+
{
|
| 80 |
+
'url': resolve_download_url('models-3.1.0', 'styleganex_age.hash'),
|
| 81 |
+
'path': resolve_relative_path('../.assets/models/styleganex_age.hash')
|
| 82 |
+
}
|
| 83 |
+
},
|
| 84 |
+
'sources':
|
| 85 |
+
{
|
| 86 |
+
'age_modifier':
|
| 87 |
+
{
|
| 88 |
+
'url': resolve_download_url('models-3.1.0', 'styleganex_age.onnx'),
|
| 89 |
+
'path': resolve_relative_path('../.assets/models/styleganex_age.onnx')
|
| 90 |
+
}
|
| 91 |
+
},
|
| 92 |
+
'templates':
|
| 93 |
+
{
|
| 94 |
+
'target': 'ffhq_512',
|
| 95 |
+
'target_with_background': 'styleganex_384'
|
| 96 |
+
},
|
| 97 |
+
'sizes':
|
| 98 |
+
{
|
| 99 |
+
'target': (256, 256),
|
| 100 |
+
'target_with_background': (384, 384)
|
| 101 |
+
},
|
| 102 |
+
'mean': [ 0.5, 0.5, 0.5 ],
|
| 103 |
+
'standard_deviation': [ 0.5, 0.5, 0.5 ]
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def get_inference_pool() -> InferencePool:
|
| 109 |
+
model_names = [ state_manager.get_item('age_modifier_model') ]
|
| 110 |
+
model_source_set = get_model_options().get('sources')
|
| 111 |
+
|
| 112 |
+
return inference_manager.get_inference_pool(__name__, model_names, model_source_set)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def clear_inference_pool() -> None:
|
| 116 |
+
model_names = [ state_manager.get_item('age_modifier_model') ]
|
| 117 |
+
inference_manager.clear_inference_pool(__name__, model_names)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def get_model_options() -> ModelOptions:
|
| 121 |
+
model_name = state_manager.get_item('age_modifier_model')
|
| 122 |
+
return create_static_model_set('full').get(model_name)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def register_args(program : ArgumentParser) -> None:
|
| 126 |
+
group_processors = find_argument_group(program, 'processors')
|
| 127 |
+
if group_processors:
|
| 128 |
+
group_processors.add_argument('--age-modifier-model', help = translator.get('help.model', __package__), default = config.get_str_value('processors', 'age_modifier_model', 'fran'), choices = age_modifier_choices.age_modifier_models)
|
| 129 |
+
group_processors.add_argument('--age-modifier-direction', help = translator.get('help.direction', __package__), type = int, default = config.get_int_value('processors', 'age_modifier_direction', '0'), choices = age_modifier_choices.age_modifier_direction_range, metavar = create_int_metavar(age_modifier_choices.age_modifier_direction_range))
|
| 130 |
+
facefusion.jobs.job_store.register_step_keys([ 'age_modifier_model', 'age_modifier_direction' ])
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
| 134 |
+
apply_state_item('age_modifier_model', args.get('age_modifier_model'))
|
| 135 |
+
apply_state_item('age_modifier_direction', args.get('age_modifier_direction'))
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def get_common_modules() -> List[ModuleType]:
|
| 139 |
+
return [ content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer ]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def pre_check() -> bool:
|
| 143 |
+
model_hash_set = get_model_options().get('hashes')
|
| 144 |
+
model_source_set = get_model_options().get('sources')
|
| 145 |
+
|
| 146 |
+
for common_module in get_common_modules():
|
| 147 |
+
if not common_module.pre_check():
|
| 148 |
+
return False
|
| 149 |
+
|
| 150 |
+
return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def pre_process(mode : ProcessMode) -> bool:
|
| 154 |
+
if mode in [ 'output', 'preview' ] and not is_image(state_manager.get_item('target_path')) and not is_video(state_manager.get_item('target_path')):
|
| 155 |
+
logger.error(translator.get('choose_image_or_video_target') + translator.get('exclamation_mark'), __name__)
|
| 156 |
+
return False
|
| 157 |
+
if mode == 'output' and not in_directory(state_manager.get_item('output_path')):
|
| 158 |
+
logger.error(translator.get('specify_image_or_video_output') + translator.get('exclamation_mark'), __name__)
|
| 159 |
+
return False
|
| 160 |
+
if mode == 'output' and not same_file_extension(state_manager.get_item('target_path'), state_manager.get_item('output_path')):
|
| 161 |
+
logger.error(translator.get('match_target_and_output_extension') + translator.get('exclamation_mark'), __name__)
|
| 162 |
+
return False
|
| 163 |
+
return True
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def post_process() -> None:
|
| 167 |
+
read_static_image.cache_clear()
|
| 168 |
+
read_static_video_frame.cache_clear()
|
| 169 |
+
video_manager.clear_video_pool()
|
| 170 |
+
|
| 171 |
+
if state_manager.get_item('video_memory_strategy') in [ 'strict', 'moderate' ]:
|
| 172 |
+
clear_inference_pool()
|
| 173 |
+
|
| 174 |
+
if state_manager.get_item('video_memory_strategy') == 'strict':
|
| 175 |
+
for common_module in get_common_modules():
|
| 176 |
+
common_module.clear_inference_pool()
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def modify_age(target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
|
| 180 |
+
model_templates = get_model_options().get('templates')
|
| 181 |
+
model_sizes = get_model_options().get('sizes')
|
| 182 |
+
face_landmark_5 = target_face.landmark_set.get('5/68').copy()
|
| 183 |
+
crop_vision_frame, affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, face_landmark_5, model_templates.get('target'), model_sizes.get('target'))
|
| 184 |
+
|
| 185 |
+
if state_manager.get_item('age_modifier_model') == 'fran':
|
| 186 |
+
box_mask = create_box_mask(crop_vision_frame, state_manager.get_item('face_mask_blur'), (0, 0, 0, 0))
|
| 187 |
+
crop_masks =\
|
| 188 |
+
[
|
| 189 |
+
box_mask
|
| 190 |
+
]
|
| 191 |
+
|
| 192 |
+
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
| 193 |
+
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
| 194 |
+
crop_masks.append(occlusion_mask)
|
| 195 |
+
|
| 196 |
+
crop_vision_frame = prepare_vision_frame(crop_vision_frame)
|
| 197 |
+
target_age = numpy.mean(target_face.age)
|
| 198 |
+
age_modifier_direction = numpy.array([ target_age, target_age + state_manager.get_item('age_modifier_direction') ], dtype = numpy.float32) / 100
|
| 199 |
+
age_modifier_direction = age_modifier_direction.clip(0, 1)
|
| 200 |
+
crop_vision_frame = forward(crop_vision_frame, crop_vision_frame, age_modifier_direction)
|
| 201 |
+
crop_vision_frame = normalize_vision_frame(crop_vision_frame)
|
| 202 |
+
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
| 203 |
+
paste_vision_frame = paste_back(temp_vision_frame, crop_vision_frame, crop_mask, affine_matrix)
|
| 204 |
+
return paste_vision_frame
|
| 205 |
+
|
| 206 |
+
if state_manager.get_item('age_modifier_model') == 'styleganex_age':
|
| 207 |
+
extend_face_landmark_5 = scale_face_landmark_5(face_landmark_5, 0.875)
|
| 208 |
+
extend_vision_frame, extend_affine_matrix = warp_face_by_face_landmark_5(temp_vision_frame, extend_face_landmark_5, model_templates.get('target_with_background'), model_sizes.get('target_with_background'))
|
| 209 |
+
extend_vision_frame_raw = extend_vision_frame.copy()
|
| 210 |
+
box_mask = create_box_mask(extend_vision_frame, state_manager.get_item('face_mask_blur'), (0, 0, 0, 0))
|
| 211 |
+
crop_masks =\
|
| 212 |
+
[
|
| 213 |
+
box_mask
|
| 214 |
+
]
|
| 215 |
+
|
| 216 |
+
if 'occlusion' in state_manager.get_item('face_mask_types'):
|
| 217 |
+
occlusion_mask = create_occlusion_mask(crop_vision_frame)
|
| 218 |
+
temp_matrix = merge_matrix([ extend_affine_matrix, cv2.invertAffineTransform(affine_matrix) ])
|
| 219 |
+
occlusion_mask = cv2.warpAffine(occlusion_mask, temp_matrix, model_sizes.get('target_with_background'))
|
| 220 |
+
crop_masks.append(occlusion_mask)
|
| 221 |
+
|
| 222 |
+
crop_vision_frame = prepare_vision_frame(crop_vision_frame)
|
| 223 |
+
extend_vision_frame = prepare_vision_frame(extend_vision_frame)
|
| 224 |
+
age_modifier_direction = numpy.array(numpy.interp(state_manager.get_item('age_modifier_direction'), [ -100, 100 ], [ 2.5, -2.5 ])).astype(numpy.float32)
|
| 225 |
+
extend_vision_frame = forward(crop_vision_frame, extend_vision_frame, age_modifier_direction)
|
| 226 |
+
extend_vision_frame = normalize_extend_frame(extend_vision_frame)
|
| 227 |
+
extend_vision_frame = match_frame_color(extend_vision_frame_raw, extend_vision_frame)
|
| 228 |
+
extend_affine_matrix *= (model_sizes.get('target')[0] * 4) / model_sizes.get('target_with_background')[0]
|
| 229 |
+
crop_mask = numpy.minimum.reduce(crop_masks).clip(0, 1)
|
| 230 |
+
crop_mask = cv2.resize(crop_mask, (model_sizes.get('target')[0] * 4, model_sizes.get('target')[1] * 4))
|
| 231 |
+
paste_vision_frame = paste_back(temp_vision_frame, extend_vision_frame, crop_mask, extend_affine_matrix)
|
| 232 |
+
return paste_vision_frame
|
| 233 |
+
|
| 234 |
+
return temp_vision_frame
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def forward(crop_vision_frame : VisionFrame, extend_vision_frame : VisionFrame, age_modifier_direction : AgeModifierDirection) -> VisionFrame:
|
| 238 |
+
age_modifier = get_inference_pool().get('age_modifier')
|
| 239 |
+
age_modifier_inputs = {}
|
| 240 |
+
|
| 241 |
+
for age_modifier_input in age_modifier.get_inputs():
|
| 242 |
+
if age_modifier_input.name == 'target':
|
| 243 |
+
age_modifier_inputs[age_modifier_input.name] = crop_vision_frame
|
| 244 |
+
if age_modifier_input.name == 'target_with_background':
|
| 245 |
+
age_modifier_inputs[age_modifier_input.name] = extend_vision_frame
|
| 246 |
+
if age_modifier_input.name == 'direction':
|
| 247 |
+
age_modifier_inputs[age_modifier_input.name] = age_modifier_direction
|
| 248 |
+
|
| 249 |
+
with thread_semaphore():
|
| 250 |
+
crop_vision_frame = age_modifier.run(None, age_modifier_inputs)[0][0]
|
| 251 |
+
|
| 252 |
+
return crop_vision_frame
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def prepare_vision_frame(vision_frame : VisionFrame) -> VisionFrame:
|
| 256 |
+
model_mean = get_model_options().get('mean')
|
| 257 |
+
model_standard_deviation = get_model_options().get('standard_deviation')
|
| 258 |
+
vision_frame = vision_frame[:, :, ::-1] / 255.0
|
| 259 |
+
vision_frame = (vision_frame - model_mean) / model_standard_deviation
|
| 260 |
+
vision_frame = numpy.expand_dims(vision_frame.transpose(2, 0, 1), axis = 0).astype(numpy.float32)
|
| 261 |
+
return vision_frame
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def normalize_vision_frame(vision_frame : VisionFrame) -> VisionFrame:
|
| 265 |
+
model_mean = get_model_options().get('mean')
|
| 266 |
+
model_standard_deviation = get_model_options().get('standard_deviation')
|
| 267 |
+
vision_frame = vision_frame.transpose(1, 2, 0)
|
| 268 |
+
vision_frame = vision_frame * model_standard_deviation + model_mean
|
| 269 |
+
vision_frame = vision_frame.clip(0, 1)
|
| 270 |
+
vision_frame = vision_frame[:, :, ::-1] * 255
|
| 271 |
+
return vision_frame
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def normalize_extend_frame(extend_vision_frame : VisionFrame) -> VisionFrame:
|
| 275 |
+
model_sizes = get_model_options().get('sizes')
|
| 276 |
+
extend_vision_frame = numpy.clip(extend_vision_frame, -1, 1)
|
| 277 |
+
extend_vision_frame = (extend_vision_frame + 1) / 2
|
| 278 |
+
extend_vision_frame = extend_vision_frame.transpose(1, 2, 0).clip(0, 255)
|
| 279 |
+
extend_vision_frame = (extend_vision_frame * 255.0)
|
| 280 |
+
extend_vision_frame = extend_vision_frame.astype(numpy.uint8)[:, :, ::-1]
|
| 281 |
+
extend_vision_frame = cv2.resize(extend_vision_frame, (model_sizes.get('target')[0] * 4, model_sizes.get('target')[1] * 4), interpolation = cv2.INTER_AREA)
|
| 282 |
+
return extend_vision_frame
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def process_frame(inputs : AgeModifierInputs) -> ProcessorOutputs:
|
| 286 |
+
reference_vision_frame = inputs.get('reference_vision_frame')
|
| 287 |
+
source_vision_frames = inputs.get('source_vision_frames')
|
| 288 |
+
target_vision_frames = inputs.get('target_vision_frames')
|
| 289 |
+
temp_vision_frame = inputs.get('temp_vision_frame')
|
| 290 |
+
temp_vision_mask = inputs.get('temp_vision_mask')
|
| 291 |
+
|
| 292 |
+
target_vision_frame = get_middle(target_vision_frames)
|
| 293 |
+
target_faces = select_faces(reference_vision_frame, source_vision_frames, target_vision_frames)
|
| 294 |
+
|
| 295 |
+
if target_faces:
|
| 296 |
+
for target_face in target_faces:
|
| 297 |
+
target_face = scale_face(target_face, target_vision_frame, temp_vision_frame)
|
| 298 |
+
temp_vision_frame = modify_age(target_face, temp_vision_frame)
|
| 299 |
+
|
| 300 |
+
return temp_vision_frame, temp_vision_mask
|
processors/modules/age_modifier/locales.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from facefusion.types import Locales
|
| 2 |
+
|
| 3 |
+
LOCALES : Locales =\
|
| 4 |
+
{
|
| 5 |
+
'en':
|
| 6 |
+
{
|
| 7 |
+
'help':
|
| 8 |
+
{
|
| 9 |
+
'model': 'choose the model responsible for aging the face',
|
| 10 |
+
'direction': 'specify the direction in which the age should be modified'
|
| 11 |
+
},
|
| 12 |
+
'uis':
|
| 13 |
+
{
|
| 14 |
+
'direction_slider': 'AGE MODIFIER DIRECTION',
|
| 15 |
+
'model_dropdown': 'AGE MODIFIER MODEL'
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
}
|
processors/modules/age_modifier/types.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, List, Literal, TypeAlias, TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy.typing import NDArray
|
| 4 |
+
|
| 5 |
+
from facefusion.types import Mask, VisionFrame
|
| 6 |
+
|
| 7 |
+
AgeModifierInputs = TypedDict('AgeModifierInputs',
|
| 8 |
+
{
|
| 9 |
+
'reference_vision_frame' : VisionFrame,
|
| 10 |
+
'source_vision_frames' : List[VisionFrame],
|
| 11 |
+
'target_vision_frames' : List[VisionFrame],
|
| 12 |
+
'temp_vision_frame' : VisionFrame,
|
| 13 |
+
'temp_vision_mask' : Mask
|
| 14 |
+
})
|
| 15 |
+
|
| 16 |
+
AgeModifierModel = Literal['fran', 'styleganex_age']
|
| 17 |
+
|
| 18 |
+
AgeModifierDirection : TypeAlias = NDArray[Any]
|