Buckets:

mishig's picture
|
download
raw
40 kB

인페인팅

Inpainting은 이미지의 특정 영역을 대체하거나 편집합니다. 이는 결함 및 아티팩트 제거와 같은 이미지 복원, 또는 이미지 영역을 완전히 새로운 것으로 대체하는 데 유용한 도구입니다. Inpainting은 이미지를 채울 영역을 결정하기 위해 마스크에 의존합니다. inpaint할 영역은 흰색 픽셀로, 유지할 영역은 검은색 픽셀로 표시됩니다. 흰색 픽셀은 프롬프트에 의해 채워집니다.

🤗 Diffusers를 사용하면 다음과 같이 inpainting을 수행할 수 있습니다:

  1. AutoPipelineForInpainting 클래스를 사용하여 inpainting 체크포인트를 로드합니다. 체크포인트에 따라 로드할 적절한 파이프라인 클래스를 자동으로 감지합니다:
import torch
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image, make_image_grid

pipeline = AutoPipelineForInpainting.from_pretrained(
    "kandinsky-community/kandinsky-2-2-decoder-inpaint", dtype=torch.float16
)
pipeline.enable_model_cpu_offload()
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
pipeline.enable_xformers_memory_efficient_attention()

가이드 전반에서 메모리를 절약하고 추론 속도를 높이기 위해 enable_model_cpu_offload()와 enable_xformers_memory_efficient_attention()를 사용하는 것을 확인할 수 있습니다. PyTorch 2.0을 사용하는 경우, 파이프라인에서 enable_xformers_memory_efficient_attention()를 호출할 필요가 없으며, PyTorch 2.0의 네이티브 scaled-dot product attention를 이미 사용하고 있기 때문입니다.

  1. 베이스 이미지와 마스크 이미지를 로드합니다:
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png")
mask_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png")
  1. 이미지를 인페인팅할 프롬프트를 생성하고, base 이미지와 mask 이미지를 함께 파이프라인에 전달합니다:
prompt = "a black cat with glowing eyes, cute, adorable, disney, pixar, highly detailed, 8k"
negative_prompt = "bad anatomy, deformed, ugly, disfigured"
image = pipeline(prompt=prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask_image).images[0]
make_image_grid([init_image, mask_image, image], rows=1, cols=3)
베이스 이미지



마스크 이미지



생성된 이미지

마스크 이미지 생성

이 가이드에서는 편의를 위해 모든 코드 예제에 마스크 이미지가 제공됩니다. 사용자 자신의 이미지로 인페인팅을 수행할 수 있지만, 이를 위해 마스크 이미지를 생성해야 합니다. 아래 Space를 사용하여 마스크 이미지를 쉽게 생성해 보세요.

인페인팅할 기본 이미지를 업로드하고 스케치 도구를 사용해 마스크를 그려 보세요. 완료되면 Run을 클릭하여 마스크 이미지를 생성하고 다운로드하세요.

Xet Storage Details

Size:
40 kB
·
Xet hash:
7d602cf277796abe7045f4db06cc73a80066773f39b9b0356727324583b93f67

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.