mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-29 07:22:12 +03:00
55 lines
3.2 KiB
Markdown
55 lines
3.2 KiB
Markdown
<!--Copyright 2025 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.
|
|
-->
|
|
|
|
# ์๋ก์ด ์์
์ ๋ํ ๋ชจ๋ธ์ ์ ์ฉํ๊ธฐ
|
|
|
|
๋ง์ diffusion ์์คํ
์ ๊ฐ์ ๊ตฌ์ฑ ์์๋ค์ ๊ณต์ ํ๋ฏ๋ก ํ ์์
์ ๋ํด ์ฌ์ ํ์ต๋ ๋ชจ๋ธ์ ์์ ํ ๋ค๋ฅธ ์์
์ ์ ์ฉํ ์ ์์ต๋๋ค.
|
|
|
|
์ด ์ธํ์ธํ
์ ์ํ ๊ฐ์ด๋๋ ์ฌ์ ํ์ต๋ [`UNet2DConditionModel`]์ ์ํคํ
์ฒ๋ฅผ ์ด๊ธฐํํ๊ณ ์์ ํ์ฌ ์ฌ์ ํ์ต๋ text-to-image ๋ชจ๋ธ์ ์ด๋ป๊ฒ ์ธํ์ธํ
์ ์ ์ฉํ๋์ง๋ฅผ ์๋ ค์ค ๊ฒ์
๋๋ค.
|
|
|
|
## UNet2DConditionModel ํ๋ผ๋ฏธํฐ ๊ตฌ์ฑ
|
|
|
|
[`UNet2DConditionModel`]์ [input sample](https://huggingface.co/docs/diffusers/v0.16.0/en/api/models#diffusers.UNet2DConditionModel.in_channels)์์ 4๊ฐ์ ์ฑ๋์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฉํฉ๋๋ค. ์๋ฅผ ๋ค์ด, [`stable-diffusion-v1-5/stable-diffusion-v1-5`](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5)์ ๊ฐ์ ์ฌ์ ํ์ต๋ text-to-image ๋ชจ๋ธ์ ๋ถ๋ฌ์ค๊ณ `in_channels`์ ์๋ฅผ ํ์ธํฉ๋๋ค:
|
|
|
|
```py
|
|
from diffusers import StableDiffusionPipeline
|
|
|
|
pipeline = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
|
|
pipeline.unet.config["in_channels"]
|
|
4
|
|
```
|
|
|
|
์ธํ์ธํ
์ ์
๋ ฅ ์ํ์ 9๊ฐ์ ์ฑ๋์ด ํ์ํฉ๋๋ค. [`stable-diffusion-v1-5/stable-diffusion-inpainting`](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)์ ๊ฐ์ ์ฌ์ ํ์ต๋ ์ธํ์ธํ
๋ชจ๋ธ์์ ์ด ๊ฐ์ ํ์ธํ ์ ์์ต๋๋ค:
|
|
|
|
```py
|
|
from diffusers import StableDiffusionPipeline
|
|
|
|
pipeline = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-inpainting")
|
|
pipeline.unet.config["in_channels"]
|
|
9
|
|
```
|
|
|
|
์ธํ์ธํ
์ ๋ํ text-to-image ๋ชจ๋ธ์ ์ ์ฉํ๊ธฐ ์ํด, `in_channels` ์๋ฅผ 4์์ 9๋ก ์์ ํด์ผ ํ ๊ฒ์
๋๋ค.
|
|
|
|
์ฌ์ ํ์ต๋ text-to-image ๋ชจ๋ธ์ ๊ฐ์ค์น์ [`UNet2DConditionModel`]์ ์ด๊ธฐํํ๊ณ `in_channels`๋ฅผ 9๋ก ์์ ํด ์ฃผ์ธ์. `in_channels`์ ์๋ฅผ ์์ ํ๋ฉด ํฌ๊ธฐ๊ฐ ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ ํฌ๊ธฐ๊ฐ ์ ๋ง๋ ์ค๋ฅ๋ฅผ ํผํ๊ธฐ ์ํด `ignore_mismatched_sizes=True` ๋ฐ `low_cpu_mem_usage=False`๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค.
|
|
|
|
```py
|
|
from diffusers import UNet2DConditionModel
|
|
|
|
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
unet = UNet2DConditionModel.from_pretrained(
|
|
model_id, subfolder="unet", in_channels=9, low_cpu_mem_usage=False, ignore_mismatched_sizes=True
|
|
)
|
|
```
|
|
|
|
Text-to-image ๋ชจ๋ธ๋ก๋ถํฐ ๋ค๋ฅธ ๊ตฌ์ฑ ์์์ ์ฌ์ ํ์ต๋ ๊ฐ์ค์น๋ ์ฒดํฌํฌ์ธํธ๋ก๋ถํฐ ์ด๊ธฐํ๋์ง๋ง `unet`์ ์
๋ ฅ ์ฑ๋ ๊ฐ์ค์น (`conv_in.weight`)๋ ๋๋คํ๊ฒ ์ด๊ธฐํ๋ฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ชจ๋ธ์ด ๋
ธ์ด์ฆ๋ฅผ ๋ฆฌํดํ๊ธฐ ๋๋ฌธ์ ์ธํ์ธํ
์ ๋ชจ๋ธ์ ํ์ธํ๋ ํ ๋ ์ค์ํฉ๋๋ค.
|