diff --git a/README.md b/README.md index b98b02b..65b4663 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ CatVTON warpper for ComfyUI. fixed the cropping issue of images with different p Original repo: [https://github.com/Zheng-Chong/CatVTON](https://github.com/Zheng-Chong/CatVTON) -![image](workflow/workflow.png) +It is recommend use 6G or higher VRAM NVidia GPU device to run. + +![image](workflow/catvton_example) ### Install Plugin Open the cmd window in the plugin directory of ComfyUI, like ComfyUI\custom_nodes,type: diff --git a/py/cat_vton.py b/py/cat_vton.py index 8b40918..88ad7d4 100644 --- a/py/cat_vton.py +++ b/py/cat_vton.py @@ -1,3 +1,5 @@ +import torch.xpu + from .func import * from comfy.utils import ProgressBar @@ -10,6 +12,7 @@ class LS_CatVTON: @classmethod def INPUT_TYPES(cls): + # device_list = ['cuda', 'cpu', "mps", "xpu"] return { "required": { "image": ("IMAGE",), @@ -20,6 +23,7 @@ class LS_CatVTON: "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), "steps": ("INT", {"default": 40, "min": 1, "max": 10000}), "cfg": ("FLOAT", {"default": 2.5, "min": 0.0, "max": 14.0, "step": 0.1, "round": 0.01,},), + # "device": (device_list,), } } @@ -30,6 +34,7 @@ class LS_CatVTON: def catvton(self, image, mask, refer_image, mask_grow, mixed_precision, seed, steps, cfg): + device = "cuda" catvton_path = os.path.join(folder_paths.models_dir, "CatVTON") sd15_inpaint_path = os.path.join(catvton_path, "stable-diffusion-inpainting") @@ -45,7 +50,7 @@ class LS_CatVTON: attn_ckpt_version="mix", weight_dtype=mixed_precision, use_tf32=True, - device='cuda' + device=device ) if mask.dim() == 2: @@ -61,7 +66,7 @@ class LS_CatVTON: mask_image = mask_image[0] mask_image = to_pil_image(mask_image) - generator = torch.Generator(device='cuda').manual_seed(seed) + generator = torch.Generator(device=device).manual_seed(seed) person_image, person_image_bbox = resize_and_padding_image(target_image, (768, 1024)) cloth_image, _ = resize_and_padding_image(refer_image, (768, 1024)) mask, _ = resize_and_padding_image(mask_image, (768, 1024)) diff --git a/workflow/catvton_example.jpg b/workflow/catvton_example.jpg new file mode 100644 index 0000000..dbe5450 Binary files /dev/null and b/workflow/catvton_example.jpg differ diff --git a/workflow/catvton_example.json b/workflow/catvton_example.json index 828f3db..6aeee6d 100644 --- a/workflow/catvton_example.json +++ b/workflow/catvton_example.json @@ -1,14 +1,14 @@ { - "last_node_id": 12, - "last_link_id": 15, + "last_node_id": 13, + "last_link_id": 18, "nodes": [ { "id": 2, "type": "LoadImage", - "pos": [ - 243, - 252 - ], + "pos": { + "0": 283, + "1": 153 + }, "size": { "0": 315, "1": 314 @@ -16,16 +16,17 @@ "flags": {}, "order": 0, "mode": 0, + "inputs": [], "outputs": [ { "name": "IMAGE", "type": "IMAGE", "links": [ 1, - 13 + 16 ], - "shape": 3, - "slot_index": 0 + "slot_index": 0, + "shape": 3 }, { "name": "MASK", @@ -45,14 +46,14 @@ { "id": 8, "type": "PreviewImage", - "pos": [ - 1645, - 241 - ], - "size": [ - 530.5761755629187, - 734.8110968147237 - ], + "pos": { + "0": 1647, + "1": 159 + }, + "size": { + "0": 530.576171875, + "1": 734.8110961914062 + }, "flags": {}, "order": 5, "mode": 0, @@ -63,17 +64,167 @@ "link": 8 } ], + "outputs": [], "properties": { "Node name for S&R": "PreviewImage" } }, + { + "id": 1, + "type": "CatVTONWrapper", + "pos": { + "0": 1146, + "1": 161 + }, + "size": { + "0": 315, + "1": 218 + }, + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 1, + "slot_index": 0 + }, + { + "name": "mask", + "type": "MASK", + "link": 18 + }, + { + "name": "refer_image", + "type": "IMAGE", + "link": 7, + "slot_index": 2 + } + ], + "outputs": [ + { + "name": "image", + "type": "IMAGE", + "links": [ + 8 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CatVTONWrapper" + }, + "widgets_values": [ + 25, + "fp16", + 491151633043877, + "randomize", + 50, + 3 + ] + }, + { + "id": 11, + "type": "LayerMask: MaskPreview", + "pos": { + "0": 1141, + "1": 563 + }, + "size": [ + 323.2476717529296, + 354.9690538940429 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 17 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "LayerMask: MaskPreview" + }, + "color": "rgba(27, 80, 119, 0.7)" + }, + { + "id": 13, + "type": "LayerMask: HumanPartsUltra", + "pos": { + "0": 682, + "1": 405 + }, + "size": { + "0": 352.79998779296875, + "1": 534 + }, + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 16 + } + ], + "outputs": [ + { + "name": "image", + "type": "IMAGE", + "links": null, + "shape": 3 + }, + { + "name": "mask", + "type": "MASK", + "links": [ + 17, + 18 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LayerMask: HumanPartsUltra" + }, + "widgets_values": [ + false, + false, + false, + true, + false, + false, + false, + false, + false, + false, + false, + false, + "VITMatte", + 8, + 6, + 0.01, + 0.99, + true, + "cuda", + 2 + ], + "color": "rgba(27, 80, 119, 0.7)" + }, { "id": 7, "type": "LoadImage", - "pos": [ - 241, - 628 - ], + "pos": { + "0": 285, + "1": 611 + }, "size": { "0": 315, "1": 314 @@ -81,6 +232,7 @@ "flags": {}, "order": 1, "mode": 0, + "inputs": [], "outputs": [ { "name": "IMAGE", @@ -104,144 +256,6 @@ "panda_t_shirt.jpg", "image" ] - }, - { - "id": 12, - "type": "LayerMask: SegmentAnythingUltra V2", - "pos": [ - 699, - 608 - ], - "size": { - "0": 315, - "1": 342 - }, - "flags": {}, - "order": 2, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 13 - } - ], - "outputs": [ - { - "name": "image", - "type": "IMAGE", - "links": null, - "shape": 3 - }, - { - "name": "mask", - "type": "MASK", - "links": [ - 14, - 15 - ], - "shape": 3, - "slot_index": 1 - } - ], - "properties": { - "Node name for S&R": "LayerMask: SegmentAnythingUltra V2" - }, - "widgets_values": [ - "sam_vit_h (2.56GB)", - "GroundingDINO_SwinT_OGC (694MB)", - 0.3, - "VITMatte", - 6, - 6, - 0.01, - 0.99, - false, - "shirt", - "cuda", - 2 - ] - }, - { - "id": 11, - "type": "LayerMask: MaskPreview", - "pos": [ - 1174, - 603 - ], - "size": [ - 251.91729700753058, - 352.4916389395413 - ], - "flags": {}, - "order": 3, - "mode": 0, - "inputs": [ - { - "name": "mask", - "type": "MASK", - "link": 14 - } - ], - "properties": { - "Node name for S&R": "LayerMask: MaskPreview" - } - }, - { - "id": 1, - "type": "CatVTONWrapper", - "pos": [ - 1135, - 250 - ], - "size": { - "0": 315, - "1": 218 - }, - "flags": {}, - "order": 4, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 1, - "slot_index": 0 - }, - { - "name": "mask", - "type": "MASK", - "link": 15 - }, - { - "name": "refer_image", - "type": "IMAGE", - "link": 7, - "slot_index": 2 - } - ], - "outputs": [ - { - "name": "image", - "type": "IMAGE", - "links": [ - 8 - ], - "shape": 3, - "slot_index": 0 - } - ], - "properties": { - "Node name for S&R": "CatVTONWrapper" - }, - "widgets_values": [ - 25, - "bf16", - 571003793697217, - "randomize", - 50, - 3 - ] } ], "links": [ @@ -270,24 +284,24 @@ "IMAGE" ], [ - 13, + 16, 2, 0, - 12, + 13, 0, "IMAGE" ], [ - 14, - 12, + 17, + 13, 1, 11, 0, "MASK" ], [ - 15, - 12, + 18, + 13, 1, 1, 1, @@ -298,10 +312,10 @@ "config": {}, "extra": { "ds": { - "scale": 0.8264462809917354, + "scale": 0.7513148009015777, "offset": [ - 16.52869750906587, - 61.78689238609821 + 338.6524316406253, + 290.41768908691427 ] } }, diff --git a/workflow/workflow.png b/workflow/workflow.png deleted file mode 100644 index 9f5af7d..0000000 Binary files a/workflow/workflow.png and /dev/null differ