|
<!--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. |
|
--> |
|
|
|
|
|
|
|
๐งจ Diffusers๋ก ๋น ๋ฅด๊ฒ ์์ํ๊ณ ์คํํ์ธ์! |
|
์ด ํ์ด๋ณด๊ธฐ๋ ์ฌ๋ฌ๋ถ์ด ๊ฐ๋ฐ์, ์ผ๋ฐ์ฌ์ฉ์ ์๊ด์์ด ์์ํ๋ ๋ฐ ๋์์ ์ฃผ๋ฉฐ, ์ถ๋ก ์ ์ํด [`DiffusionPipeline`] ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. |
|
|
|
์์ํ๊ธฐ์ ์์์, ํ์ํ ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค์น๋์ด ์๋์ง ํ์ธํ์ธ์: |
|
|
|
```bash |
|
pip install --upgrade diffusers accelerate transformers |
|
``` |
|
|
|
- [`accelerate`](https://huggingface.co/docs/accelerate/index)์ ์ถ๋ก ๋ฐ ํ์ต์ ์ํ ๋ชจ๋ธ ๋ถ๋ฌ์ค๊ธฐ ์๋๋ฅผ ๋์
๋๋ค. |
|
- [`transformers`](https://huggingface.co/docs/transformers/index)๋ [Stable Diffusion](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/overview)๊ณผ ๊ฐ์ด ๊ฐ์ฅ ๋๋ฆฌ ์ฌ์ฉ๋๋ ํ์ฐ ๋ชจ๋ธ์ ์คํํ๊ธฐ ์ํด ํ์ํฉ๋๋ค. |
|
|
|
|
|
|
|
[`DiffusionPipeline`]์ ์ถ๋ก ์ ์ํด ์ฌ์ ํ์ต๋ ํ์ฐ ์์คํ
์ ์ฌ์ฉํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์
๋๋ค. ๋ค์ํ ์์์ ๋ง์ ์์
์ [`DiffusionPipeline`]์ ๋ฐ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ง์๋๋ ์์
์ ์๋์ ํ๋ฅผ ์ฐธ๊ณ ํ์ธ์: |
|
|
|
| **Task** | **Description** | **Pipeline** |
|
|------------------------------|--------------------------------------------------------------------------------------------------------------|-----------------| |
|
| Unconditional Image Generation | ๊ฐ์ฐ์์ ๋
ธ์ด์ฆ์์ ์ด๋ฏธ์ง ์์ฑ | [unconditional_image_generation](./using-diffusers/unconditional_image_generation`) | |
|
| Text-Guided Image Generation | ํ
์คํธ ํ๋กฌํํธ๋ก ์ด๋ฏธ์ง ์์ฑ | [conditional_image_generation](./using-diffusers/conditional_image_generation) | |
|
| Text-Guided Image-to-Image Translation | ํ
์คํธ ํ๋กฌํํธ์ ๋ฐ๋ผ ์ด๋ฏธ์ง ์กฐ์ | [img2img](./using-diffusers/img2img) | |
|
| Text-Guided Image-Inpainting | ๋ง์คํฌ ๋ฐ ํ
์คํธ ํ๋กฌํํธ๊ฐ ์ฃผ์ด์ง ์ด๋ฏธ์ง์ ๋ง์คํน๋ ๋ถ๋ถ์ ์ฑ์ฐ๊ธฐ | [inpaint](./using-diffusers/inpaint) | |
|
| Text-Guided Depth-to-Image Translation | ๊น์ด ์ถ์ ์ ํตํด ๊ตฌ์กฐ๋ฅผ ์ ์งํ๋ฉด์ ํ
์คํธ ํ๋กฌํํธ์ ๋ฐ๋ผ ์ด๋ฏธ์ง์ ์ผ๋ถ๋ฅผ ์กฐ์ | [depth2image](./using-diffusers/depth2image) | |
|
|
|
ํ์ฐ ํ์ดํ๋ผ์ธ์ด ๋ค์ํ ์์
์ ๋ํด ์ด๋ป๊ฒ ์๋ํ๋์ง๋ [**Using Diffusers**](./using-diffusers/overview)๋ฅผ ์ฐธ๊ณ ํ์ธ์. |
|
|
|
์๋ฅผ๋ค์ด, [`DiffusionPipeline`] ์ธ์คํด์ค๋ฅผ ์์ฑํ์ฌ ์์ํ๊ณ , ๋ค์ด๋ก๋ํ๋ ค๋ ํ์ดํ๋ผ์ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ์ง์ ํฉ๋๋ค. |
|
๋ชจ๋ [Diffusers' checkpoint](https://huggingface.co/models?library=diffusers&sort=downloads)์ ๋ํด [`DiffusionPipeline`]์ ์ฌ์ฉํ ์ ์์ต๋๋ค. |
|
ํ์ง๋ง, ์ด ๊ฐ์ด๋์์๋ [Stable Diffusion](https://huggingface.co/CompVis/stable-diffusion)์ ์ฌ์ฉํ์ฌ text-to-image๋ฅผ ํ๋๋ฐ [`DiffusionPipeline`]์ ์ฌ์ฉํฉ๋๋ค. |
|
|
|
[Stable Diffusion](https://huggingface.co/CompVis/stable-diffusion) ๊ธฐ๋ฐ ๋ชจ๋ธ์ ์คํํ๊ธฐ ์ ์ [license](https://huggingface.co/spaces/CompVis/stable-diffusion-license)๋ฅผ ์ฃผ์ ๊น๊ฒ ์ฝ์ผ์ธ์. |
|
์ด๋ ๋ชจ๋ธ์ ํฅ์๋ ์ด๋ฏธ์ง ์์ฑ ๊ธฐ๋ฅ๊ณผ ์ด๊ฒ์ผ๋ก ์์ฑ๋ ์ ์๋ ์ ํดํ ์ฝํ
์ธ ๋๋ฌธ์
๋๋ค. ์ ํํ Stable Diffusion ๋ชจ๋ธ(*์*: [`runwayml/stable-diffusion-v1-5`](https://huggingface.co/runwayml/stable-diffusion-v1-5))๋ก ์ด๋ํ์ฌ ๋ผ์ด์ผ์ค๋ฅผ ์ฝ์ผ์ธ์. |
|
|
|
๋ค์๊ณผ ๊ฐ์ด ๋ชจ๋ธ์ ๋ก๋ํ ์ ์์ต๋๋ค: |
|
|
|
```python |
|
>>> from diffusers import DiffusionPipeline |
|
|
|
>>> pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") |
|
``` |
|
|
|
[`DiffusionPipeline`]์ ๋ชจ๋ ๋ชจ๋ธ๋ง, ํ ํฐํ ๋ฐ ์ค์ผ์ค๋ง ๊ตฌ์ฑ์์๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ์บ์ํฉ๋๋ค. |
|
๋ชจ๋ธ์ ์ฝ 14์ต๊ฐ์ ๋งค๊ฐ๋ณ์๋ก ๊ตฌ์ฑ๋์ด ์์ผ๋ฏ๋ก GPU์์ ์คํํ๋ ๊ฒ์ด ์ข์ต๋๋ค. |
|
PyTorch์์์ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ฑ๊ธฐ ๊ฐ์ฒด๋ฅผ GPU๋ก ์ฎ๊ธธ ์ ์์ต๋๋ค. |
|
|
|
```python |
|
>>> pipeline.to("cuda") |
|
``` |
|
|
|
์ด์ `pipeline`์ ์ฌ์ฉํ ์ ์์ต๋๋ค: |
|
|
|
```python |
|
>>> image = pipeline("An image of a squirrel in Picasso style").images[0] |
|
``` |
|
|
|
์ถ๋ ฅ์ ๊ธฐ๋ณธ์ ์ผ๋ก [PIL Image object](https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class)๋ก ๋ํ๋ฉ๋๋ค. |
|
|
|
๋ค์๊ณผ ๊ฐ์ด ํจ์๋ฅผ ํธ์ถํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ ์ ์์ต๋๋ค: |
|
|
|
```python |
|
>>> image.save("image_of_squirrel_painting.png") |
|
``` |
|
|
|
**์ฐธ๊ณ **: ๋ค์์ ํตํด ๊ฐ์ค์น๋ฅผ ๋ค์ด๋ก๋ํ์ฌ ๋ก์ปฌ์์ ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ ์๋ ์์ต๋๋ค: |
|
|
|
``` |
|
git lfs install |
|
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 |
|
``` |
|
|
|
๊ทธ๋ฆฌ๊ณ ์ ์ฅ๋ ๊ฐ์ค์น๋ฅผ ํ์ดํ๋ผ์ธ์ ๋ถ๋ฌ์ต๋๋ค. |
|
|
|
```python |
|
>>> pipeline = DiffusionPipeline.from_pretrained("./stable-diffusion-v1-5") |
|
``` |
|
|
|
ํ์ดํ๋ผ์ธ ์คํ์ ๋์ผํ ๋ชจ๋ธ ์ํคํ
์ฒ์ด๋ฏ๋ก ์์ ์ฝ๋์ ๋์ผํฉ๋๋ค. |
|
|
|
```python |
|
>>> generator.to("cuda") |
|
>>> image = generator("An image of a squirrel in Picasso style").images[0] |
|
>>> image.save("image_of_squirrel_painting.png") |
|
``` |
|
|
|
ํ์ฐ ์์คํ
์ ๊ฐ๊ฐ ์ฅ์ ์ด ์๋ ์ฌ๋ฌ ๋ค๋ฅธ [schedulers](./api/schedulers/overview)์ ํจ๊ป ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Stable Diffusion์ `PNDMScheduler`๋ก ์คํ๋์ง๋ง ๋ค๋ฅธ ์ค์ผ์ค๋ฌ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํฉ๋๋ค. *์* [`EulerDiscreteScheduler`] ์ค์ผ์ค๋ฌ๋ฅผ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์์ต๋๋ค: |
|
|
|
```python |
|
>>> from diffusers import EulerDiscreteScheduler |
|
|
|
>>> pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") |
|
|
|
>>> # change scheduler to Euler |
|
>>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config) |
|
``` |
|
|
|
์ค์ผ์ค๋ฌ ๋ณ๊ฒฝ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ [Using Schedulers](./using-diffusers/schedulers) ๊ฐ์ด๋๋ฅผ ์ฐธ๊ณ ํ์ธ์. |
|
|
|
[Stability AI's](https://stability.ai/)์ Stable Diffusion ๋ชจ๋ธ์ ์ธ์์ ์ธ ์ด๋ฏธ์ง ์์ฑ ๋ชจ๋ธ์ด๋ฉฐ ํ
์คํธ์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ๋ ๋ง์ ์์
์ ์ํํ ์ ์์ต๋๋ค. ์ฐ๋ฆฌ๋ Stable Diffusion๋ง์ ์ํ ์ ์ฒด ๋ฌธ์ ํ์ด์ง๋ฅผ ์ ๊ณตํฉ๋๋ค [link](./conceptual/stable_diffusion). |
|
|
|
๋ง์ฝ ๋ ์ ์ ๋ฉ๋ชจ๋ฆฌ, ๋ ๋์ ์ถ๋ก ์๋, Mac๊ณผ ๊ฐ์ ํน์ ํ๋์จ์ด ๋๋ ONNX ๋ฐํ์์์ ์คํ๋๋๋ก Stable Diffusion์ ์ต์ ํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์ถ๋ค๋ฉด ์ต์ ํ ํ์ด์ง๋ฅผ ์ดํด๋ณด์ธ์: |
|
|
|
- [Optimized PyTorch on GPU](./optimization/fp16) |
|
- [Mac OS with PyTorch](./optimization/mps) |
|
- [ONNX](./optimization/onnx) |
|
- [OpenVINO](./optimization/open_vino) |
|
|
|
ํ์ฐ ๋ชจ๋ธ์ ๋ฏธ์ธ์กฐ์ ํ๊ฑฐ๋ ํ์ต์ํค๋ ค๋ฉด, [**training section**](./training/overview)์ ์ดํด๋ณด์ธ์. |
|
|
|
๋ง์ง๋ง์ผ๋ก, ์์ฑ๋ ์ด๋ฏธ์ง๋ฅผ ๊ณต๊ฐ์ ์ผ๋ก ๋ฐฐํฌํ ๋ ์ ์ค์ ๊ธฐํด ์ฃผ์ธ์ ๐ค. |