Image to Image는 입력 이미지를 가져와 출력 이미지로 변환하는 작업입니다.
이러한 유형의 작업은 스타일 전송, 색상화, 초고해상도 등과 같은 다양한 상황에 적용할 수 있습니다.
!wget https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg/660px-Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg -O ./dataset/mountain.jpg
--2024-05-19 17:10:06-- https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg/660px-Everest_North_Face_toward_Base_Camp_Tibet_Luca_Galuzzi_2006.jpg
Resolving upload.wikimedia.org (upload.wikimedia.org)... 103.102.166.240, 2001:df2:e500:ed1a::2:b
Connecting to upload.wikimedia.org (upload.wikimedia.org)|103.102.166.240|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 98683 (96K) [image/jpeg]
Saving to: ‘./dataset/mountain.jpg’
./dataset/mountain. 100%[===================>] 96.37K 493KB/s in 0.2s
2024-05-19 17:10:07 (493 KB/s) - ‘./dataset/mountain.jpg’ saved [98683/98683]
import torch
from PIL import Image
from diffusers import StableDiffusionImg2ImgPipeline
model_id_or_path = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
model_id_or_path,
torch_dtype=torch.float32
)
pipe = pipe.to("cuda")
init_image = Image.open("dataset/mountain.jpg").convert("RGB").resize((768, 512))
init_image
/home/kubwa/anaconda3/envs/pytorch/lib/python3.11/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
warnings.warn(
model_index.json: 0%| | 0.00/541 [00:00<?, ?B/s]
Fetching 15 files: 0%| | 0/15 [00:00<?, ?it/s]
model.safetensors: 0%| | 0.00/1.22G [00:00<?, ?B/s]
model.safetensors: 0%| | 0.00/492M [00:00<?, ?B/s]
(…)ature_extractor/preprocessor_config.json: 0%| | 0.00/342 [00:00<?, ?B/s]
scheduler/scheduler_config.json: 0%| | 0.00/308 [00:00<?, ?B/s]
tokenizer/special_tokens_map.json: 0%| | 0.00/472 [00:00<?, ?B/s]
text_encoder/config.json: 0%| | 0.00/617 [00:00<?, ?B/s]
tokenizer/merges.txt: 0%| | 0.00/525k [00:00<?, ?B/s]
safety_checker/config.json: 0%| | 0.00/4.72k [00:00<?, ?B/s]
diffusion_pytorch_model.safetensors: 0%| | 0.00/3.44G [00:00<?, ?B/s]
tokenizer/vocab.json: 0%| | 0.00/1.06M [00:00<?, ?B/s]
unet/config.json: 0%| | 0.00/743 [00:00<?, ?B/s]
tokenizer/tokenizer_config.json: 0%| | 0.00/806 [00:00<?, ?B/s]
vae/config.json: 0%| | 0.00/547 [00:00<?, ?B/s]
diffusion_pytorch_model.safetensors: 0%| | 0.00/335M [00:00<?, ?B/s]
Loading pipeline components...: 0%| | 0/7 [00:00<?, ?it/s]
prompt = "A fantasy landscape, trending on artstation"
images = pipe(
prompt=prompt,
image=init_image,
strength=0.75,
guidance_scale=7.5).images
images[0]
0%| | 0/37 [00:00<?, ?it/s]