# ๐ŸŽจ ComfyUI-productfix ![middlek_project_header](assets/middlek_git_header.png) e-commerce ์ƒํ’ˆ์˜ ํ…์ŠคํŠธ, ๋กœ๊ณ , ๋””ํ…Œ์ผ ๋“ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ComfyUI ์ปค์Šคํ…€ ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค. ## ๐ŸŽฌ Demo ![project_header](assets/project_header.png) ์Šค๋งˆํŠธํฐ์œผ๋กœ ์ฐ์€ ๋‚ด ๋ฐฉ ๋ฌผ๊ฑด(์ƒ‰๋ณด์ • X)๋“ค๋กœ ์ƒ์„ฑํ•œ AI ์ด๋ฏธ์ง€ ## ๐Ÿ“Œ Index - [Introduction](#-introduction) - [Features](#-features) - [Application](#๏ธ-application) - [Approach](#-approach) - [Install](#-install) - [How to use](#-how-to-use) ## ๐Ÿš€ Introduction Stable diffusion์œผ๋กœ ์ƒ์„ฑํ•œ ์ด๋ฏธ์ง€๋Š” ์‹œ๊ฐ์ ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ์ถฉ์‹ค๋„๊ฐ€ ๋†’์€ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜์ง€๋งŒ, ์ƒ์„ฑ ๊ณผ์ •์—์„œ ์ž…๋ ฅ ๊ฐ์ฒด๊ฐ€ ๋ณ€ํ˜•๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๊ฐ์ฒด์— ํ…์ŠคํŠธ์™€ ๋ธŒ๋žœ๋“œ ๋กœ๊ณ  ๊ฐ™์ด ์ธ์œ„์  ๊ทœ์น™์„ฑ์„ ๊ฐ€์ง„ ์š”์†Œ์—์„œ ์ด ๋ฌธ์ œ๊ฐ€ ๋‘๋“œ๋Ÿฌ์ง‘๋‹ˆ๋‹ค. ์ด๋Ÿฐ **๋ณ€ํ˜• ๋ฌธ์ œ๋Š” e-commerce ํ™˜๊ฒฝ์—์„œ ํŒ๋งคํ•˜๋Š” ์‹ค์ œ ์ƒํ’ˆ์— ์ ์šฉํ•  ๊ฒฝ์šฐ ์‹ฌ๊ฐํ•œ ์ œ์•ฝ**์œผ๋กœ ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค. **Productfix**๋Š” ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํŠน์„ฑ(ํ…์ŠคํŠธ, ๋กœ๊ณ , ๋””ํ…Œ์ผ ๋“ฑ)์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” **Latent injection**์ด๋ผ๋Š” AI application์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ์ฒด์˜ ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ๋ณด์กดํ•˜๋Š”๋ฐ ๋„์›€์ด ๋˜๋Š” ์ถ”๊ฐ€์ ์ธ ๋…ธ๋“œ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด ๋…ธ๋“œ๋ฅผ ํ†ตํ•ด ๊ธฐ์กด์˜ ๋””์ž์ธ ํˆด(ํฌํ† ์ƒต, ์ผ๋Ÿฌ์ŠคํŠธ๋ ˆ์ดํ„ฐ ๊ฐ™์€)๋กœ ํ•ด์•ผ๋งŒ ํ–ˆ๋˜ ํ›„์ฒ˜๋ฆฌ ์ž‘์—…์„ ๋Œ€ํญ ์ค„์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์œผ๋กœ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค. ComfyUI์—์„œ custom node๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ๋ถ„์˜ ์›Œํฌํ”Œ๋กœ์šฐ์— ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ## ๐Ÿ’ก Features
Apply Latent Injection
Get Text Mask
Reset Model Patcher Calculate Weight
## ๐Ÿƒ๐Ÿปโ€โ™‚๏ธ 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](assets/iclight_injection.png) 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](assets/iclight_injection_adapter.png) prompt: product photo, professional photography, realistic / seed: 42

Latent injection์€ IC-Light์™€ IP-Adapter๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ๋•Œ ์ง„๊ฐ€๋ฅผ ๋ฐœํœ˜ํ•ฉ๋‹ˆ๋‹ค.ํ…œํ”Œ๋ฆฟ ์Šคํƒ€์ผ ์ด๋ฏธ์ง€์™€ ์ƒํ’ˆ์„ ํ•ฉ์„ฑํ•  ๋•Œ ์‚ฌ์šฉํ•ด๋ณด์„ธ์š”! - ### **IC-Light + controlnet + text condition + Text transfer + Latent Injection** ![latent_injection_text](assets/more_results_0.png) Items in my room captured with my phone camera ![latent_injection_text](assets/more_results_1.png) prompt: product photo, professional photography, realistic, water, bubble / seed: 42 / controlnet: depth ![latent_injection_text](assets/more_results_2.png) prompt: product photo, professional photography, realistic, flowers, outdoors / seed: 42 / controlnet: depth - ### **IC-Light + controlnet + IP-Adapter + Text transfer + Latent Injection** ![latent_injection_adapter](assets/more_results_0.png) Items in my room captured with my phone camera ![latent_injection_adapter](assets/more_results_3.png) prompt: product photo, professional photography, realistic / seed: 42 / controlnet: depth ![latent_injection_adapter](assets/more_results_4.png) prompt: product photo, professional photography, realistic / seed: 42 / controlnet: depth - ### **Text transfer** ![producfix_src](assets/productfix_src.png) Input / text condition / image condition(IP-Adapter) ![productfix_text](assets/productfix_text.png) only IC-Light / **Latent injection** / detail transfer / **Text transfer** ![producfix_text_closeup](assets/productfix_text_closeup.png) close up

![productfix_adapter](assets/productfix_adapter.png) only IC-Light / **Latent injection** / detail transfer / **Text transfer** ![producfix_adapter_closeup](assets/productfix_adapter_closeup.png) close up

Text transfer๋Š” ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํ…์ŠคํŠธ๋ฅผ ๋ณด์กดํ•˜๊ธฐ ์œ„ํ•ด ๊ฐœ๋ฐœ๋œ OCR ํ…์ŠคํŠธ ๋งˆ์Šคํฌ ๊ธฐ๋ฐ˜ Detail transfer application์ž…๋‹ˆ๋‹ค. `GetTextMask` node์™€ `DetailTransfer` node๋ฅผ ํ™œ์šฉํ•ด ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. - ### **Upscaled results + Text detail transfer** ![upsvaled_results](assets/upscaled_results.png) ## ๐Ÿ›  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](assets/latent_injection_flow.jpg) $$ X_t=\begin{cases} CO(X_{t}\cdot M,(P+\eta\cdot\sigma_t)\cdot inv(M),&\sigma_{end} \leq \sigma_t \leq \sigma_{start} \\ X_t,& otherwise\end{cases} $$ $X_t$ : sample $M$ : product mask $P$ : product latent $CO$ : composition operation(ex: add, overlay, soft light etc.) ์ž…๋ ฅ ๊ฐ์ฒด์˜ ํŠน์ง• ๋ณด์กด๊ณผ ์˜๋ฏธ ์žˆ๋Š” ์กฐ๋ช… ๋ณ€ํ™”๋ฅผ ๋™์‹œ์— ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋ณตํ•ฉ์ ์ธ ์ „๋žต์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. **์ƒ˜ํ”Œ๋ง ๊ณผ์ •์—์„œ ๋…ธ์ด์ฆˆ๊ฐ€ ์ถ”๊ฐ€๋œ ์ž ์žฌ ๊ณต๊ฐ„์„ ๋ณตํ•ฉ ์—ฐ์‚ฐํ•˜์—ฌ ๊ฐ์ฒด์˜ ์„ธ๋ถ€ ํŠน์ง•์„ ์œ ์ง€**ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ IC-Light์˜ ์ „์—ญ์  ์กฐ๋ช… ๋ณ€ํ™” ํŠน์„ฑ์„ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด **์ƒ˜ํ”Œ๋ง์˜ ์ดˆ๊ธฐ์™€ ํ›„๊ธฐ ๋‹จ๊ณ„๋ฅผ ์„ ํƒ์ ์œผ๋กœ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.** ์ด ๋ฐฉ์‹์€ scheduler์˜ sigma ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์ž‘๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์–‘ํ•œ scheduler ์œ ํ˜•์— ๋Œ€ํ•ด ์•ˆ์ •์ ์ธ ์„ฑ๋Šฅ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ๊ฐ์ฒด์˜ ๊ณ ์œ ํ•œ ํŠน์„ฑ์„ ๋ณด์กดํ•˜๋ฉด์„œ๋„ ์กฐ๋ช… ํšจ๊ณผ๋ฅผ ์œ ๋™์ ์œผ๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ## ๐Ÿ“ฅ Install ```bash 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](assets/productfix_text_comfyui.png) [์—ฌ๊ธฐ์„œ](workflows/productfix_text.json) workflow๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - **IC-Light + controlnet + IP-Adapter + Text transfer + Latent Injection** ![latent_injection_flow](assets/productfix_adapter_comfyui.png) [์—ฌ๊ธฐ์„œ](workflows/productfix_adapter.json) 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 ml-favorfit-develop 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 - middlekcenter@gmail.com