Commit
·
0df24eb
1
Parent(s):
e462e4d
reorder code
Browse files- .insightface/models/1k3d68.onnx +0 -3
- .insightface/models/2d106det.onnx +0 -3
- .insightface/models/antelopev2.zip +0 -3
- .insightface/models/antelopev2/1k3d68.onnx +0 -3
- .insightface/models/antelopev2/2d106det.onnx +0 -3
- .insightface/models/antelopev2/genderage.onnx +0 -3
- .insightface/models/antelopev2/glintr100.onnx +0 -3
- .insightface/models/antelopev2/scrfd_10g_bnkps.onnx +0 -3
- .insightface/models/genderage.onnx +0 -3
- .insightface/models/glintr100.onnx +0 -3
- .insightface/models/scrfd_10g_bnkps.onnx +0 -3
- antelopev2/1k3d68.onnx +0 -3
- antelopev2/2d106det.onnx +0 -3
- antelopev2/genderage.onnx +0 -3
- antelopev2/glintr100.onnx +0 -3
- antelopev2/scrfd_10g_bnkps.onnx +0 -3
- handler.py +44 -44
.insightface/models/1k3d68.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:df5c06b8a0c12e422b2ed8947b8869faa4105387f199c477af038aa01f9a45cc
|
| 3 |
-
size 143607619
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/2d106det.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f001b856447c413801ef5c42091ed0cd516fcd21f2d6b79635b1e733a7109dbf
|
| 3 |
-
size 5030888
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2.zip
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8e182f14fc6e80b3bfa375b33eb6cff7ee05d8ef7633e738d1c89021dcf0c5c5
|
| 3 |
-
size 360662982
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2/1k3d68.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:df5c06b8a0c12e422b2ed8947b8869faa4105387f199c477af038aa01f9a45cc
|
| 3 |
-
size 143607619
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2/2d106det.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f001b856447c413801ef5c42091ed0cd516fcd21f2d6b79635b1e733a7109dbf
|
| 3 |
-
size 5030888
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2/genderage.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4fde69b1c810857b88c64a335084f1c3fe8f01246c9a191b48c7bb756d6652fb
|
| 3 |
-
size 1322532
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2/glintr100.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4ab1d6435d639628a6f3e5008dd4f929edf4c4124b1a7169e1048f9fef534cdf
|
| 3 |
-
size 260665334
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/antelopev2/scrfd_10g_bnkps.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:5838f7fe053675b1c7a08b633df49e7af5495cee0493c7dcf6697200b85b5b91
|
| 3 |
-
size 16923827
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/genderage.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4fde69b1c810857b88c64a335084f1c3fe8f01246c9a191b48c7bb756d6652fb
|
| 3 |
-
size 1322532
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/glintr100.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4ab1d6435d639628a6f3e5008dd4f929edf4c4124b1a7169e1048f9fef534cdf
|
| 3 |
-
size 260665334
|
|
|
|
|
|
|
|
|
|
|
|
.insightface/models/scrfd_10g_bnkps.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:5838f7fe053675b1c7a08b633df49e7af5495cee0493c7dcf6697200b85b5b91
|
| 3 |
-
size 16923827
|
|
|
|
|
|
|
|
|
|
|
|
antelopev2/1k3d68.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:df5c06b8a0c12e422b2ed8947b8869faa4105387f199c477af038aa01f9a45cc
|
| 3 |
-
size 143607619
|
|
|
|
|
|
|
|
|
|
|
|
antelopev2/2d106det.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f001b856447c413801ef5c42091ed0cd516fcd21f2d6b79635b1e733a7109dbf
|
| 3 |
-
size 5030888
|
|
|
|
|
|
|
|
|
|
|
|
antelopev2/genderage.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4fde69b1c810857b88c64a335084f1c3fe8f01246c9a191b48c7bb756d6652fb
|
| 3 |
-
size 1322532
|
|
|
|
|
|
|
|
|
|
|
|
antelopev2/glintr100.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:4ab1d6435d639628a6f3e5008dd4f929edf4c4124b1a7169e1048f9fef534cdf
|
| 3 |
-
size 260665334
|
|
|
|
|
|
|
|
|
|
|
|
antelopev2/scrfd_10g_bnkps.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:5838f7fe053675b1c7a08b633df49e7af5495cee0493c7dcf6697200b85b5b91
|
| 3 |
-
size 16923827
|
|
|
|
|
|
|
|
|
|
|
|
handler.py
CHANGED
|
@@ -28,10 +28,14 @@ dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
|
|
| 28 |
|
| 29 |
class EndpointHandler():
|
| 30 |
def __init__(self, model_dir):
|
| 31 |
-
print("Loading model from", model_dir)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# transform = Compose([
|
| 37 |
# Resize(
|
|
@@ -47,39 +51,13 @@ class EndpointHandler():
|
|
| 47 |
# PrepareForNet(),
|
| 48 |
# ])
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
self.controlnet_identitynet = ControlNetModel.from_pretrained(
|
| 51 |
controlnet_path, torch_dtype=dtype
|
| 52 |
)
|
| 53 |
|
| 54 |
-
pretrained_model_name_or_path = "wangqixun/YamerMIX_v8"
|
| 55 |
-
|
| 56 |
-
self.pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
|
| 57 |
-
pretrained_model_name_or_path,
|
| 58 |
-
controlnet=[self.controlnet_identitynet],
|
| 59 |
-
torch_dtype=dtype,
|
| 60 |
-
safety_checker=None,
|
| 61 |
-
feature_extractor=None,
|
| 62 |
-
).to(device)
|
| 63 |
-
|
| 64 |
-
self.pipe.scheduler = diffusers.EulerDiscreteScheduler.from_config(
|
| 65 |
-
self.pipe.scheduler.config
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
# load and disable LCM
|
| 69 |
-
self.pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
|
| 70 |
-
self.pipe.disable_lora()
|
| 71 |
-
|
| 72 |
-
self.pipe.cuda()
|
| 73 |
-
self.pipe.load_ip_adapter_instantid(face_adapter)
|
| 74 |
-
self.pipe.image_proj_model.to("cuda")
|
| 75 |
-
self.pipe.unet.to("cuda")
|
| 76 |
-
|
| 77 |
-
# if we need more parameters
|
| 78 |
-
# scheduler_class_name = "EulerDiscreteScheduler"
|
| 79 |
-
# add_kwargs = {}
|
| 80 |
-
# scheduler = getattr(diffusers, scheduler_class_name)
|
| 81 |
-
# self.pipe.scheduler = scheduler.from_config(self.pipe.scheduler.config, **add_kwargs)
|
| 82 |
-
|
| 83 |
controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"
|
| 84 |
controlnet_canny_model = "diffusers/controlnet-canny-sdxl-1.0"
|
| 85 |
# controlnet_depth_model = "diffusers/controlnet-depth-sdxl-1.0-small"
|
|
@@ -90,19 +68,10 @@ class EndpointHandler():
|
|
| 90 |
controlnet_canny = ControlNetModel.from_pretrained(
|
| 91 |
controlnet_canny_model, torch_dtype=dtype
|
| 92 |
).to(device)
|
| 93 |
-
|
| 94 |
# controlnet_depth = ControlNetModel.from_pretrained(
|
| 95 |
# controlnet_depth_model, torch_dtype=dtype
|
| 96 |
# ).to(device)
|
| 97 |
|
| 98 |
-
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 99 |
-
# depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()
|
| 100 |
-
|
| 101 |
-
def get_canny_image(image, t1=100, t2=200):
|
| 102 |
-
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 103 |
-
edges = cv2.Canny(image, t1, t2)
|
| 104 |
-
return Image.fromarray(edges, "L")
|
| 105 |
-
|
| 106 |
# def get_depth_map(image):
|
| 107 |
|
| 108 |
# image = np.array(image) / 255.0
|
|
@@ -124,6 +93,11 @@ class EndpointHandler():
|
|
| 124 |
|
| 125 |
# return depth_image
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
self.controlnet_map = {
|
| 128 |
"pose": controlnet_pose,
|
| 129 |
"canny": controlnet_canny,
|
|
@@ -135,11 +109,35 @@ class EndpointHandler():
|
|
| 135 |
"canny": get_canny_image,
|
| 136 |
# "depth": get_depth_map,
|
| 137 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
self.
|
| 140 |
-
|
|
|
|
| 141 |
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
identitynet_strength_ratio = 0.8
|
| 145 |
|
|
@@ -283,6 +281,8 @@ class EndpointHandler():
|
|
| 283 |
|
| 284 |
print("Start inference...")
|
| 285 |
|
|
|
|
|
|
|
| 286 |
self.pipe.set_ip_adapter_scale(adapter_strength_ratio)
|
| 287 |
images = self.pipe(
|
| 288 |
prompt=prompt,
|
|
|
|
| 28 |
|
| 29 |
class EndpointHandler():
|
| 30 |
def __init__(self, model_dir):
|
|
|
|
| 31 |
|
| 32 |
+
print("Loading FaceAnalysis", model_dir)
|
| 33 |
+
self.app = FaceAnalysis(name="antelopev2", root="/repository/models/antelopev2", providers=["CPUExecutionProvider"])
|
| 34 |
+
self.app.prepare(ctx_id=0, det_size=(640, 640))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 38 |
+
# depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()
|
| 39 |
|
| 40 |
# transform = Compose([
|
| 41 |
# Resize(
|
|
|
|
| 51 |
# PrepareForNet(),
|
| 52 |
# ])
|
| 53 |
|
| 54 |
+
face_adapter = f"/repository/checkpoints/ip-adapter.bin"
|
| 55 |
+
controlnet_path = f"/repository/checkpoints/ControlNetModel"
|
| 56 |
+
|
| 57 |
self.controlnet_identitynet = ControlNetModel.from_pretrained(
|
| 58 |
controlnet_path, torch_dtype=dtype
|
| 59 |
)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"
|
| 62 |
controlnet_canny_model = "diffusers/controlnet-canny-sdxl-1.0"
|
| 63 |
# controlnet_depth_model = "diffusers/controlnet-depth-sdxl-1.0-small"
|
|
|
|
| 68 |
controlnet_canny = ControlNetModel.from_pretrained(
|
| 69 |
controlnet_canny_model, torch_dtype=dtype
|
| 70 |
).to(device)
|
|
|
|
| 71 |
# controlnet_depth = ControlNetModel.from_pretrained(
|
| 72 |
# controlnet_depth_model, torch_dtype=dtype
|
| 73 |
# ).to(device)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# def get_depth_map(image):
|
| 76 |
|
| 77 |
# image = np.array(image) / 255.0
|
|
|
|
| 93 |
|
| 94 |
# return depth_image
|
| 95 |
|
| 96 |
+
def get_canny_image(image, t1=100, t2=200):
|
| 97 |
+
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 98 |
+
edges = cv2.Canny(image, t1, t2)
|
| 99 |
+
return Image.fromarray(edges, "L")
|
| 100 |
+
|
| 101 |
self.controlnet_map = {
|
| 102 |
"pose": controlnet_pose,
|
| 103 |
"canny": controlnet_canny,
|
|
|
|
| 109 |
"canny": get_canny_image,
|
| 110 |
# "depth": get_depth_map,
|
| 111 |
}
|
| 112 |
+
|
| 113 |
+
pretrained_model_name_or_path = "wangqixun/YamerMIX_v8"
|
| 114 |
+
|
| 115 |
+
self.pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
|
| 116 |
+
pretrained_model_name_or_path,
|
| 117 |
+
controlnet=[self.controlnet_identitynet],
|
| 118 |
+
torch_dtype=dtype,
|
| 119 |
+
safety_checker=None,
|
| 120 |
+
feature_extractor=None,
|
| 121 |
+
).to(device)
|
| 122 |
|
| 123 |
+
self.pipe.scheduler = diffusers.EulerDiscreteScheduler.from_config(
|
| 124 |
+
self.pipe.scheduler.config
|
| 125 |
+
)
|
| 126 |
|
| 127 |
+
# load and disable LCM
|
| 128 |
+
self.pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
|
| 129 |
+
self.pipe.disable_lora()
|
| 130 |
+
|
| 131 |
+
self.pipe.cuda()
|
| 132 |
+
self.pipe.load_ip_adapter_instantid(face_adapter)
|
| 133 |
+
self.pipe.image_proj_model.to("cuda")
|
| 134 |
+
self.pipe.unet.to("cuda")
|
| 135 |
+
|
| 136 |
+
# if we need more parameters
|
| 137 |
+
# scheduler_class_name = "EulerDiscreteScheduler"
|
| 138 |
+
# add_kwargs = {}
|
| 139 |
+
# scheduler = getattr(diffusers, scheduler_class_name)
|
| 140 |
+
# self.pipe.scheduler = scheduler.from_config(self.pipe.scheduler.config, **add_kwargs)
|
| 141 |
|
| 142 |
identitynet_strength_ratio = 0.8
|
| 143 |
|
|
|
|
| 281 |
|
| 282 |
print("Start inference...")
|
| 283 |
|
| 284 |
+
self.generator = torch.Generator(device=device).manual_seed(42)
|
| 285 |
+
|
| 286 |
self.pipe.set_ip_adapter_scale(adapter_strength_ratio)
|
| 287 |
images = self.pipe(
|
| 288 |
prompt=prompt,
|