ComfyUI Extension: ComfyUI-productfix

Authored by MiddleKD

Created

Updated

8 stars

This is a ComfyUI custom node that helps generate images while preserving the text, logos, and details of e-commerce products.

Custom Nodes (0)

    README

    ๐ŸŽจ ComfyUI-productfix

    git_header e-commerce ์ƒํ’ˆ์˜ ํ…์ŠคํŠธ, ๋กœ๊ณ , ๋””ํ…Œ์ผ ๋“ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ComfyUI ์ปค์Šคํ…€ ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค.

    ๐ŸŽฌ Demo

    project_header

    ์Šค๋งˆํŠธํฐ์œผ๋กœ ์ฐ์€ ๋‚ด ๋ฐฉ ๋ฌผ๊ฑด(์ƒ‰๋ณด์ • X)๋“ค๋กœ ์ƒ์„ฑํ•œ AI ์ด๋ฏธ์ง€

    ๐Ÿ“Œ Index

    ๐Ÿš€ Introduction

    Stable diffusion์œผ๋กœ ์ƒ์„ฑํ•œ ์ด๋ฏธ์ง€๋Š” ์‹œ๊ฐ์ ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์ถฉ์‹ค๋„๊ฐ€ ๋†’์€ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜์ง€๋งŒ, ์ƒ์„ฑ ๊ณผ์ •์—์„œ ์ž…๋ ฅ ๊ฐ์ฒด๊ฐ€ ๋ณ€ํ˜•๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์ฒด์— ํ…์ŠคํŠธ์™€ ๋ธŒ๋žœ๋“œ ๋กœ๊ณ  ๊ฐ™์ด ์ธ์œ„์  ๊ทœ์น™์„ฑ์„ ๊ฐ€์ง„ ์š”์†Œ์—์„œ ์ด ๋ฌธ์ œ๊ฐ€ ํŠนํžˆ ๋‘๋“œ๋Ÿฌ์ง‘๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ณ€ํ˜• ๋ฌธ์ œ๋Š” e-commerce ํ™˜๊ฒฝ์—์„œ ํŒ๋งคํ•˜๋Š” ์‹ค์ œ ์ƒํ’ˆ์— ์ ์šฉํ•  ๊ฒฝ์šฐ ์‹ฌ๊ฐํ•œ ์ œ์•ฝ์œผ๋กœ ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค.

    Productfix๋Š” ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํŠน์„ฑ(ํ…์ŠคํŠธ, ๋กœ๊ณ , ๋””ํ…Œ์ผ ๋“ฑ)์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” Latent injection์ด๋ผ๋Š” AI application์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ์ฒด์˜ ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ๋ณด์กดํ•˜๋Š”๋ฐ ๋„์›€์ด ๋˜๋Š” ์ถ”๊ฐ€์ ์ธ ๋…ธ๋“œ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

    ์ด ๋…ธ๋“œ๋ฅผ ํ†ตํ•ด ๊ธฐ์กด์˜ ๋””์ž์ธ ํˆด(ํฌํ† ์ƒต, ์ผ๋Ÿฌ์ŠคํŠธ๋ ˆ์ดํ„ฐ ๊ฐ™์€)๋กœ ํ•ด์•ผ๋งŒ ํ–ˆ๋˜ ํ›„์ฒ˜๋ฆฌ ์ž‘์—…์„ ๋Œ€ํญ ์ค„์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์œผ๋กœ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค. ComfyUI์—์„œ custom node๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ๋ถ„์˜ ์›Œํฌํ”Œ๋กœ์šฐ์— ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๐Ÿ’ก Features

    <details> <summary><strong>Apply Latent Injection</strong></summary> <ul> <li>ComfyUI์˜ KSampler ๋…ธ๋“œ๋ฅผ hijackํ•˜์—ฌ Latent injection์„ ์ˆ˜ํ–‰ํ•˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.</li> <li>์‹คํ–‰์ด ์™„๋ฃŒ๋˜๋ฉด ๋ณธ๋ž˜ KSampler ๋…ธ๋“œ๋กœ ๋ณต๊ตฌํ•ฉ๋‹ˆ๋‹ค.</li> </ul> </details> <details> <summary><strong>Get Text Mask</strong></summary> <ul> <li>Easy OCR ํŒจํ‚ค์ง€๋ฅผ ์ด์šฉํ•˜์—ฌ Text Mask๋ฅผ Tensor๋กœ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค.</li> <li>Easy OCR custom node๋Š” ์ด๋ฏธ ์กด์žฌํ•˜์ง€๋งŒ(<a href="https://github.com/JaidedAI/EasyOCR">https://github.com/JaidedAI/EasyOCR</a>), PIL ํŒจํ‚ค์ง€ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์ด stableํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋…ธ๋“œ ์‚ฌ์šฉ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค.</li> </ul> </details> <details> <summary><strong>Reset Model Patcher Calculate Weight</strong></summary> <ul> <li>๋‹ค๋ฅธ node์—์„œ Modelpatcher์˜ calculate weight ํ•จ์ˆ˜๋ฅผ injectionํ–ˆ๋‹ค๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” custom node๊ฐ€ ๋‹ค์ˆ˜ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.(ex: comfyui-inpaint-nodes <a href="https://github.com/Acly/comfyui-inpaint-nodes">https://github.com/Acly/comfyui-inpaint-nodes</a>)</li> <li>์ด๋ฅผ ์›๋ณธ Modelpatcher์˜ calculate weight๋กœ resetํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค.</li> </ul> </details>

    ๐Ÿƒ๐Ÿปโ€โ™‚๏ธ Application

    • Comparing โ€œIC-Light + Textโ€ / โ€œIC-Light + Text + Latent Injectionโ€

      condition / Input / IC-Light / latent injection($\sigma_{end}$=1.0) / latent injection($\sigma_{end}$=0.5) ic_light_text prompt: product photo, professional photography, realistic, leaf, outdoors / seed: 42

    • Comparing โ€œIC-Light + IP-Adapterโ€ / โ€œIC-Light + IP-Adapter + Latent Injectionโ€

      condition / Input / IC-Light / latent injection($\sigma_{end}$=1.0) / latent injection($\sigma_{end}$=0.5) ic_light_adapter prompt: product photo, professional photography, realistic / seed: 42 <br/><br/> Latent injection์€ IC-Light์™€ IP-Adapter๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ๋•Œ ์ง„๊ฐ€๋ฅผ ๋ฐœํœ˜ํ•ฉ๋‹ˆ๋‹ค.ํ…œํ”Œ๋ฆฟ ์Šคํƒ€์ผ ์ด๋ฏธ์ง€์™€ ์ƒํ’ˆ์„ ํ•ฉ์„ฑํ•  ๋•Œ ์‚ฌ์šฉํ•ด๋ณด์„ธ์š”!

    • IC-Light + controlnet + text condition + Text transfer + Latent Injection

      latent_injection_text Items in my room captured with my phone camera latent_injection_text prompt: product photo, professional photography, realistic, water, bubble / seed: 42 / controlnet: depth latent_injection_text prompt: product photo, professional photography, realistic, flowers, outdoors / seed: 42 / controlnet: depth

    • IC-Light + controlnet + IP-Adapter + Text transfer + Latent Injection

      latent_injection_adapter Items in my room captured with my phone camera

      latent_injection_adapter

      prompt: product photo, professional photography, realistic / seed: 42 / controlnet: depth

      latent_injection_adapter prompt: product photo, professional photography, realistic / seed: 42 / controlnet: depth

    • Text transfer

      producfix_src Input / text condition / image condition(IP-Adapter)

      productfix_text only IC-Light / Latent injection / detail transfer / Text transfer

      producfix_text_closeup close up <br/><br/> productfix_adapter only IC-Light / Latent injection / detail transfer / Text transfer

      producfix_adapter_closeup close up <br/><br/> Text transfer๋Š” ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํ…์ŠคํŠธ๋ฅผ ๋ณด์กดํ•˜๊ธฐ ์œ„ํ•ด ๊ฐœ๋ฐœ๋œ OCR ํ…์ŠคํŠธ ๋งˆ์Šคํฌ ๊ธฐ๋ฐ˜ Detail transfer application์ž…๋‹ˆ๋‹ค. GetTextMask node์™€ DetailTransfer node๋ฅผ ํ™œ์šฉํ•ด ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    • Upscaled results + Text detail transfer

      upsvaled_results

    ๐Ÿ›  Approach

    • Background: Inpainting

    Diffusion ๋ชจ๋ธ์˜ Inpainting์€ ๋งˆ์Šคํฌ๋ฅผ ์กฐ๊ฑด์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ƒ˜ํ”Œ๋ง ๋‹จ๊ณ„์—์„œ ๋งˆ์Šคํฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์›๋ณธ๊ณผ ์ƒ์„ฑ๋œ ์ž ์žฌ ๊ณต๊ฐ„์„ ํ•ฉ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์€ ์ž…๋ ฅ ๊ฐ์ฒด๋ฅผ ์œ ์ง€ํ•˜๋ฉด์„œ ๋งˆ์Šคํฌ ์˜์—ญ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ €ํ’ˆ์งˆ ์ž…๋ ฅ ๊ฐ์ฒด(์˜ˆ: ์Šค๋งˆํŠธํฐ์œผ๋กœ ์ดฌ์˜)์˜ ๊ฒฝ์šฐ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€ ํ’ˆ์งˆ๋„ ์ €ํ•˜๋˜๋Š” ํ•œ๊ณ„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

    • Background: IC-Light

    IC-Light๋Š” ์ „๊ฒฝ๊ณผ ๋ฐฐ๊ฒฝ์˜ ์กฐ๋ช…์„ ์กฐ์ž‘ํ•˜๋Š” ํ˜์‹ ์ ์ธ Adapter Unet์ž…๋‹ˆ๋‹ค. ์ž…๋ ฅ ๊ฐ์ฒด์˜ ์žฌ์กฐ๋ช…์„ ํ†ตํ•ด ์ €ํ’ˆ์งˆ ๊ฐ์ฒด๋„ ์šฐ์ˆ˜ํ•œ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ „๊ฒฝ ์ƒ์„ฑ ๊ณผ์ •์—์„œ ๊ฐ์ฒด ์„ธ๋ถ€ ์‚ฌํ•ญ์ด ๋ณ€ํ˜•๋˜๋Š” ๋ฌธ์ œ๋Š” ์—ฌ์ „ํžˆ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

    • Background: Kandinsky Inpainting Process

    Kandinsky diffusion inpainting์€ ์ผ๋ฐ˜์ ์ธ inpainting๊ณผ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒ˜ํ”Œ๋ง ๋‹จ๊ณ„๋งˆ๋‹ค ์ž ์žฌ ๊ณต๊ฐ„์„ ํ•ฉ์„ฑํ•  ๋•Œ, ์›๋ณธ ๋Œ€์‹  scheduler์˜ sigma ๊ฐ’์— ๋”ฐ๋ฅธ ๋…ธ์ด์ฆˆ๊ฐ€ ์ถ”๊ฐ€๋œ ์ž ์žฌ ๊ณต๊ฐ„์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฐฉ์‹์€ ์ผ๊ด€๋œ ๋…ธ์ด์ฆˆ๋ฅผ ํ†ตํ•ด ํ’ˆ์งˆ ํ–ฅ์ƒ์„ ์ด๋Œ์–ด๋ƒ…๋‹ˆ๋‹ค.

    • Background: CLIP Skip

    CLIP Skip์€ ํ…์ŠคํŠธ ์กฐ๊ฑด์„ ์ ์šฉํ•  ๋•Œ, ์ƒ˜ํ”Œ๋ง ๊ณผ์ •์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„๊นŒ์ง€ ์ ์šฉํ•˜์ง€ ์•Š๊ณ  ์ค‘๊ฐ„์— ์ค‘๋‹จํ•˜๋Š” ์ถ”๋ก  ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ด๋Š” ์กฐ๊ฑด์„ ์ œ์–ดํ•˜์—ฌ ์ „์ฒด ๋งฅ๋ฝ์— ๋ถ€ํ•ฉํ•˜๋Š” ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

    • Solution: Latent injection

      latent_injection_flow

      math

      $X_t$ : sample

      $M$ : product mask

      $P$ : product latent

      $CO$ : composition operation(ex: add, overlay, soft light etc.)

      ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํŠน์ง• ๋ณด์กด๊ณผ ์˜๋ฏธ ์žˆ๋Š” ์กฐ๋ช… ๋ณ€ํ™”๋ฅผ ๋™์‹œ์— ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋ณตํ•ฉ์ ์ธ ์ „๋žต์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ƒ˜ํ”Œ๋ง ๊ณผ์ •์—์„œ ๋…ธ์ด์ฆˆ๊ฐ€ ์ถ”๊ฐ€๋œ ์ž ์žฌ ๊ณต๊ฐ„์„ ๋ณตํ•ฉ ์—ฐ์‚ฐํ•˜์—ฌ ๊ฐ์ฒด์˜ ์„ธ๋ถ€ ํŠน์ง•์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ IC-Light์˜ ์ „์—ญ์  ์กฐ๋ช… ๋ณ€ํ™” ํŠน์„ฑ์„ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด ์ƒ˜ํ”Œ๋ง์˜ ์ดˆ๊ธฐ์™€ ํ›„๊ธฐ ๋‹จ๊ณ„๋ฅผ ์„ ํƒ์ ์œผ๋กœ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค. ์ด ๋ฐฉ์‹์€ scheduler์˜ sigma ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์ž‘๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์–‘ํ•œ scheduler ์œ ํ˜•์— ๋Œ€ํ•ด ์•ˆ์ •์ ์ธ ์„ฑ๋Šฅ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ๊ฐ์ฒด์˜ ๊ณ ์œ ํ•œ ํŠน์„ฑ์„ ๋ณด์กดํ•˜๋ฉด์„œ๋„ ์กฐ๋ช… ํšจ๊ณผ๋ฅผ ์œ ๋™์ ์œผ๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๐Ÿ“ฅ Install

    cd custom_nodes
    git clone {this repository}
    pip install -r requirements.txt
    

    ๐Ÿ–ฅ How to use

    ComfyUI-workflows

    • IC-Light + controlnet + text condition + Text transfer + Latent Injection latent_injection_flow

      ์—ฌ๊ธฐ์„œ workflow๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    • IC-Light + controlnet + IP-Adapter + Text transfer + Latent Injection latent_injection_flow

      ์—ฌ๊ธฐ์„œ workflow๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๐Ÿ“š Reference

    This project is based on research and code from several papers and open-source repositories.

    • IC-Light: https://github.com/lllyasviel/IC-Light
    • kandinsky2.2: https://github.com/ai-forever/Kandinsky-2
    • clip-skip: https://medium.com/@natsunoyuki/clip-skip-with-the-diffusers-library-b2b63f38a443
    • Anton Razzhigaev,ย Arseniy Shakhmatov, Kandinsky: an Improved Text-to-Image Synthesis with Image Prior and Latent Diffusion, arXiv, 2023
    • Chuanxia Zheng,ย Long Tung Vuong,ย Jianfei Cai,ย Dinh Phung, MoVQ: Modulating Quantized Vectors for High-Fidelity Image Generation, arXiv, 2022

    ๐Ÿ“„ License

    MIT License
    
    Copyright (c) 2024 middlek
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    

    ๐Ÿ“ž Contact

    middlek - [email protected]