antelopev2

This commit is contained in:
lllyasviel
2024-01-31 18:16:40 -08:00
parent 571c4586c5
commit 13a649010a
4 changed files with 80 additions and 22 deletions

View File

@@ -361,22 +361,22 @@ legacy_preprocessors = {
# "Inpaint"
# ]
# },
"instant_id_face_embedding": {
"label": "instant_id_face_embedding",
"call_function": functools.partial(g_insight_face_instant_id_model.run_model_instant_id, return_keypoints=False),
"unload_function": None,
"managed_model": "g_insight_face_instant_id_model",
"model_free": False,
"no_control_mode": False,
"resolution": None,
"slider_1": None,
"slider_2": None,
"slider_3": None,
"priority": 0,
"tags": [
"Instant_ID"
]
},
# "instant_id_face_embedding": {
# "label": "instant_id_face_embedding",
# "call_function": functools.partial(g_insight_face_instant_id_model.run_model_instant_id, return_keypoints=False),
# "unload_function": None,
# "managed_model": "g_insight_face_instant_id_model",
# "model_free": False,
# "no_control_mode": False,
# "resolution": None,
# "slider_1": None,
# "slider_2": None,
# "slider_3": None,
# "priority": 0,
# "tags": [
# "Instant-ID"
# ]
# },
"instant_id_face_keypoints": {
"label": "instant_id_face_keypoints",
"call_function": functools.partial(g_insight_face_instant_id_model.run_model_instant_id, return_keypoints=True),
@@ -390,7 +390,7 @@ legacy_preprocessors = {
"slider_3": None,
"priority": 0,
"tags": [
"Instant_ID"
"Instant-ID"
]
},
# "ip-adapter_clip_sd15": {

View File

@@ -56,6 +56,7 @@ class LegacyPreprocessor(Preprocessor):
't2i-adapter': ['t2i_adapter', 't2iadapter', 't2ia'],
'ip-adapter': ['ip_adapter', 'ipadapter'],
'openpose': ['openpose', 'densepose'],
'instant-iD': ['instant_id', 'instantid'],
}
self.model_filename_filters = []

View File

@@ -1,4 +1,4 @@
# This file is exactly same with https://github.com/cubiq/ComfyUI_IPAdapter_plus/blob/main/IPAdapterPlus.py
# https://github.com/cubiq/ComfyUI_IPAdapter_plus/blob/main/IPAdapterPlus.py
import torch
import contextlib
@@ -532,17 +532,34 @@ class InsightFaceLoader:
FUNCTION = "load_insight_face"
CATEGORY = "ipadapter"
def load_insight_face(self, provider):
def load_insight_face(self, name="buffalo_l", provider="CPU"):
try:
from insightface.app import FaceAnalysis
except ImportError as e:
raise Exception(e)
if name == 'antelopev2':
from modules.modelloader import load_file_from_url
model_root = os.path.join(INSIGHTFACE_DIR, 'models', "antelopev2")
if not model_root:
os.makedirs(model_root, exist_ok=True)
for local_file, url in (
("1k3d68.onnx", "https://huggingface.co/DIAMONIK7777/antelopev2/resolve/main/1k3d68.onnx"),
("2d106det.onnx", "https://huggingface.co/DIAMONIK7777/antelopev2/resolve/main/2d106det.onnx"),
("genderage.onnx", "https://huggingface.co/DIAMONIK7777/antelopev2/resolve/main/genderage.onnx"),
("glintr100.onnx", "https://huggingface.co/DIAMONIK7777/antelopev2/resolve/main/glintr100.onnx"),
("scrfd_10g_bnkps.onnx",
"https://huggingface.co/DIAMONIK7777/antelopev2/resolve/main/scrfd_10g_bnkps.onnx"),
):
local_path = os.path.join(model_root, local_file)
if not os.path.exists(local_path):
load_file_from_url(url, model_dir=model_root)
from insightface.utils import face_align
global insightface_face_align
insightface_face_align = face_align
model = FaceAnalysis(name="buffalo_l", root=INSIGHTFACE_DIR, providers=[provider + 'ExecutionProvider',])
model = FaceAnalysis(name=name, root=INSIGHTFACE_DIR, providers=[provider + 'ExecutionProvider',])
model.prepare(ctx_id=0, det_size=(640, 640))
return (model,)
@@ -572,7 +589,10 @@ class IPAdapterApply:
FUNCTION = "apply_ipadapter"
CATEGORY = "ipadapter"
def apply_ipadapter(self, ipadapter, model, weight, clip_vision=None, image=None, weight_type="original", noise=None, embeds=None, attn_mask=None, start_at=0.0, end_at=1.0, unfold_batch=False, insightface=None, faceid_v2=False, weight_v2=False):
def apply_ipadapter(self, ipadapter, model, weight, clip_vision=None, image=None, weight_type="original",
noise=None, embeds=None, attn_mask=None, start_at=0.0, end_at=1.0, unfold_batch=False,
insightface=None, faceid_v2=False, weight_v2=False, using_instant_id=False):
self.dtype = torch.float16 if ldm_patched.modules.model_management.should_use_fp16() else torch.float32
self.device = ldm_patched.modules.model_management.get_torch_device()
self.weight = weight

View File

@@ -38,7 +38,7 @@ class PreprocessorClipVisionWithInsightFaceForIPAdapter(PreprocessorClipVisionFo
def load_insightface(self):
if self.cached_insightface is None:
self.cached_insightface = opInsightFaceLoader("CPU")[0]
self.cached_insightface = opInsightFaceLoader()[0]
return self.cached_insightface
def __call__(self, input_image, resolution, slider_1=None, slider_2=None, slider_3=None, **kwargs):
@@ -55,6 +55,39 @@ class PreprocessorClipVisionWithInsightFaceForIPAdapter(PreprocessorClipVisionFo
return cond
class PreprocessorInsightFaceForInstantID(Preprocessor):
def __init__(self, name):
super().__init__()
self.name = name
self.tags = ['Instant-ID']
self.model_filename_filters = ['Instant-ID', 'Instant_ID']
self.sorting_priority = 20
self.slider_resolution = PreprocessorParameter(visible=False)
self.corp_image_with_a1111_mask_when_in_img2img_inpaint_tab = False
self.show_control_mode = False
self.sorting_priority = 10
self.cached_insightface = None
def load_insightface(self):
if self.cached_insightface is None:
self.cached_insightface = opInsightFaceLoader(name='antelopev2')[0]
return self.cached_insightface
def __call__(self, input_image, resolution, slider_1=None, slider_2=None, slider_3=None, **kwargs):
cond = dict(
clip_vision=None,
insightface=self.load_insightface(),
image=numpy_to_pytorch(input_image),
weight_type="original",
noise=0.0,
embeds=None,
attn_mask=None,
unfold_batch=False,
using_instant_id=True
)
return cond
add_supported_preprocessor(PreprocessorClipVisionForIPAdapter(
name='CLIP-ViT-H (IPAdapter)',
url='https://huggingface.co/h94/IP-Adapter/resolve/main/models/image_encoder/model.safetensors',
@@ -73,6 +106,10 @@ add_supported_preprocessor(PreprocessorClipVisionWithInsightFaceForIPAdapter(
filename='CLIP-ViT-H-14.safetensors'
))
add_supported_preprocessor(PreprocessorInsightFaceForInstantID(
name='InsightFace (InstantID)',
))
class IPAdapterPatcher(ControlModelPatcher):
@staticmethod