chflame163 / ComfyUI_LayerStyle

A set of nodes for ComfyUI that can composite layer and mask to achieve Photoshop like functionality.
MIT License
1.24k stars 68 forks source link

MaskEdgeUltraDetailV2 slow because VITMatte is not running on GPU #145

Closed imperator-maximus closed 3 months ago

imperator-maximus commented 3 months ago

I tested it on GPU here: https://github.com/chflame163/ComfyUI_LayerStyle/blob/9cdac00ee1f2d75a04780462e7904d4ac04e1382/py/imagefunc.py#L1417

and it was 5 times faster. Can you change it (also for input tensors line below)? Thank you!

chflame163 commented 3 months ago

I tested it on GPU here:

How can it run on the GPU? Can you explain it in detail?

imperator-maximus commented 3 months ago

sure

    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    vit_matte_model.model.to(device)

and

  with torch.no_grad():
        inputs = {k: v.to(device) for k, v in inputs.items()}
chflame163 commented 3 months ago

sure

Thank you, I successfully ran it. And I realized that large image can lead to exceeding the VRAM, and I will find a solution for this.

imperator-maximus commented 3 months ago

maybe running in 1024x1024 max and using guided filter (which you already have) for hi-res? this is code of a node I made: https://github.com/flyingdogsoftware/gyre_for_comfyui/blob/master/inspyrenet_pipeline.py it is using Inspyrenet for background removal and so it might be a similar situation here.

chflame163 commented 3 months ago

maybe running in 1024x1024 max and using guided filter (which you already have) for hi-res?

Thank you. The nodes has been updated. BTW: I tested the edge detail of down-sampling, there is no difference between using guidefilter and directly resize. : )

imperator-maximus commented 3 months ago

thank you - works great 👍

image