mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-27 17:22:53 +03:00
* feat) optimization kr translation * fix) typo, italic setting * feat) dreambooth, text2image kr * feat) lora kr * fix) LoRA * fix) fp16 fix * fix) doc-builder style * fix) fp16 ์ผ๋ถ ๋จ์ด ์์ * fix) fp16 style fix * fix) opt, training docs update * merge conflict * Fix community pipelines (#3266) * Allow disabling torch 2_0 attention (#3273) * Allow disabling torch 2_0 attention * make style * Update src/diffusers/models/attention.py * Release: v0.16.1 * feat) toctree update * feat) toctree update * Fix custom releases (#3708) * Fix custom releases * make style * Fix loading if unexpected keys are present (#3720) * Fix loading * make style * Release: v0.17.0 * opt_overview * commit * Create pipeline_overview.mdx * unconditional_image_generatoin_1stDraft * โจ Add translation for write_own_pipeline.mdx * conditional-์ง์ญ, ์ธ์ปจ๋์ ๋ * unconditional_image_generation first draft * reviese * Update pipeline_overview.mdx * revise-2 * โป๏ธ translation fixed for write_own_pipeline.mdx * complete translate basic_training.mdx * other-formats.mdx ๋ฒ์ญ ์๋ฃ * fix tutorials/basic_training.mdx * other-formats ์์ * inpaint ํ๊ตญ์ด ๋ฒ์ญ * depth2img translation * translate training/adapt-a-model.mdx * revised_all * feedback taken * using_safetensors.mdx_first_draft * custom_pipeline_examples.mdx_first_draft * img2img ํ๊ธ๋ฒ์ญ ์๋ฃ * tutorial_overview edit * reusing_seeds * torch2.0 * translate complete * fix) ์ฉ์ด ํต์ผ ๊ท์ฝ ๋ฐ์ * [fix] ํผ๋๋ฐฑ์ ๋ฐ์ํด์ ๋ฒ์ญ ๋ณด์ * ์คํ์ ์ ์ + ์ปจ๋ฒค์ ์๋ฐฐ๋ ๋ถ๋ถ ์ ์ * typo, style fix * toctree update * copyright fix * toctree fix * Update _toctree.yml --------- Co-authored-by: Chanran Kim <seriousran@gmail.com> Co-authored-by: apolinรกrio <joaopaulo.passos@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Lee, Hongkyu <75282888+howsmyanimeprofilepicture@users.noreply.github.com> Co-authored-by: hyeminan <adios9709@gmail.com> Co-authored-by: movie5 <oyh5800@naver.com> Co-authored-by: idra79haza <idra79haza@github.com> Co-authored-by: Jihwan Kim <cuchoco@naver.com> Co-authored-by: jungwoo <boonkoonheart@gmail.com> Co-authored-by: jjuun0 <jh061993@gmail.com> Co-authored-by: szjung-test <93111772+szjung-test@users.noreply.github.com> Co-authored-by: idra79haza <37795618+idra79haza@users.noreply.github.com> Co-authored-by: howsmyanimeprofilepicture <howsmyanimeprofilepicture@gmail.com> Co-authored-by: hoswmyanimeprofilepicture <hoswmyanimeprofilepicture@gmail.com>
100 lines
3.9 KiB
Plaintext
100 lines
3.9 KiB
Plaintext
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations under the License.
|
|
-->
|
|
|
|
# ํ
์คํธ ๊ธฐ๋ฐ image-to-image ์์ฑ
|
|
|
|
[[Colab์์ ์ด๊ธฐ]]
|
|
|
|
[`StableDiffusionImg2ImgPipeline`]์ ์ฌ์ฉํ๋ฉด ํ
์คํธ ํ๋กฌํํธ์ ์์ ์ด๋ฏธ์ง๋ฅผ ์ ๋ฌํ์ฌ ์ ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑด์ ์ง์ ํ ์ ์์ต๋๋ค.
|
|
|
|
์์ํ๊ธฐ ์ ์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ์ค์น๋์ด ์๋์ง ํ์ธํ์ธ์:
|
|
|
|
```bash
|
|
!pip install diffusers transformers ftfy accelerate
|
|
```
|
|
|
|
[`nitrosocke/Ghibli-Diffusion`](https://huggingface.co/nitrosocke/Ghibli-Diffusion)๊ณผ ๊ฐ์ ์ฌ์ ํ์ต๋ stable diffusion ๋ชจ๋ธ๋ก [`StableDiffusionImg2ImgPipeline`]์ ์์ฑํ์ฌ ์์ํ์ธ์.
|
|
|
|
|
|
```python
|
|
import torch
|
|
import requests
|
|
from PIL import Image
|
|
from io import BytesIO
|
|
from diffusers import StableDiffusionImg2ImgPipeline
|
|
|
|
device = "cuda"
|
|
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("nitrosocke/Ghibli-Diffusion", torch_dtype=torch.float16).to(
|
|
device
|
|
)
|
|
```
|
|
|
|
์ด๊ธฐ ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ์ฌ์ ์ฒ๋ฆฌํ์ฌ ํ์ดํ๋ผ์ธ์ ์ ๋ฌํ ์ ์์ต๋๋ค:
|
|
|
|
```python
|
|
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
|
|
|
response = requests.get(url)
|
|
init_image = Image.open(BytesIO(response.content)).convert("RGB")
|
|
init_image.thumbnail((768, 768))
|
|
init_image
|
|
```
|
|
|
|
<div class="flex justify-center">
|
|
<img src="https://huggingface.co/datasets/YiYiXu/test-doc-assets/resolve/main/image_2_image_using_diffusers_cell_8_output_0.jpeg"/>
|
|
</div>
|
|
|
|
<Tip>
|
|
|
|
๐ก `strength`๋ ์
๋ ฅ ์ด๋ฏธ์ง์ ์ถ๊ฐ๋๋ ๋
ธ์ด์ฆ์ ์์ ์ ์ดํ๋ 0.0์์ 1.0 ์ฌ์ด์ ๊ฐ์
๋๋ค. 1.0์ ๊ฐ๊น์ด ๊ฐ์ ๋ค์ํ ๋ณํ์ ํ์ฉํ์ง๋ง ์
๋ ฅ ์ด๋ฏธ์ง์ ์๋ฏธ์ ์ผ๋ก ์ผ์นํ์ง ์๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
|
|
|
|
</Tip>
|
|
|
|
ํ๋กฌํํธ๋ฅผ ์ ์ํ๊ณ (์ง๋ธ๋ฆฌ ์คํ์ผ(Ghibli-style)์ ๋ง๊ฒ ์กฐ์ ๋ ์ด ์ฒดํฌํฌ์ธํธ์ ๊ฒฝ์ฐ ํ๋กฌํํธ ์์ `ghibli style` ํ ํฐ์ ๋ถ์ฌ์ผ ํฉ๋๋ค) ํ์ดํ๋ผ์ธ์ ์คํํฉ๋๋ค:
|
|
|
|
```python
|
|
prompt = "ghibli style, a fantasy landscape with castles"
|
|
generator = torch.Generator(device=device).manual_seed(1024)
|
|
image = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5, generator=generator).images[0]
|
|
image
|
|
```
|
|
|
|
<div class="flex justify-center">
|
|
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ghibli-castles.png"/>
|
|
</div>
|
|
|
|
๋ค๋ฅธ ์ค์ผ์ค๋ฌ๋ก ์คํํ์ฌ ์ถ๋ ฅ์ ์ด๋ค ์ํฅ์ ๋ฏธ์น๋์ง ํ์ธํ ์๋ ์์ต๋๋ค:
|
|
|
|
```python
|
|
from diffusers import LMSDiscreteScheduler
|
|
|
|
lms = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
|
|
pipe.scheduler = lms
|
|
generator = torch.Generator(device=device).manual_seed(1024)
|
|
image = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5, generator=generator).images[0]
|
|
image
|
|
```
|
|
|
|
<div class="flex justify-center">
|
|
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lms-ghibli.png"/>
|
|
</div>
|
|
|
|
์๋ ๊ณต๋ฐฑ์ ํ์ธํ๊ณ `strength` ๊ฐ์ ๋ค๋ฅด๊ฒ ์ค์ ํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์์ฑํด ๋ณด์ธ์. `strength`๋ฅผ ๋ฎ๊ฒ ์ค์ ํ๋ฉด ์๋ณธ ์ด๋ฏธ์ง์ ๋ ์ ์ฌํ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
|
|
|
|
์์ ๋กญ๊ฒ ์ค์ผ์ค๋ฌ๋ฅผ [`LMSDiscreteScheduler`]๋ก ์ ํํ์ฌ ์ถ๋ ฅ์ ์ด๋ค ์ํฅ์ ๋ฏธ์น๋์ง ํ์ธํด ๋ณด์ธ์.
|
|
|
|
<iframe
|
|
src="https://stevhliu-ghibli-img2img.hf.space"
|
|
frameborder="0"
|
|
width="850"
|
|
height="500"
|
|
></iframe> |