From 34dd13cea976bd8eaf58e19e5cc629ed025cea16 Mon Sep 17 00:00:00 2001 From: matt3o Date: Tue, 5 Mar 2024 13:13:27 +0100 Subject: [PATCH] allow batches of kps images, fix #80 --- InstantID.py | 5 +++-- README.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/InstantID.py b/InstantID.py index e0e03be..fa30b6f 100644 --- a/InstantID.py +++ b/InstantID.py @@ -376,7 +376,7 @@ def INPUT_TYPES(s): CATEGORY = "InstantID" def preprocess_image(self, faceanalysis, image): - face_kps = extractFeatures(faceanalysis, image[0].unsqueeze(0), extract_kps=True) + face_kps = extractFeatures(faceanalysis, image, extract_kps=True) if face_kps is None: face_kps = torch.zeros_like(image) @@ -437,7 +437,8 @@ def apply_instantid(self, instantid, insightface, control_net, image, model, pos if face_embed is None: raise Exception('Reference Image: No face detected.') - face_kps = extractFeatures(insightface, image_kps[0].unsqueeze(0) if image_kps is not None else image[0].unsqueeze(0), extract_kps=True) + # if no keypoints image is provided, use the image itself (only the first one in the batch) + face_kps = extractFeatures(insightface, image_kps if image_kps is not None else image[0].unsqueeze(0), extract_kps=True) if face_kps is None: face_kps = torch.zeros_like(image) if image_kps is None else image_kps diff --git a/README.md b/README.md index 43d2e20..fb53bd4 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The person is posed based on the keypoints generated from the reference image. Y ## Noise Injection -The default InstantID implementation seems to really burn the image, I find that by injecting noise to the negative embeds we can mitigate the effect and also increase the likeliness to the reference. The default Apply InstantID node automatically injects 35% noise, if you want to fine tune the effect you use the Advanced InstantID node. +The default InstantID implementation seems to really burn the image, I find that by injecting noise to the negative embeds we can mitigate the effect and also increase the likeliness to the reference. The default Apply InstantID node automatically injects 35% noise, if you want to fine tune the effect you can use the Advanced InstantID node. This is still experimental and may change in the future.