BleachNick's picture
upload required packages
87d40d2

A newer version of the Gradio SDK is available: 5.9.1

Upgrade

μƒˆλ‘œμš΄ μž‘μ—…μ— λŒ€ν•œ λͺ¨λΈμ„ μ μš©ν•˜κΈ°

λ§Žμ€ diffusion μ‹œμŠ€ν…œμ€ 같은 ꡬ성 μš”μ†Œλ“€μ„ κ³΅μœ ν•˜λ―€λ‘œ ν•œ μž‘μ—…μ— λŒ€ν•΄ μ‚¬μ „ν•™μŠ΅λœ λͺ¨λΈμ„ μ™„μ „νžˆ λ‹€λ₯Έ μž‘μ—…μ— μ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 μΈνŽ˜μΈνŒ…μ„ μœ„ν•œ κ°€μ΄λ“œλŠ” μ‚¬μ „ν•™μŠ΅λœ [UNet2DConditionModel]의 μ•„ν‚€ν…μ²˜λ₯Ό μ΄ˆκΈ°ν™”ν•˜κ³  μˆ˜μ •ν•˜μ—¬ μ‚¬μ „ν•™μŠ΅λœ text-to-image λͺ¨λΈμ„ μ–΄λ–»κ²Œ μΈνŽ˜μΈνŒ…μ— μ μš©ν•˜λŠ”μ§€λ₯Ό μ•Œλ €μ€„ κ²ƒμž…λ‹ˆλ‹€.

UNet2DConditionModel νŒŒλΌλ―Έν„° ꡬ성

[UNet2DConditionModel]은 input sampleμ—μ„œ 4개의 채널을 기본적으둜 ν—ˆμš©ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, runwayml/stable-diffusion-v1-5와 같은 μ‚¬μ „ν•™μŠ΅λœ text-to-image λͺ¨λΈμ„ 뢈러였고 in_channels의 수λ₯Ό ν™•μΈν•©λ‹ˆλ‹€:

from diffusers import StableDiffusionPipeline

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

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

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λ₯Ό μ„€μ •ν•΄μ•Ό ν•©λ‹ˆλ‹€.

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