ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ComfyUI) 이미지를 프롬프트로 바꾸는 방법
    Stable Diffusion 2024. 10. 17. 23:27
    반응형

    ComfyUI의 커스텀 노드를 활용해 이미지에서 프롬프트를 추출하는 방법을 알아보겠습니다. 이미지에서 추출한 프롬프트로 생성된 이미지는 원본 이미지와 상당한 차이가 있을 수 있습니다. 원본과 유사한 이미지를 생성하고 싶다면 Img to Img 방식을 사용하거나, ControlNet을 활용하는 것이 좋습니다. ControlNet 사용방법은 이전 블로그 글을 참고해 주세요.

     

    ComfyUI) ControlNet 사용법 + XY plot

    ControlNet이란?ControlNet은 이미지 생성 과정을 세밀하게 제어할 수 있도록 도와주는 확장 기능입니다.ControlNet 사용을 위한 노드Load ControlNet Model : ControlNet 모델을 불러오기 위한 노드입니다. 여기에

    astorynotheavy.tistory.com

    이미지에서 프롬프트를 추출하는 방법은 여러 가지가 있지만, 최근에는 LLM(Large Language Models)을 활용하는 방법이 많이 사용되고 있습니다. LLM을 활용하는 방법으로는 Ollama 모델이나 Florence2 모델을 사용하는 방법이 있으나, 이들 방법은 사용법이 복잡하거나 고성능 GPU가 필요한 단점이 있습니다. 따라서, 사용법이 간단하고 RTX 3060 12G에서도 원활하게 사용할 수 있는 방법을 소개해 드리겠습니다. 바로 Florence-2-base-PromptGen-v1.5 모델을 사용하는 방법입니다. 이 모델은 ComfyUI에서 활용할 수 있도록 Florence2 모델을 미세 조정한 것입니다. 이 모델을 사용하려면 MiaoshouAI-Tagger 노드를 설치해야 합니다. 지금부터 자세히 알아보겠습니다. 

    MiaoshouAI-Tagger 노드 설치

    Custom Nodes Manager에서 Miaoshouai를 검색한 후 나타나는 ComfyUI-Miaoshouai-Tagger를 설치하고, 재시작하면 설치가 완료됩니다. 

    ComfyUI Custom Nodes Manager

    Miaoshouai-Tagger 노드 사용방법

    MiaoshouAI-Tagger 노드를 설치하면 3가지 노드를 사용할 수 있습니다. MiaoshouAI Tagger, MiaoshouAI Save Tags, MiaoshouAI Flux Clip Text Encode입니다. 이 중 MiaoshouAI 노드가 이미지에서 프롬프트를 추출하는 노드이므로, 이 노드의 사용법을 알아보겠습니다. 참고로, MiaoshouAI Save Tags 노드는 폴더에 있는 이미지들의 프롬프트를 파일로 저장하는 역할을 하며, MiaoshouAI Flux Clip Text Encode 노드는 Flux 모델에 사용하기 편리한 노드입니다. 관심이 있으시면 한 번 사용해 보시기 바랍니다. 

    MiaoshouAI Tagger 노드

    MiaoshouAI Tagger 노드

    MiaoshouAI Tagger 노드의 사용방법은 매우 간단합니다. 먼저 model 항목에서 사용할 모델을 선택해 설치합니다. 사용 가능한 모델은 promptgen_base_v1.5와 promptgen_large_v1.5입니다. 선택한 모델은 워크플로우 실행 시 자동으로 다운로드됩니다. 만약 모델이 다운로드되지 않거나 오류가 발생한다면, ComfyUI\models\LLM 폴더에 있는 모델을 삭제한 후 다시 워크플로우를 실행하면 오류 없이 진행될 것입니다. 

    caption_method는 추출할 프롬프트의 형식을 지정하는 항목입니다. 선택 가능한 옵션으로는 tag, simple, structured, detailed, mixed의 5가지가 있고, 각 옵션의 특징은 아래와 같습니다. 적절한 방법을 선택해 프롬프트를 추출하시면 됩니다. 

    • tag : 키워드 추출
    • simple : 간단한 프롬프트 생성
    • structured : 이미지의 사물 위치와 구조를 프롬프트에 반영
    • detailed : 자세한 프롬프트 생성
    • mixed : detailed에서 생성된 프롬프트 뒤에 tag에서 생성된 키워드를 추가

    적절한 방법을 선택해 프롬프트를 추출하시면 됩니다. 

    기타 설정은 기본값으로 사용하셔도 무방합니다. 

    노드 하단에 텍스트를 입력할 수 있는 3가지 항목이 있습니다. prefix_caption, suffix_caption, replace_tags입니다. prefix_caption은 생성된 프롬프트 앞에 추가할 텍스트를 입력하는 곳입니다. 예를 들어, Pony 모델을 사용할 때 자주 사용하는 score_9, score_8_up, score_7_up 같은 태그나 화질 관련 태그를 추가할 때 유용합니다. suffix_caption은 프롬프트 뒤에 텍스트를 추가하는 항목으로, 필요한 내용을 입력하시면 됩니다. replace_tags는 생성된 태그를 다른 태그로 변경할 때 사용합니다. 

    만약 아래의 프롬프트 입력란이 구분되어 보이지 않는다면, 노드의 크기를 늘리면 정상적으로 보일 것입니다. 

    Workflow

    MiaoshouAI Tagger 워크플로우

    이미지에서 프롬프트를 추출하기 위해 필요한 노드는 3가지입니다. MiaoshouAI Tagger 노드, Load Image 노드 그리고 Show Text 노드입니다. Load Image 노드는 이미지를 불러오는 역할을 하, Show Text 노드는 생성된 프롬프트를 출력하는 역할을 합니다. 노드들은 위 그림과 같이 연결하시면 되며, 첨부된 워크플로우를 참고해 주세요. 

    MiaoshouAI Tagger.json
    0.00MB

     

    프롬프트 추출 및 결과

    앞에서 설명한 워크플로우를 이용하여 아래 이미지에 프롬프트를 추출해 보겠습니다. 

    tags
    flower, outdoors, sky, day, cloud, tree, blue sky, no humans, petals, building, scenery, street, power lines, cherry blossoms.
    simple
    a scenic street lined with cherry blossom trees in full bloom, creating a vibrant and lively atmosphere.
    structured
    a serene street lined with cherry blossom trees in full bloom, the trees are positioned on both sides of the road, creating a sense of depth and perspective, the street is empty, with no cars or people present, in the background, a clear blue sky with fluffy white clouds and scattered petals of cherry blossoms can be seen, adding a touch of tranquility to the scene, on either side of the street, small houses with their roofs and windows are visible, while utility poles and wires stretch along the sides, the overall atmosphere is peaceful and idyllic, inviting the viewer to step into the tranquil world of this picturesque street.
    detailed
    a highly detailed digital illustration depicting a serene, rural street lined with tall, cherry blossom trees, the trees are in full bloom, their branches adorned with delicate pink petals, creating a beautiful contrast against the clear blue sky with fluffy white clouds, the street is paved with a smooth, white line dividing the center of the road, and the shadows cast by the trees create a sense of depth and dimension, on either side of the street, there are traditional japanese-style houses with sloping roofs and wooden walls, adding to the rural setting, the houses are surrounded by lush greenery, enhancing the serene atmosphere, the overall style of the illustration is realistic with a slight anime influence, characterized by smooth textures and vibrant colors, highly polished, with a high level of detail in both the trees and the sky, giving it a lifelike quality.
    mixed
    a highly detailed digital illustration depicting a serene, rural street lined with tall, cherry blossom trees, the trees are in full bloom, their branches adorned with delicate pink petals, creating a beautiful contrast against the clear blue sky with fluffy white clouds, the street is paved with smooth, white lines, and the buildings on either side are traditional japanese-style houses with dark brown roofs and beige walls, the buildings are positioned along the sides of the street, adding depth and perspective to the scene, the overall style is realistic with a slight anime influence, characterized by clean lines and vibrant colors, highly polished, with a high level of detail in the textures and shading, giving the scene a lifelike quality, the image exudes a sense of tranquility and natural beauty, enhanced by the serene street and the peaceful atmosphere of the setting \(konosuba\), 1girl, solo, looking at viewer, flower, outdoors, sky, day, cloud, tree, blue sky, no humans, building, flower pot, electricity, street, cherry blossoms.

    프롬프트 추출 결과, 선택한 caption_method에 따라 다양한 형식의 프롬프트가 생성되었습니다. 이렇게 추출된 프롬프트는 이미지 생성에 효과적으로 활용될 수 있으며, 원하는 스타일이나 세부 사항을 반영한 이미지를 만들 때 큰 도움이 됩니다. 특히, MiaoshouAI Tagger 노드는 간단한 설정으로 고품질 프롬프트를 제공하므로 다양한 이미지 생성 워크플로우에 쓰일 수 있습니다. 이를 통해 보다 창의적이고 효율적인 작업을 진행해 보시기 바랍니다. 

    Additional Information

    프롬프트 추출 및 이미지 생성 워크플로우 + FaceDetailer

    프롬프트 추출과 동시에 이미지를 생성하는 워크플로우(FaceDetailer 추가)
    MiaoshouAI Tagger + Image generate + FaceDetailer.json
    0.02MB

     

    프롬프트 추출과 동시에 이미지를 생성하려면, 위의 워크플로우를 참고하시기 바랍니다. 연결이 복잡하기 때문에 Efficient 노드를 사용하였습니다. 

    Caption_method의 종류에 따른 이미지 생성 결과

    특이사항

    Caption_method 중 tags를 이용해 왼쪽 마법사의 프롬프트를 추출하면 다음과 같이 생성됩니다. 

    1girl, solo, long hair, looking at viewer, blue eyes, long sleeves, holding, jewelry, white hair, male focus, cape, holding weapon, crown, staff, magic

    추출된 프롬프트에 1girl이 포함되어 있으므로 여성의 이미지가 생성되어야 하지만, 여러 번 이미지를 생성해도 남성 이미지가 나타납니다. 이는 처음에 나오는 1girl 프롬프트보다 male 관련 태그가 더 강하게 작용하는 것으로 보입니다. 

    반응형

    댓글

Designed by Vitual Stylist