File size: 3,220 Bytes
87d40d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!--Copyright 2024 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개의 채널을 기본적으둜 ν—ˆμš©ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄,  [`runwayml/stable-diffusion-v1-5`](https://huggingface.co/runwayml/stable-diffusion-v1-5)와 같은 μ‚¬μ „ν•™μŠ΅λœ text-to-image λͺ¨λΈμ„ 뢈러였고 `in_channels`의 수λ₯Ό ν™•μΈν•©λ‹ˆλ‹€:

```py
from diffusers import StableDiffusionPipeline

pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipeline.unet.config["in_channels"]
4
```

μΈνŽ˜μΈνŒ…μ€ μž…λ ₯ μƒ˜ν”Œμ— 9개의 채널이 ν•„μš”ν•©λ‹ˆλ‹€. [`runwayml/stable-diffusion-inpainting`](https://huggingface.co/runwayml/stable-diffusion-inpainting)와 같은 μ‚¬μ „ν•™μŠ΅λœ μΈνŽ˜μΈνŒ… λͺ¨λΈμ—μ„œ 이 값을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€:

```py
from diffusers import StableDiffusionPipeline

pipeline = StableDiffusionPipeline.from_pretrained("runwayml/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 = "runwayml/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`)λŠ” λžœλ€ν•˜κ²Œ μ΄ˆκΈ°ν™”λ©λ‹ˆλ‹€. 그렇지 μ•ŠμœΌλ©΄ λͺ¨λΈμ΄ λ…Έμ΄μ¦ˆλ₯Ό λ¦¬ν„΄ν•˜κΈ° λ•Œλ¬Έμ— μΈνŽ˜μΈνŒ…μ˜ λͺ¨λΈμ„ νŒŒμΈνŠœλ‹ ν•  λ•Œ μ€‘μš”ν•©λ‹ˆλ‹€.