face_index selection

This commit is contained in:
kijai
2024-07-09 13:00:03 +03:00
parent 6735771664
commit f8aada81db
2 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ class Cropper(object):
elif len(src_face) > 1:
log(f'More than one face detected in the image, only pick one face by rule {direction}.')
src_face = src_face[0]
src_face = src_face[self.crop_cfg.face_index]
pts = src_face.landmark_2d_106
+5 -2
View File
@@ -63,11 +63,12 @@ class InferenceConfig:
class CropConfig:
def __init__(self, dsize=512, scale=2.3, vx_ratio=0, vy_ratio=-0.125):
def __init__(self, dsize=512, scale=2.3, vx_ratio=0, vy_ratio=-0.125, face_index=0):
self.dsize = dsize
self.scale = scale
self.vx_ratio = vx_ratio
self.vy_ratio = vy_ratio
self.face_index = face_index
class ArgumentConfig:
@@ -365,6 +366,7 @@ class LivePortraitCropper:
"scale": ("FLOAT", {"default": 2.3, "min": 1.0, "max": 4.0, "step": 0.01}),
"vx_ratio": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
"vy_ratio": ("FLOAT", {"default": -0.125, "min": -1.0, "max": 1.0, "step": 0.01}),
"face_index": ("INT", {"default": 0, "min": 0, "max": 100}),
},
"optional": {
"onnx_device": (
@@ -382,7 +384,7 @@ class LivePortraitCropper:
FUNCTION = "process"
CATEGORY = "LivePortrait"
def process(self, source_image, dsize, scale, vx_ratio, vy_ratio, onnx_device='CUDA'):
def process(self, source_image, dsize, scale, vx_ratio, vy_ratio, face_index, onnx_device='CUDA'):
source_image_np = (source_image * 255).byte().numpy()
crop_cfg = CropConfig(
@@ -390,6 +392,7 @@ class LivePortraitCropper:
scale = scale,
vx_ratio = vx_ratio,
vy_ratio = vy_ratio,
face_index = face_index
)
cropper = Cropper(crop_cfg=crop_cfg, provider=onnx_device)