release version

This commit is contained in:
toto
2024-01-11 21:32:59 +08:00
parent c5fbb321e0
commit cf29de1216
18 changed files with 265 additions and 3485 deletions
Vendored
BIN
View File
Binary file not shown.
+1
View File
@@ -1,2 +1,3 @@
__pycache__
.idea
.DS_Store
+122 -4
View File
@@ -1,4 +1,122 @@
# ComfyUI-FaceChain
continue coding....
Expected to be released on January 20
预计1月20日左右发布,不会鸽
# [ComfyUI-FaceChain](https://github.com/THtianhao/ComfyUI-FaceChain)
This project is adapted from [facechain](https://github.com/modelscope/facechain) and involves the breakdown and improvement of the processes of [facechain](https://github.com/modelscope/facechain).
![workflow_inpaiting_inference.png](workflows%2Fworkflow_inpaiting_inference.png)
English | [简体中文](./README_zh-CN.md)
## Contact
If you have any questions or suggestions, you can reach us through the following channels:
- Email: tototianhao@gmail.com
- Telegram: https://t.me/+JoFE2vqHU4phZjg1
- WeChat Group: <img src="./images/wechat.jpg" width="300">
### Steps
1. Install ComfyUI first.
2. After a successful installation of ComfyUI, navigate to the `custom_nodes` directory at `ComfyUI/custom_nodes/`.
```
cd custom_nodes
```
3. Clone this project into the `custom_nodes` directory.
```
git clone https://github.com/THtianhao/ComfyUI-Portrait-Maker.git
```
4. Restart ComfyUI.
## ComfyUI Workflow
Facechain Workflow Location: [workflow_inpaiting_inference.png](workflows%2Fworkflow_inpaiting_inference.png)
Drag the workflow directly into ComfyUI.
## Node Introduction
### FC StyleLoraLoad
> The workflow can load the checkpoints and style Lora used by facechain, download them first, and then merge them, providing relevant prompts.
> Workflow: [./workflow/workflow_inference.json](./workflows/workflow_inference.json)
### FC FaceDetectCrop
> Detects faces and crops them.
![workflow_face_detect_crop.png](workflows%2Fworkflow_face_detect_crop.png)
Parameter Description:
1. mode: Cropping mode, normal mode crops according to the face, square 512 width height will scale the face to 512.
2. face_index: Index of the face, if there are multiple faces, retrieve them based on the index.
3. crop_ratio: Only effective in normal mode, crops the face proportionally, 1.0 is 1x the face.
### FC FaceFusion
> Fusion using model scope model.
![workflow_face_fusion.png](workflows%2Fworkflow_face_fusion.png)
### FC FaceSegment
> Segmentation using model scope model to obtain masks for the face and body.
![workflow_face_segment.png](workflows%2Fworkflow_face_segment.png)
Parameter Description:
1. ksize: Expansion parameter for segmenting the edges of the face.
2. ksize1: Expansion parameter for segmenting the edges of the face.
3. include_neck: Whether the segmented image includes the neck.
### FC FaceSegAndReplace
> Performs face fusion and replaces the original image, similar to facefusion but mainly used for multiple people.
![workflow_face_seg_and_replace.png](workflows%2Fworkflow_face_seg_and_replace.png)
### FC RemoveCannyFace
> Removes the Canny-detected parts of the face.
![workflow_remove_canny_face.png](workflows%2Fworkflow_remove_canny_face.png)
### FC ReplaceByMask
> Replaces the image based on the mask.
![workflow_replace_by_mask.png](workflows%2Fworkflow_replace_by_mask.png)
* FC MaskOP
> Operations on the mask.
Parameter Description:
1. mode: Provides three operations, blur, erosion, dilation.
2. kernel: The kernel used for the operation, the larger the kernel, the stronger the operation.
![workflow_mask_op.png](workflows%2Fworkflow_mask_op.png)
* FC FCCropToOrigin
> Currently, it can only be used in conjunction with `FC FaceDetectCrop` in `square 512 width height` mode. Pastes the cropped image onto the target image based on the mask.
![workflow_face_detect_crop.png](workflows%2Fworkflow_face_detect_crop.png)
Parameter Description:
1. origin_image: Original image.
2. origin_box: Bounding box of the original image.
3. origin_mask: Mask cropped from the original image.
4. paste_image: Pasting image, must be consistent with the origin_mask, hence the need for `FC FaceDetectCrop` in `square 512 width height` mode.
## Contribution
If you find any issues or have suggestions for improvement, feel free to contribute. Follow these steps:
1. Branch out a new feature branch: `git checkout -b feature/your-feature-name`
2. Make your changes and commit: `git commit -m "Add new feature"`
3. Push to your remote branch: `git push origin feature/your-feature-name`
4. Create a Pull Request (PR).
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Join us and contribute to the development of EasyPhoto ComfyUI Plugin!
+122
View File
@@ -0,0 +1,122 @@
# [ComfyUI-FaceChain](https://github.com/THtianhao/ComfyUI-FaceChain)
项目改编于[facechain](https://github.com/modelscope/facechain),对于[facechain](https://github.com/modelscope/facechain)进行了流程上的拆解和改进。
![workflow_inpaiting_inference.png](workflows%2Fworkflow_inpaiting_inference.png)
English | [简体中文](./README_zh-CN.md)
## 联系
如果你有任何疑问或建议,可以通过以下方式联系我们:
- 电子邮件:tototianhao@gmail.com
- telegram: https://t.me/+JoFE2vqHU4phZjg1
- 微信群: <img src="./images/wechat.jpg" width="300">
### 步骤
1. 首先安装ComfyUI
2. ComfyUI运行成功后进入`custom_nodes` 目录 `ComfyUI/custom_nodes/`
```
cd custom_nodes
```
3. 克隆此项目到custom_nodes目录中
```
git clone https://github.com/THtianhao/ComfyUI-Portrait-Maker.git
```
4. 重新启动ComfyUI
## ComfyUI 工作流
Facechain工作位置: [workflow_inpaiting_inference.png](workflows%2Fworkflow_inpaiting_inference.png)
将工作流直接拖进comfyui中
## 节点介绍
### FC StyleLoraLoad
> workflow可以加载facechain 用到的checkpoint和风格lora,首先下载然后进行融合,并且给出相关的prompt
> workflow : [./workflow/workflow_inference.json](./workflows/workflow_inference.json)
### FC FaceDetectCrop
> 识别人脸并且剪裁
![workflow_face_detect_crop.png](workflows%2Fworkflow_face_detect_crop.png)
参数介绍:
1. mode:剪裁模式,normal模式为按照人脸剪裁,square 512 width height会将人脸缩放到512
2. face_index:人脸的索引,如果有多个人脸的话按照多个人脸的话按照index进行获取
3. crop_ratio:只在normal模式下生效,将人脸按照比例剪裁1.0为1倍人脸
### FC FaceFusion
> 使用model scope模型进行融合
![workflow_face_fusion.png](workflows%2Fworkflow_face_fusion.png)
### FC FaceSegment
> 使用model scope模型进行分割并且获取脸部和身体的mask
![workflow_face_segment.png](workflows%2Fworkflow_face_segment.png)
参数介绍:
1. ksize: 分割人脸边缘的扩展参数
2. ksize1: 分割人脸边缘的扩展参数
3. include_neck: 分割的图像是否包含脖子
### FC FaceSegAndReplace
> 进行人脸融合并且分割人脸替换原图,差异和facefusion不大,主要用在多人
![workflow_face_seg_and_replace.png](workflows%2Fworkflow_face_seg_and_replace.png)
### FC RemoveCannyFace
> 删除掉canny的人脸部分
![workflow_remove_canny_face.png](workflows%2Fworkflow_remove_canny_face.png)
### FC ReplaceByMask
> 根据mask替换图像
![workflow_replace_by_mask.png](workflows%2Fworkflow_replace_by_mask.png)
* FC MaskOP
> 对mask的操作
参数介绍:
1. mode: 提供了三种操作,模糊处理,腐蚀,膨胀
2. kernel: 用于操作的核,越大操作力度越强
![workflow_mask_op.png](workflows%2Fworkflow_mask_op.png)
* FC FCCropToOrigin
> 目前只能配合 `FC FaceDetectCrop` 的`square 512 width height`模式一起使用,将截取的图像根据mask粘贴到目标图像上
![workflow_face_detect_crop.png](workflows%2Fworkflow_face_detect_crop.png)
参数介绍:
1. origin_image: 原始图像
2. origin_box:原始图像的bbox
3. origin_mask:原始图像截取的mask
4. paste_image:粘贴图像 必须和origin_mask保持一致,因此需要`FC FaceDetectCrop` 的`square 512 width height`模式
## 贡献
如果你发现任何问题或有改进建议,欢迎贡献。请遵循以下步骤:
1. 分支出一个新的特性分支:`git checkout -b feature/your-feature-name`
2. 进行修改并提交:`git commit -m "Add new feature"`
3. 推送到你的远程分支:`git push origin feature/your-feature-name`
4. 创建一个 Pull 请求(PR)。
## 许可证
该项目采用 MIT 许可证。查看 [LICENSE](LICENSE) 文件以获取详细信息。
欢迎加入我们,为 EasyPhoto ConfyUI Plugin 的发展做出贡献!
+2 -1
View File
@@ -48,7 +48,7 @@ def facechain_detect_crop(source_image_pil, face_index=0, crop_ratio=1, mode='no
debug('mask', mask.shape)
corp_img_pil = source_image_pil.crop(bbox)
return corp_img_pil, mask, bbox, points_array
elif mode == "square 512 width heigh":
elif mode == "square 512 width height":
np_image = image_to_np(source_image_pil)
face_ratio = 0.45
crop_l = int(max(face_h, face_w) / face_ratio / 2)
@@ -69,6 +69,7 @@ def facechain_detect_crop(source_image_pil, face_index=0, crop_ratio=1, mode='no
raise RuntimeError('模式错误')
def segment(img, ksize=0, eyeh=0, ksize1=0, include_neck=False, warp_mask=None, return_human=True):
print('ksize', ksize, "ksize1", ksize1, 'warp_mask', warp_mask)
seg_image = get_segmentation()(img)
masks = seg_image['masks']
scores = seg_image['scores']
+17 -17
View File
@@ -32,7 +32,7 @@ class FaceDetectCrop:
"source_image": ("IMAGE",),
"face_index": ("INT", {"default": 0, "min": 0, "max": 10, "step": 1}),
"crop_ratio": ("FLOAT", {"default": 1.0, "min": 0, "max": 10, "step": 0.1}),
"mode": (["normal", "square 512 width heigh"],),
"mode": (["normal", "square 512 width height"],),
}
}
@@ -54,8 +54,8 @@ class FCFaceSegment:
},
"optional": {
"ksize": ("FLOAT", {"default": 0, "min": 0, "max": 10, "step": 0.1}),
"ksize1": ("FLOAT", {"default": 0, "min": 0, "max": 10, "step": 0.1}),
"ksize": ("FLOAT", {"default": 0, "min": 0, "max": 1, "step": 0.01}),
"ksize1": ("FLOAT", {"default": 0, "min": 0, "max": 1, "step": 0.01}),
"include_neck": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
"warp_mask": ("MASK",),
},
@@ -66,9 +66,9 @@ class FCFaceSegment:
FUNCTION = "fc_segment"
CATEGORY = "facechain/model"
def fc_segment(self, source_image, ksize=0, ksize1=0, include_neck=False, warp_mask=None, ):
def fc_segment(self, source_image, ksize, ksize1, include_neck=False, warp_mask=None, ):
pil_source_image = tensor_to_img(source_image)
seg_image, mask, human_mask = segment(pil_source_image, ksize, ksize1, include_neck, warp_mask, True)
seg_image, mask, human_mask = segment(pil_source_image, ksize=ksize, ksize1=ksize1, include_neck=include_neck, warp_mask=warp_mask, return_human=True)
return image_to_tensor(seg_image), mask_np2_to_mask_tensor(mask), mask_np2_to_mask_tensor(human_mask)
class FCFaceFusionAndSegReplace:
@@ -177,7 +177,7 @@ class FCReplaceByMask:
np_source_image = tensor_to_np(source_image)
np_replace_image = tensor_to_np(replace_image)
np_mask = mask_tensor_to_mask_np3(mask)
result_np = np_source_image * np_mask + np_replace_image(1 - np_mask)
result_np = np_source_image * np_mask + np_replace_image * (1 - np_mask)
return (image_np_to_image_tensor(result_np),)
class FCCropAndPaste:
@@ -213,8 +213,8 @@ class FCMaskOP:
return {
"required": {
"mask": ("MASK",),
"ksize": ("INT", {"default": 8, "min": 0, "max": 100, "step": 1}),
"method": (["expand_dims", "concatenate", "burl", "erode"],),
"method": (["burl", "erode", "dilate"],),
"kernel": ("INT", {"default": 16, "min": 0, "max": 100, "step": 1}),
}
}
@@ -222,19 +222,19 @@ class FCMaskOP:
FUNCTION = "mask_op"
CATEGORY = "facechain/mask"
def mask_op(self, mask, ksize, method):
def mask_op(self, mask, method, kernel):
mask_np = mask_tensor_to_mask_np3(mask)
result = None
if method == "concatenate":
result = np.concatenate([mask_np, mask_np, mask_np], axis=2)
elif method == "expand_dims":
result = np.expand_dims(mask_np, axis=2)
elif method == "burl":
result = cv2.GaussianBlur(mask_np, (int(ksize * 1.8) * 2 + 1, int(ksize * 1.8) * 2 + 1), 0)
kernel_real = np.ones((kernel, kernel), np.uint8)
if method == "burl":
result = cv2.GaussianBlur(mask_np, (int(kernel * 1.8) * 2 + 1, int(kernel * 1.8) * 2 + 1), 0)
result = np.expand_dims(result, axis=2)
elif method == 'erode':
kernel = np.ones((ksize * 2, ksize * 2))
result = cv2.erode(mask_np, kernel, iterations=1)
result = cv2.erode(mask_np, kernel_real, iterations=1)
result = np.expand_dims(result, axis=2)
elif method == 'dilate':
result = cv2.dilate(mask_np, kernel_real, iterations=1)
result = np.expand_dims(result, axis=2)
return (mask_np3_to_mask_tensor(result),)
class FCCropToOrigin:
+1 -1
View File
@@ -54,7 +54,7 @@ class FCStyleLoraLoad:
}
}
RETURN_TYPES = ("MODEL", "CLIP", "VAE", "CONDITION",)
RETURN_TYPES = ("MODEL", "CLIP", "VAE", "STRING",)
RETURN_NAMES = ("MODEL", "CLIP", "VAE", "style_prompt",)
FUNCTION = "style_lora_load"
CATEGORY = "facechain/lora"
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 679 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB