Buckets:
| # ์ด๋ฏธ์ง-์ด๋ฏธ์ง | |
| Stable Diffusion ๋ชจ๋ธ์ ํ ์คํธ ํ๋กฌํํธ์ ์ด๊ธฐ ์ด๋ฏธ์ง๋ฅผ ์ ๋ฌํ์ฌ ์๋ก์ด ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํจ์ผ๋ก์จ ์ด๋ฏธ์ง-์ด๋ฏธ์ง ์์ฑ์๋ ์ ์ฉํ ์ ์์ต๋๋ค. | |
| [StableDiffusionImg2ImgPipeline](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline)๋ Chenlin Meng, Yutong He, Yang Song, Jiaming Song, Jiajun Wu, Jun-Yan Zhu, Stefano Ermon์ด ์ ์ํ [SDEdit: Guided Image Synthesis and Editing with Stochastic Differential Equations](https://huggingface.co/papers/2108.01073)์ diffusion-denoising ๋ฉ์ปค๋์ฆ์ ์ฌ์ฉํฉ๋๋ค. | |
| ํด๋น ๋ ผ๋ฌธ์ ์ด๋ก์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| *์ง๋ ๊ธฐ๋ฐ ์ด๋ฏธ์ง ํฉ์ฑ์ ์ผ๋ฐ ์ฌ์ฉ์๊ฐ ์ต์ํ์ ๋ ธ๋ ฅ์ผ๋ก ์ฌ์ง๊ณผ ๊ฐ์ ์ฌ์ค์ ์ธ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ํธ์งํ ์ ์๊ฒ ํฉ๋๋ค. ํต์ฌ ๊ณผ์ ๋ ์ฌ์ฉ์ ์ ๋ ฅ(์: ์์ผ๋ก ๊ทธ๋ฆฐ ์์น ๋ ์คํธ๋กํฌ)์ ๋ํ ์ถฉ์ค์ฑ๊ณผ ํฉ์ฑ๋ ์ด๋ฏธ์ง์ ์ฌ์ค์ฑ ์ฌ์ด์ ๊ท ํ์ ๋ง์ถ๋ ๊ฒ์ ๋๋ค. ๊ธฐ์กด GAN ๊ธฐ๋ฐ ๋ฐฉ๋ฒ์ ์กฐ๊ฑด๋ถ GAN ๋๋ GAN ์ญ์ ํ์ ์ฌ์ฉํ์ฌ ์ด๋ฌํ ๊ท ํ์ ๋ฌ์ฑํ๋ ค ํ์ง๋ง, ์ด๋ ์ด๋ ค์ธ ๋ฟ๋ง ์๋๋ผ ๊ฐ๋ณ ์์ฉ ๋ถ์ผ์ ๋ฐ๋ผ ์ถ๊ฐ์ ์ธ ํ์ต ๋ฐ์ดํฐ๋ ์์ค ํจ์๊ฐ ํ์ํ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค. ์ด๋ฌํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด, ์ฐ๋ฆฌ๋ ํ๋ฅ ๋ฏธ๋ถ ๋ฐฉ์ ์(SDE)์ ํตํด ๋ฐ๋ณต์ ์ผ๋ก ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ์ฌ ์ฌ์ค์ ์ธ ์ด๋ฏธ์ง๋ฅผ ํฉ์ฑํ๋ ํ์ฐ ๋ชจ๋ธ ์์ฑ ์ฌ์ ์ง์์ ๊ธฐ๋ฐ์ผ๋ก ํ ์๋ก์ด ์ด๋ฏธ์ง ํฉ์ฑ ๋ฐ ํธ์ง ๋ฐฉ๋ฒ์ธ Stochastic Differential Editing(SDEdit)์ ์๊ฐํฉ๋๋ค. ์ด๋ค ์ ํ์ ์ฌ์ฉ์ ๊ฐ์ด๋๋ฅผ ๊ฐ์ง ์ ๋ ฅ ์ด๋ฏธ์ง๊ฐ ์ฃผ์ด์ง๋ฉด, SDEdit์ ๋จผ์ ์ ๋ ฅ์ ๋ ธ์ด์ฆ๋ฅผ ์ถ๊ฐํ ๋ค์, SDE ์ฌ์ ์ง์์ ํตํด ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ์ญ๋ ธ์ด์ฆํํ์ฌ ์ฌ์ค์ฑ์ ๋์ ๋๋ค. SDEdit์ ์์ ๋ณ ํ์ต์ด๋ ์ญ์ ํ์ ์๊ตฌํ์ง ์์ผ๋ฉฐ, ์ฌ์ค์ฑ๊ณผ ์ถฉ์ค์ฑ ์ฌ์ด์ ๊ท ํ์ ์์ฐ์ค๋ฝ๊ฒ ๋ฌ์ฑํ ์ ์์ต๋๋ค. SDEdit์ ์คํธ๋กํฌ ๊ธฐ๋ฐ ์ด๋ฏธ์ง ํฉ์ฑ ๋ฐ ํธ์ง, ์ด๋ฏธ์ง ํฉ์ฑ์ ํฌํจํ ์ฌ๋ฌ ์์ ์์ ์ธ๊ฐ ์ง๊ฐ ์ฐ๊ตฌ์ ๋ฐ๋ผ ์ฌ์ค์ฑ์์ ์ต๋ 98.09%, ์ ๋ฐ์ ์ธ ๋ง์กฑ๋์์ 91.72%๊น์ง ์ต์ฒจ๋จ GAN ๊ธฐ๋ฐ ๋ฐฉ๋ฒ๋ณด๋ค ํ์ ํ ์ฐ์ํ ์ฑ๋ฅ์ ๋ณด์ ๋๋ค.* | |
| > [!TIP] | |
| > ์ค์ผ์ค๋ฌ์ ์๋์ ํ์ง ์ฌ์ด์ ํธ๋ ์ด๋์คํ๋ฅผ ํ์ํ๋ ๋ฐฉ๋ฒ๊ณผ ํ์ดํ๋ผ์ธ ๊ตฌ์ฑ ์์๋ฅผ ํจ์จ์ ์ผ๋ก ์ฌ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ๋ ค๋ฉด Stable Diffusion [Tips](overview#tips) ์น์ ์ ๊ผญ ํ์ธํ์ธ์! | |
| ## StableDiffusionImg2ImgPipeline[[diffusers.StableDiffusionImg2ImgPipeline]] | |
| #### diffusers.StableDiffusionImg2ImgPipeline[[diffusers.StableDiffusionImg2ImgPipeline]] | |
| ```python | |
| diffusers.StableDiffusionImg2ImgPipeline(vae: AutoencoderKL, text_encoder: CLIPTextModel, tokenizer: CLIPTokenizer, unet: UNet2DConditionModel, scheduler: KarrasDiffusionSchedulers, safety_checker: StableDiffusionSafetyChecker, feature_extractor: CLIPImageProcessorPil, image_encoder: CLIPVisionModelWithProjection = None, requires_safety_checker: bool = True) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L182) | |
| **๋งค๊ฐ๋ณ์:** | |
| vae ([AutoencoderKL](/docs/diffusers/main/ko/api/models/autoencoderkl#diffusers.AutoencoderKL)) : ์ด๋ฏธ์ง๋ฅผ ์ ์ฌ ํํ์ผ๋ก ์ธ์ฝ๋ฉํ๊ณ ์ ์ฌ ํํ์์ ์ด๋ฏธ์ง๋ก ๋์ฝ๋ฉํ๋ Variational Auto-Encoder (VAE) ๋ชจ๋ธ์ ๋๋ค. | |
| text_encoder ([CLIPTextModel](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel)) : ๊ณ ์ ๋ ํ ์คํธ ์ธ์ฝ๋ ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)). | |
| tokenizer ([CLIPTokenizer](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer)) : ํ ์คํธ๋ฅผ ํ ํฐํํ๊ธฐ ์ํ `CLIPTokenizer`์ ๋๋ค. | |
| unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : ์ธ์ฝ๋ฉ๋ ์ด๋ฏธ์ง latents์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ `UNet2DConditionModel`. | |
| scheduler ([SchedulerMixin](/docs/diffusers/main/ko/api/schedulers/overview#diffusers.SchedulerMixin)) : `unet`์ ํจ๊ป ์ฌ์ฉ๋์ด ์ธ์ฝ๋ฉ๋ ์ด๋ฏธ์ง latents์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๋ ์ค์ผ์ค๋ฌ์ ๋๋ค. [DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler), [LMSDiscreteScheduler](/docs/diffusers/main/ko/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler), ๋๋ [PNDMScheduler](/docs/diffusers/main/ko/api/schedulers/pndm#diffusers.PNDMScheduler) ์ค ํ๋์ผ ์ ์์ต๋๋ค. | |
| safety_checker (`StableDiffusionSafetyChecker`) : ์์ฑ๋ ์ด๋ฏธ์ง๊ฐ offensiveํ๊ฑฐ๋ ์ ํดํ ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋ ์ ์๋์ง ์ถ์ ํ๋ ๋ถ๋ฅ ๋ชจ๋์ ๋๋ค. ๋ชจ๋ธ์ ์ ์ฌ์ ์ ํด์ฑ์ ๋ํ ์์ธํ ๋ด์ฉ์ [model card](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5)๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| feature_extractor ([CLIPImageProcessor](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor)) : ์์ฑ๋ ์ด๋ฏธ์ง์์ ํน์ง์ ์ถ์ถํ๊ธฐ ์ํ `CLIPImageProcessor`. `safety_checker`์ ์ ๋ ฅ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. | |
| Stable Diffusion์ ์ฌ์ฉํ ํ ์คํธ ๊ธฐ๋ฐ ์ด๋ฏธ์ง-์ด๋ฏธ์ง ์์ฑ์ ์ํ Pipeline | |
| ์ด ๋ชจ๋ธ์ [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)์์ ์์๋ฉ๋๋ค. ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋, ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์. | |
| ํ์ดํ๋ผ์ธ์ ๋ค์ ๋ก๋ฉ ๋ฉ์๋๋ ์์ํฉ๋๋ค: | |
| - ํ ์คํธ ์ธ๋ฒ์ ์๋ฒ ๋ฉ์ ๋ก๋ํ๋ [load_textual_inversion()](/docs/diffusers/main/ko/api/loaders/textual_inversion#diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion) | |
| - LoRA ๊ฐ์ค์น๋ฅผ ๋ก๋ํ๋ [load_lora_weights()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_weights) | |
| - LoRA ๊ฐ์ค์น๋ฅผ ์ ์ฅํ๋ [save_lora_weights()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.save_lora_weights) | |
| - `.ckpt` ํ์ผ์ ๋ก๋ํ๊ธฐ ์ํ [from_single_file()](/docs/diffusers/main/ko/api/loaders/single_file#diffusers.loaders.FromSingleFileMixin.from_single_file) | |
| - IP Adapter๋ฅผ ๋ก๋ํ๊ธฐ ์ํ [load_ip_adapter()](/docs/diffusers/main/ko/api/loaders/ip_adapter#diffusers.loaders.IPAdapterMixin.load_ip_adapter) | |
| #### __ํธ์ถ__[[diffusers.StableDiffusionImg2ImgPipeline.__call__]] | |
| ```python | |
| __call__(prompt: str | list[str] = None, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, strength: float = 0.8, num_inference_steps: int | None = 50, timesteps: list[int] = None, sigmas: list[float] = None, guidance_scale: float | None = 7.5, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int | None = 1, eta: float | None = 0.0, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, ip_adapter_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, ip_adapter_image_embeds: list[torch.Tensor] | None = None, output_type: str | None = 'pil', return_dict: bool = True, cross_attention_kwargs: dict[str, typing.Any] | None = None, clip_skip: int = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L858) | |
| **๋งค๊ฐ๋ณ์:** | |
| prompt (`str` ๋๋ `list[str]`, *์ ํ ์ฌํญ*) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ ํ๋กฌํํธ์ ๋๋ค. ์ ์๋์ง ์์ ๊ฒฝ์ฐ `prompt_embeds`๋ฅผ ์ ๋ฌํด์ผ ํฉ๋๋ค. | |
| image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `list[torch.Tensor]`, `list[PIL.Image.Image]`, ๋๋ `list[np.ndarray]`) : ์์์ ์ผ๋ก ์ฌ์ฉํ ์ด๋ฏธ์ง ๋ฐฐ์น์ `Image`, numpy ๋ฐฐ์ด ๋๋ ํ ์๋ฅผ ๋ํ๋ ๋๋ค. numpy ๋ฐฐ์ด๊ณผ pytorch ํ ์ ๋ชจ๋์์ ์์ ๊ฐ ๋ฒ์๋ `[0, 1]`์ ๋๋ค. ํ ์ ๋๋ ํ ์ ๋ชฉ๋ก์ธ ๊ฒฝ์ฐ, ์์ shape์ `(B, C, H, W)` ๋๋ `(C, H, W)`์ฌ์ผ ํฉ๋๋ค. numpy ๋ฐฐ์ด ๋๋ ๋ฐฐ์ด ๋ชฉ๋ก์ธ ๊ฒฝ์ฐ, ์์ shape์ `(B, H, W, C)` ๋๋ `(H, W, C)`์ฌ์ผ ํฉ๋๋ค. `image`๋ก ์ด๋ฏธ์ง latents๋ ๋ฐ์ ์ ์์ง๋ง, latents๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉ๋์ง ์์ต๋๋ค. | |
| strength (`float`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 0.8) : ์ฐธ์กฐ `image`๋ฅผ ๋ณํํ ์ ๋๋ฅผ ๋ํ๋ ๋๋ค. 0๊ณผ 1 ์ฌ์ด์ฌ์ผ ํฉ๋๋ค. `image`๋ ์์์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, `strength` ๊ฐ์ด ๋์์๋ก ๋ ๋ง์ ๋ ธ์ด์ฆ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๋๋ ธ์ด์ง ๋จ๊ณ์ ์๋ ์ด๊ธฐ์ ์ถ๊ฐ๋ ๋ ธ์ด์ฆ์ ์์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. `strength`๊ฐ 1์ด๋ฉด ์ถ๊ฐ๋๋ ๋ ธ์ด์ฆ๊ฐ ์ต๋๊ฐ ๋๋ฉฐ, `num_inference_steps`์ ์ง์ ๋ ์ ์ฒด ๋ฐ๋ณต ํ์๋งํผ ๋๋ ธ์ด์ง ํ๋ก์ธ์ค๊ฐ ์คํ๋ฉ๋๋ค. 1์ด๋ผ๋ ๊ฐ์ ์ฌ์ค์ `image`๋ฅผ ๋ฌด์ํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค. | |
| num_inference_steps (`int`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 50) : ๋๋ ธ์ด์ง ๋จ๊ณ ์์ ๋๋ค. ๋๋ ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค. ์ด ๋งค๊ฐ๋ณ์๋ `strength`์ ์ํด ์กฐ์ ๋ฉ๋๋ค. | |
| timesteps (`list[int]`, *์ ํ ์ฌํญ*) : `set_timesteps` ๋ฉ์๋์ `timesteps` ์ธ์๋ฅผ ์ง์ํ๋ ์ค์ผ์ค๋ฌ์ ๋ ธ์ด์ฆ ์ ๊ฑฐ ๊ณผ์ ์ ์ฌ์ฉํ ์ปค์คํ ํ์์คํ ์ ๋๋ค. ์ ์๋์ง ์์ ๊ฒฝ์ฐ, `num_inference_steps`๊ฐ ์ ๋ฌ๋ ๋์ ๊ธฐ๋ณธ ๋์์ด ์ฌ์ฉ๋ฉ๋๋ค. ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌ๋์ด ์์ด์ผ ํฉ๋๋ค. | |
| sigmas (`list[float]`, *์ ํ ์ฌํญ*) : `set_timesteps` ๋ฉ์๋์ `sigmas` ์ธ์๋ฅผ ์ง์ํ๋ ์ค์ผ์ค๋ฌ์ ๋ ธ์ด์ฆ ์ ๊ฑฐ ๊ณผ์ ์ ์ฌ์ฉํ ์ปค์คํ ์๊ทธ๋ง์ ๋๋ค. ์ ์๋์ง ์์ ๊ฒฝ์ฐ, `num_inference_steps`๊ฐ ์ ๋ฌ๋ ๋์ ๊ธฐ๋ณธ ๋์์ด ์ฌ์ฉ๋ฉ๋๋ค. | |
| guidance_scale (`float`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 7.5) : guidance scale ๊ฐ์ด ๋์์๋ก ๋ชจ๋ธ์ ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋์ ํ ์คํธ `prompt`์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ ๋๋ฉ๋๋ค. `guidance_scale > 1`์ผ ๋ guidance scale์ด ํ์ฑํ๋ฉ๋๋ค. | |
| negative_prompt (`str` ๋๋ `list[str]`, *์ ํ*) : ์ด๋ฏธ์ง ์์ฑ์์ ํฌํจํ์ง ์์ ๋ด์ฉ์ ์๋ดํ๋ ํ๋กฌํํธ์ ๋๋ค. ์ ์๋์ง ์์ ๊ฒฝ์ฐ ๋์ `negative_prompt_embeds`๋ฅผ ์ ๋ฌํด์ผ ํฉ๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์์ ๋(`guidance_scale < 1`)์๋ ๋ฌด์๋ฉ๋๋ค. | |
| num_images_per_prompt (`int`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์. | |
| eta (`float`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 0.0) : [DDIM](https://huggingface.co/papers/2010.02502) ๋ ผ๋ฌธ์์ ์ ์ํ ํ๋ผ๋ฏธํฐ eta (ฮท)์ ํด๋นํฉ๋๋ค. [DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler)์๋ง ์ ์ฉ๋๋ฉฐ, ๋ค๋ฅธ ์ค์ผ์ค๋ฌ์์๋ ๋ฌด์๋ฉ๋๋ค. | |
| generator (`torch.Generator` ๋๋ `list[torch.Generator]`, *์ ํ ์ฌํญ*) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)์ ๋๋ค. | |
| prompt_embeds (`torch.Tensor`, *์ ํ ์ฌํญ*) : ๋ฏธ๋ฆฌ ์์ฑ๋ ํ ์คํธ ์๋ฒ ๋ฉ์ ๋๋ค. ํ ์คํธ ์ ๋ ฅ(ํ๋กฌํํธ ๊ฐ์ค์น)์ ์ฝ๊ฒ ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด `prompt` ์ ๋ ฅ ์ธ์์์ ํ ์คํธ ์๋ฒ ๋ฉ์ด ์์ฑ๋ฉ๋๋ค. | |
| negative_prompt_embeds (`torch.Tensor`, *์ ํ ์ฌํญ*) : ๋ฏธ๋ฆฌ ์์ฑ๋ ๋ถ์ ํ ์คํธ ์๋ฒ ๋ฉ์ ๋๋ค. ํ ์คํธ ์ ๋ ฅ(ํ๋กฌํํธ ๊ฐ์ค์น)์ ์ฝ๊ฒ ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด `negative_prompt` ์ ๋ ฅ ์ธ์์์ `negative_prompt_embeds`๊ฐ ์์ฑ๋ฉ๋๋ค. | |
| ip_adapter_image : (`PipelineImageInput`, *์ ํ ์ฌํญ*): IP Adapters์ ํจ๊ป ์ฌ์ฉํ ์ ํ์ ์ด๋ฏธ์ง ์ ๋ ฅ์ ๋๋ค. | |
| ip_adapter_image_embeds (`list[torch.Tensor]`, *์ ํ*) : IP-Adapter๋ฅผ ์ํ ์ฌ์ ์์ฑ๋ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋๋ค. IP-Adapter์ ์์ ๋์ผํ ๊ธธ์ด์ ๋ฆฌ์คํธ์ฌ์ผ ํฉ๋๋ค. ๊ฐ ์์๋ `(batch_size, num_images, emb_dim)` ํํ์ ํ ์์ฌ์ผ ํฉ๋๋ค. `do_classifier_free_guidance`๊ฐ `True`๋ก ์ค์ ๋ ๊ฒฝ์ฐ, ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ํฌํจํด์ผ ํฉ๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด `ip_adapter_image` ์ ๋ ฅ ์ธ์๋ก๋ถํฐ ์๋ฒ ๋ฉ์ด ๊ณ์ฐ๋ฉ๋๋ค. | |
| output_type (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `"pil"`) : ์์ฑ๋ ์ด๋ฏธ์ง์ ์ถ๋ ฅ ํ์์ ๋๋ค. `PIL.Image` ๋๋ `np.array` ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค. | |
| return_dict (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : ์ผ๋ฐ ํํ ๋์ [StableDiffusionPipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput)์ ๋ฐํํ ์ง ์ฌ๋ถ. | |
| cross_attention_kwargs (`dict`, *์ ํ ์ฌํญ*) : ์ง์ ๋ ๊ฒฝ์ฐ [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py)์์ ์ ์๋ `AttentionProcessor`๋ก ์ ๋ฌ๋๋ kwargs ์ฌ์ ์ ๋๋ค. | |
| clip_skip (`int`, *์ ํ ์ฌํญ*) : ํ๋กฌํํธ ์๋ฒ ๋ฉ์ ๊ณ์ฐํ ๋ CLIP์์ ๊ฑด๋๋ธ ๋ ์ด์ด ์. ๊ฐ์ด 1์ด๋ฉด ์ต์ข ๋ ์ด์ด ๋ฐ๋ก ์ด์ ๋ ์ด์ด์ ์ถ๋ ฅ์ ํ๋กฌํํธ ์๋ฒ ๋ฉ ๊ณ์ฐ์ ์ฌ์ฉํฉ๋๋ค. | |
| callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : ์ถ๋ก ์ค ๊ฐ denoising ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์ ๋๋ `PipelineCallback` ๋๋ `MultiPipelineCallbacks`์ ํ์ ํด๋์ค์ ๋๋ค. ๋ค์ ์ธ์๋ฅผ ๊ฐ์ง๋๋ค: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs`์๋ `callback_on_step_end_tensor_inputs`๋ก ์ง์ ๋ ๋ชจ๋ ํ ์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค. | |
| callback_on_step_end_tensor_inputs (`list`, *์ ํ ์ฌํญ*) : `callback_on_step_end` ํจ์์ ํ ์ ์ ๋ ฅ ๋ชฉ๋ก์ ๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ ์๋ `callback_kwargs` ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ `._callback_tensor_inputs` ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค. | |
| **๋ฐํ๊ฐ:** [StableDiffusionPipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput) ๋๋ `tuple` | |
| If `return_dict` is `True`, [StableDiffusionPipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput) is returned, otherwise a `tuple` is returned where the first element is a list with the generated images and the second element is a list of `bool`s indicating whether the corresponding generated image contains "not-safe-for-work" (nsfw) content. | |
| ์์ฑ์ ์ํ pipeline์ ํธ์ถ ํจ์. | |
| ์: | |
| ```py | |
| >>> import requests | |
| >>> import torch | |
| >>> from PIL import Image | |
| >>> from io import BytesIO | |
| >>> from diffusers import StableDiffusionImg2ImgPipeline | |
| >>> device = "cuda" | |
| >>> model_id_or_path = "stable-diffusion-v1-5/stable-diffusion-v1-5" | |
| >>> pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) | |
| >>> pipe = pipe.to(device) | |
| >>> 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 = init_image.resize((768, 512)) | |
| >>> prompt = "A fantasy landscape, trending on artstation" | |
| >>> images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images | |
| >>> images[0].save("fantasy_landscape.png") | |
| ``` | |
| #### enable_attention_slicing[[diffusers.StableDiffusionImg2ImgPipeline.enable_attention_slicing]] | |
| ```python | |
| enable_attention_slicing(slice_size: str | int = 'auto') | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L2030) | |
| **๋งค๊ฐ๋ณ์:** | |
| slice_size (`str` ๋๋ `int`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `"auto"`) : `"auto"`์ธ ๊ฒฝ์ฐ attention heads์ ์ ๋ฌ๋๋ ์ ๋ ฅ์ ์ ๋ฐ์ผ๋ก ์ค์ฌ attention์ ๋ ๋จ๊ณ๋ก ๊ณ์ฐํฉ๋๋ค. `"max"`์ธ ๊ฒฝ์ฐ ํ ๋ฒ์ ํ๋์ ์ฌ๋ผ์ด์ค๋ง ์คํํ์ฌ ์ต๋์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ์ฝํฉ๋๋ค. ์ซ์๊ฐ ์ ๊ณต๋๋ฉด `attention_head_dim // slice_size`๋งํผ์ ์ฌ๋ผ์ด์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ด ๊ฒฝ์ฐ `attention_head_dim`์ `slice_size`์ ๋ฐฐ์์ฌ์ผ ํฉ๋๋ค. | |
| ์ฌ๋ผ์ด์ค๋ ์ดํ ์ ๊ณ์ฐ์ ํ์ฑํํฉ๋๋ค. ์ด ์ต์ ์ด ํ์ฑํ๋๋ฉด ์ดํ ์ ๋ชจ๋์ ์ ๋ ฅ ํ ์๋ฅผ ์ฌ๋ผ์ด์ค๋ก ๋ถํ ํ์ฌ ์ฌ๋ฌ ๋จ๊ณ์ ๊ฑธ์ณ ์ดํ ์ ์ ๊ณ์ฐํฉ๋๋ค. ์ดํ ์ ํค๋ ํ๋๊ฐ ๋๋ ๊ฒฝ์ฐ, ๊ฐ ํค๋๋ฅผ ์์ฐจ์ ์ผ๋ก ๊ณ์ฐํฉ๋๋ค. ์ด๋ ์๋๊ฐ ์ฝ๊ฐ ๊ฐ์ํ๋ ๋์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ์ฝํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค. | |
| > [!WARNING] > โ ๏ธ ์ด๋ฏธ `scaled_dot_product_attention`(SDPA)๋ฅผ ์ฌ์ฉ ์ค์ด๋ผ๋ฉด attention slicing์ ํ์ฑํํ์ง ๋ง์ธ์ | |
| from PyTorch > 2.0 or xFormers. ์ด๋ฌํ attention ๊ณ์ฐ์ ์ด๋ฏธ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ฑ์ด ๋งค์ฐ ๋์ ์ด ๊ธฐ๋ฅ์ ํ์ฑํํ ํ์๊ฐ ์์ต๋๋ค. SDPA ๋๋ xFormers์ ํจ๊ป attention slicing์ ํ์ฑํํ๋ฉด ์ฌ๊ฐํ ์ฑ๋ฅ ์ ํ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค! | |
| ์: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import StableDiffusionPipeline | |
| >>> pipe = StableDiffusionPipeline.from_pretrained( | |
| ... "stable-diffusion-v1-5/stable-diffusion-v1-5", | |
| ... dtype=torch.float16, | |
| ... use_safetensors=True, | |
| ... ) | |
| >>> prompt = "a photo of an astronaut riding a horse on mars" | |
| >>> pipe.enable_attention_slicing() | |
| >>> image = pipe(prompt).images[0] | |
| ``` | |
| #### disable_attention_slicing[[diffusers.StableDiffusionImg2ImgPipeline.disable_attention_slicing]] | |
| ```python | |
| disable_attention_slicing() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L2067) | |
| ์ฌ๋ผ์ด์ค๋ ์ดํ ์ ๊ณ์ฐ ๊ธฐ๋ฅ์ ๋นํ์ฑํํฉ๋๋ค. `enable_attention_slicing`๊ฐ ์ด์ ์ ํธ์ถ๋ ๊ฒฝ์ฐ, ์ดํ ์ ์ ํ ๋ฒ์ ๊ณ์ฐ๋ฉ๋๋ค. | |
| #### enable_xformers_memory_efficient_attention[[diffusers.StableDiffusionImg2ImgPipeline.enable_xformers_memory_efficient_attention]] | |
| ```python | |
| enable_xformers_memory_efficient_attention(attention_op: typing.Optional[typing.Callable] = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L1975) | |
| **๋งค๊ฐ๋ณ์:** | |
| attention_op (`Callable`, *์ ํ ์ฌํญ*) : xFormers์ [`memory_efficient_attention()`](https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention) ํจ์์ `op` ์ธ์๋ก ์ฌ์ฉ๋ ๋ ๊ธฐ๋ณธ `None` ์ฐ์ฐ์๋ฅผ ์ฌ์ ์ํฉ๋๋ค. | |
| [xFormers](https://facebookresearch.github.io/xformers/)์์ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ธ ์ดํ ์ ์ ํ์ฑํํฉ๋๋ค. ์ด ์ต์ ์ ํ์ฑํํ๋ฉด ์ถ๋ก ์ GPU ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ๊ฐ์ํ๊ณ ์๋๊ฐ ํฅ์๋ ์ ์์ต๋๋ค. ํ์ต ์ ์๋ ํฅ์์ ๋ณด์ฅ๋์ง ์์ต๋๋ค. | |
| > [!WARNING] > โ ๏ธ memory efficient attention๊ณผ sliced attention์ด ๋ชจ๋ ํ์ฑํ๋ ๊ฒฝ์ฐ, memory efficient | |
| attention์ > ์ฐ์ ์์๋ฅผ ๊ฐ์ง๋๋ค. | |
| ์: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import DiffusionPipeline | |
| >>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp | |
| >>> pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", dtype=torch.float16) | |
| >>> pipe = pipe.to("cuda") | |
| >>> pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp) | |
| >>> # Workaround for not accepting attention shape using VAE for Flash Attention | |
| >>> pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None) | |
| ``` | |
| #### disable_xformers_memory_efficient_attention[[diffusers.StableDiffusionImg2ImgPipeline.disable_xformers_memory_efficient_attention]] | |
| ```python | |
| disable_xformers_memory_efficient_attention() | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L2006) | |
| [xFormers](https://facebookresearch.github.io/xformers/)์์ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ดํ ์ ์ ๋นํ์ฑํํฉ๋๋ค. | |
| #### load_textual_inversion[[diffusers.StableDiffusionImg2ImgPipeline.load_textual_inversion]] | |
| ```python | |
| load_textual_inversion(pretrained_model_name_or_path: str | list[str] | dict[str, torch.Tensor] | list[dict[str, torch.Tensor]], token: str | list[str] | None = None, tokenizer: 'PreTrainedTokenizer' | None = None, text_encoder: 'PreTrainedModel' | None = None, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L270) | |
| **๋งค๊ฐ๋ณ์:** | |
| pretrained_model_name_or_path (`str` ๋๋ `os.PathLike` ๋๋ `list[str or os.PathLike]` ๋๋ `Dict` ๋๋ `list[Dict]`) : ๋ค์ ์ค ํ๋์ด๊ฑฐ๋, ์ด๋ค์ ๋ฆฌ์คํธ์ผ ์ ์์ต๋๋ค: - Hub์ ํธ์คํ ๋ ์ฌ์ ํ์ต ๋ชจ๋ธ์ *model id* ๋ฌธ์์ด (์: `sd-concepts-library/low-poly-hd-logos-icons`). - ํ ์คํธ ์ธ๋ฒ์ ๊ฐ์ค์น๋ฅผ ํฌํจํ๋ *๋๋ ํฐ๋ฆฌ* ๊ฒฝ๋ก (์: `./my_text_inversion_directory/`). - ํ ์คํธ ์ธ๋ฒ์ ๊ฐ์ค์น๋ฅผ ํฌํจํ๋ *ํ์ผ* ๊ฒฝ๋ก (์: `./my_text_inversions.pt`). - [torch state dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict). | |
| token (`str` ๋๋ `list[str]`, *์ ํ ์ฌํญ*) : ํ ์คํธ ์ธ๋ฒ์ ๊ฐ์ค์น์ ์ฌ์ฉํ ํ ํฐ์ ์ฌ์ ์ํฉ๋๋ค. `pretrained_model_name_or_path`๊ฐ ๋ฆฌ์คํธ์ธ ๊ฒฝ์ฐ, `token`๋ ๋์ผํ ๊ธธ์ด์ ๋ฆฌ์คํธ์ฌ์ผ ํฉ๋๋ค. | |
| text_encoder ([CLIPTextModel](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel), *์ ํ ์ฌํญ*) : ๋๊ฒฐ๋ ํ ์คํธ ์ธ์ฝ๋([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)). ์ง์ ๋์ง ์์ผ๋ฉด ํจ์๊ฐ self.tokenizer๋ฅผ ์ฌ์ฉํฉ๋๋ค. | |
| tokenizer ([CLIPTokenizer](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer), *์ ํ ์ฌํญ*) : ํ ์คํธ๋ฅผ ํ ํฐํํ `CLIPTokenizer`์ ๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ํจ์๊ฐ self.tokenizer๋ฅผ ์ฌ์ฉํฉ๋๋ค. | |
| weight_name (`str`, *์ ํ ์ฌํญ*) : ์ปค์คํ ๊ฐ์ค์น ํ์ผ์ ์ด๋ฆ. ๋ค์ ๊ฒฝ์ฐ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค: - ์ ์ฅ๋ ํ ์คํธ ์ธ๋ฒ์ ํ์ผ์ด ๐ค Diffusers ํ์์ด์ง๋ง `text_inv.bin`๊ณผ ๊ฐ์ ํน์ ๊ฐ์ค์น ์ด๋ฆ์ผ๋ก ์ ์ฅ๋ ๊ฒฝ์ฐ. - ์ ์ฅ๋ ํ ์คํธ ์ธ๋ฒ์ ํ์ผ์ด Automatic1111 ํ์์ธ ๊ฒฝ์ฐ. | |
| cache_dir (`str | os.PathLike`, *์ ํ ์ฌํญ*) : ํ์ค ์บ์๋ฅผ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ, ๋ค์ด๋ก๋๋ ์ฌ์ ํ์ต ๋ชจ๋ธ ๊ตฌ์ฑ์ด ์บ์๋๋ ๋๋ ํฐ๋ฆฌ์ ๊ฒฝ๋ก์ ๋๋ค. | |
| force_download (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ์บ์๋ ๋ฒ์ ์ด ์กด์ฌํ๋๋ผ๋ ๋ชจ๋ธ ๊ฐ์ค์น ๋ฐ ๊ตฌ์ฑ ํ์ผ์ (์ฌ)๋ค์ด๋ก๋๋ฅผ ๊ฐ์ ํ ์ง ์ฌ๋ถ. | |
| proxies (`dict[str, str]`, *์ ํ ์ฌํญ*) : ํ๋กํ ์ฝ ๋๋ ์๋ํฌ์ธํธ๋ณ๋ก ์ฌ์ฉํ ํ๋ก์ ์๋ฒ์ ์ฌ์ ์ ๋๋ค. ์๋ฅผ ๋ค์ด, `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`์ ๊ฐ์ต๋๋ค. ๊ฐ ์์ฒญ์ ํ๋ก์๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. | |
| local_files_only (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ๋ก์ปฌ ๋ชจ๋ธ ๊ฐ์ค์น์ ๊ตฌ์ฑ ํ์ผ๋ง ๋ก๋ํ ์ง ์ฌ๋ถ๋ฅผ ์ง์ ํฉ๋๋ค. `True`๋ก ์ค์ ํ๋ฉด Hub์์ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ์ง ์์ต๋๋ค. | |
| hf_token (`str` ๋๋ *bool*, *์ ํ ์ฌํญ*) : ์๊ฒฉ ํ์ผ์ ๋ํ HTTP bearer ์ธ์ฆ์ผ๋ก ์ฌ์ฉํ ํ ํฐ์ ๋๋ค. `True`์ธ ๊ฒฝ์ฐ, `diffusers-cli login`์์ ์์ฑ๋ ํ ํฐ(`~/.huggingface`์ ์ ์ฅ๋จ)์ด ์ฌ์ฉ๋ฉ๋๋ค. | |
| revision (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `"main"`) : ์ฌ์ฉํ ํน์ ๋ชจ๋ธ ๋ฒ์ ์ ๋๋ค. Git์์ ํ์ฉํ๋ ๋ธ๋์น ์ด๋ฆ, ํ๊ทธ ์ด๋ฆ, ์ปค๋ฐ ID ๋๋ ๊ธฐํ ์๋ณ์์ผ ์ ์์ต๋๋ค. | |
| subfolder (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `""`) : Hub ๋๋ ๋ก์ปฌ์ ๋ ํฐ ๋ชจ๋ธ ์ ์ฅ์ ๋ด์์ ๋ชจ๋ธ ํ์ผ์ ์๋ธํด๋ ์์น์ ๋๋ค. | |
| mirror (`str`, *์ ํ ์ฌํญ*) : ์ค๊ตญ์์ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ ๋ ์ ๊ทผ์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ ๋ฏธ๋ฌ ์์ค์ ๋๋ค. ํด๋น ์์ค์ ์ ์์ฑ์ด๋ ์์ ์ฑ์ ๋ณด์ฅํ์ง ์์ผ๋ฉฐ, ์์ธํ ๋ด์ฉ์ ๋ฏธ๋ฌ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| [StableDiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline)์ ํ ์คํธ ์ธ์ฝ๋์ Textual Inversion ์๋ฒ ๋ฉ์ ๋ก๋ํฉ๋๋ค(๐ค Diffusers์ Automatic1111 ํ์ ๋ชจ๋ ์ง์). | |
| ์: | |
| ๐ค Diffusers ํ์์ผ๋ก Textual Inversion ์๋ฒ ๋ฉ ๋ฒกํฐ๋ฅผ ๋ก๋ํ๋ ค๋ฉด: | |
| ```py | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5" | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda") | |
| pipe.load_textual_inversion("sd-concepts-library/cat-toy") | |
| prompt = "A <cat-toy> backpack" | |
| image = pipe(prompt, num_inference_steps=50).images[0] | |
| image.save("cat-backpack.png") | |
| ``` | |
| Automatic1111 ํ์์ Textual Inversion ์๋ฒ ๋ฉ ๋ฒกํฐ๋ฅผ ๋ก๋ํ๋ ค๋ฉด ๋จผ์ ๋ฒกํฐ๋ฅผ ๋ค์ด๋ก๋(์: [civitAI](https://civitai.com/models/3036?modelVersionId=9857)์์)ํ ๋ค์ ๋ฒกํฐ๋ฅผ ๋ก๋ํด์ผ ํฉ๋๋ค. | |
| ๋ก์ปฌ์์: | |
| ```py | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5" | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda") | |
| pipe.load_textual_inversion("./charturnerv2.pt", token="charturnerv2") | |
| prompt = "charturnerv2, multiple views of the same character in the same outfit, a character turnaround of a woman wearing a black jacket and red shirt, best quality, intricate details." | |
| image = pipe(prompt, num_inference_steps=50).images[0] | |
| image.save("character.png") | |
| ``` | |
| #### from_single_file[[diffusers.StableDiffusionImg2ImgPipeline.from_single_file]] | |
| ```python | |
| from_single_file(pretrained_model_link_or_path, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/single_file.py#L248) | |
| **๋งค๊ฐ๋ณ์:** | |
| pretrained_model_link_or_path (`str` ๋๋ `os.PathLike`, *์ ํ ์ฌํญ*) : ๋ค์ ์ค ํ๋์ผ ์ ์์ต๋๋ค. - Hub์ `.ckpt` ํ์ผ ๋งํฌ(์: `"https://huggingface.co/<repo_id>/blob/main/<path_to_file>.ckpt"`). - ๋ชจ๋ ํ์ดํ๋ผ์ธ ๊ฐ์ค์น๋ฅผ ํฌํจํ๋ *ํ์ผ*์ ๊ฒฝ๋ก. | |
| dtype (`str` ๋๋ `torch.dtype`, *์ ํ ์ฌํญ*) : ๊ธฐ๋ณธ `torch.dtype`๋ฅผ ์ฌ์ ์ํ์ฌ ๋ค๋ฅธ dtype๋ก ๋ชจ๋ธ์ ๋ก๋ํฉ๋๋ค. | |
| force_download (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ์บ์๋ ๋ฒ์ ์ด ์กด์ฌํ๋๋ผ๋ ๋ชจ๋ธ ๊ฐ์ค์น ๋ฐ ๊ตฌ์ฑ ํ์ผ์ (์ฌ)๋ค์ด๋ก๋๋ฅผ ๊ฐ์ ํ ์ง ์ฌ๋ถ. | |
| cache_dir (`str | os.PathLike`, *์ ํ ์ฌํญ*) : ํ์ค ์บ์๋ฅผ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ, ๋ค์ด๋ก๋๋ ์ฌ์ ํ์ต ๋ชจ๋ธ ๊ตฌ์ฑ์ด ์บ์๋๋ ๋๋ ํฐ๋ฆฌ์ ๊ฒฝ๋ก์ ๋๋ค. | |
| proxies (`dict[str, str]`, *์ ํ ์ฌํญ*) : ํ๋กํ ์ฝ ๋๋ ์๋ํฌ์ธํธ๋ณ๋ก ์ฌ์ฉํ ํ๋ก์ ์๋ฒ์ ์ฌ์ ์ ๋๋ค. ์๋ฅผ ๋ค์ด, `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`์ ๊ฐ์ต๋๋ค. ๊ฐ ์์ฒญ์ ํ๋ก์๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. | |
| local_files_only (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `False`) : ๋ก์ปฌ ๋ชจ๋ธ ๊ฐ์ค์น์ ๊ตฌ์ฑ ํ์ผ๋ง ๋ก๋ํ ์ง ์ฌ๋ถ๋ฅผ ์ง์ ํฉ๋๋ค. `True`๋ก ์ค์ ํ๋ฉด Hub์์ ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํ์ง ์์ต๋๋ค. | |
| token (`str` ๋๋ *bool*, *์ ํ ์ฌํญ*) : ์๊ฒฉ ํ์ผ์ ๋ํ HTTP bearer ์ธ์ฆ์ผ๋ก ์ฌ์ฉํ ํ ํฐ์ ๋๋ค. `True`์ธ ๊ฒฝ์ฐ, `diffusers-cli login`์์ ์์ฑ๋ ํ ํฐ(`~/.huggingface`์ ์ ์ฅ๋จ)์ด ์ฌ์ฉ๋ฉ๋๋ค. | |
| revision (`str`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `"main"`) : ์ฌ์ฉํ ํน์ ๋ชจ๋ธ ๋ฒ์ ์ ๋๋ค. Git์์ ํ์ฉํ๋ ๋ธ๋์น ์ด๋ฆ, ํ๊ทธ ์ด๋ฆ, ์ปค๋ฐ ID ๋๋ ๊ธฐํ ์๋ณ์์ผ ์ ์์ต๋๋ค. | |
| original_config_file (`str`, *์ ํ ์ฌํญ*) : ๋ชจ๋ธ์ ํ์ตํ๋ ๋ฐ ์ฌ์ฉ๋ ์๋ config ํ์ผ์ ๊ฒฝ๋ก์ ๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด checkpoint ํ์ผ์์ config ํ์ผ์ ์ถ๋ก ํฉ๋๋ค. | |
| config (`str`, *์ ํ ์ฌํญ*) : ๋ค์ ์ค ํ๋์ผ ์ ์์ต๋๋ค. - Hub์ ํธ์คํ ๋ ์ฌ์ ํ์ต๋ ํ์ดํ๋ผ์ธ์ *repo id* ๋ฌธ์์ด(์: `CompVis/ldm-text2im-large-256`). - Diffusers ํ์์ ํ์ดํ๋ผ์ธ ๊ตฌ์ฑ ์์ ์ค์ ์ ํฌํจํ๋ *๋๋ ํฐ๋ฆฌ* ๊ฒฝ๋ก(์: `./my_pipeline_directory/`). | |
| disable_mmap ('bool', *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 'False') : Safetensors ๋ชจ๋ธ์ ๋ก๋ํ ๋ mmap์ ๋นํ์ฑํํ ์ง ์ฌ๋ถ์ ๋๋ค. ๋ชจ๋ธ์ด ๋คํธ์ํฌ ๋ง์ดํธ๋ ํ๋ ๋๋ผ์ด๋ธ์ ์๋ ๊ฒฝ์ฐ ์ด ์ต์ ์ ์ฌ์ฉํ๋ฉด ์ฑ๋ฅ์ด ๋ ์ข์์ง ์ ์์ต๋๋ค. | |
| kwargs (๋จ์ ํค์๋ ์ธ์์ ์ฌ์ , *์ ํ ์ฌํญ*) : ๋ก๋ ๋ฐ ์ ์ฅ ๊ฐ๋ฅํ ๋ณ์(ํน์ ํ์ดํ๋ผ์ธ ํด๋์ค์ ํ์ดํ๋ผ์ธ ๊ตฌ์ฑ ์์)๋ฅผ ๋ฎ์ด์ธ ์ ์์ต๋๋ค. ๋ฎ์ด์ฐ๊ธฐ๋ ๊ตฌ์ฑ ์์๋ ํ์ดํ๋ผ์ธ์ `__init__` ๋ฉ์๋์ ์ง์ ์ ๋ฌ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์๋ ์์๋ฅผ ์ฐธ์กฐํ์ธ์. | |
| `.ckpt` ๋๋ `.safetensors` ํ์์ผ๋ก ์ ์ฅ๋ ์ฌ์ ํ์ต๋ ํ์ดํ๋ผ์ธ ๊ฐ์ค์น์์ [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)์ ์ด๊ธฐํํฉ๋๋ค. ํ์ดํ๋ผ์ธ์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ๊ฐ ๋ชจ๋(`model.eval()`)๋ก ์ค์ ๋ฉ๋๋ค. | |
| ์: | |
| ```py | |
| >>> from diffusers import StableDiffusionPipeline | |
| >>> # Download pipeline from huggingface.co and cache. | |
| >>> pipeline = StableDiffusionPipeline.from_single_file( | |
| ... "https://huggingface.co/WarriorMama777/OrangeMixs/blob/main/Models/AbyssOrangeMix/AbyssOrangeMix.safetensors" | |
| ... ) | |
| >>> # Download pipeline from local file | |
| >>> # file is downloaded under ./v1-5-pruned-emaonly.ckpt | |
| >>> pipeline = StableDiffusionPipeline.from_single_file("./v1-5-pruned-emaonly.ckpt") | |
| >>> # Enable float16 and move to GPU | |
| >>> pipeline = StableDiffusionPipeline.from_single_file( | |
| ... "https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.ckpt", | |
| ... torch_dtype=torch.float16, | |
| ... ) | |
| >>> pipeline.to("cuda") | |
| ``` | |
| #### load_lora_weights[[diffusers.StableDiffusionImg2ImgPipeline.load_lora_weights]] | |
| ```python | |
| load_lora_weights(pretrained_model_name_or_path_or_dict: str | dict[str, torch.Tensor], adapter_name: str | None = None, hotswap: bool = False, **kwargs) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/lora_pipeline.py#L150) | |
| **๋งค๊ฐ๋ณ์:** | |
| pretrained_model_name_or_path_or_dict (`str` ๋๋ `os.PathLike` ๋๋ `dict`) : [lora_state_dict()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.lora_state_dict)์(๋ฅผ) ์ฐธ์กฐํ์ธ์. | |
| adapter_name (`str`, *์ ํ ์ฌํญ*) : ๋ก๋๋ ์ด๋ํฐ ๋ชจ๋ธ์ ์ฐธ์กฐํ ๋ ์ฌ์ฉํ ์ด๋ํฐ ์ด๋ฆ. ์ง์ ํ์ง ์์ผ๋ฉด ๋ก๋ ์ค์ธ ์ด๋ํฐ์ ์ด ๊ฐ์๋ฅผ i๋ผ๊ณ ํ ๋ `default_{i}`๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. | |
| low_cpu_mem_usage (`bool`, *์ ํ ์ฌํญ*) : ๋ฌด์์ ๊ฐ์ค์น๋ฅผ ์ด๊ธฐํํ์ง ์๊ณ ์ฌ์ ํ์ต๋ LoRA ๊ฐ์ค์น๋ง ๋ก๋ํ์ฌ ๋ชจ๋ธ ๋ก๋ฉ ์๋๋ฅผ ๋์ ๋๋ค. | |
| hotswap (`bool`, *์ ํ ์ฌํญ*) : ๊ธฐ๋ณธ๊ฐ์ `False`์ ๋๋ค. ๊ธฐ์กด (LoRA) ์ด๋ํฐ๋ฅผ ์๋ก ๋ก๋ํ ์ด๋ํฐ๋ก ์ ์๋ฆฌ์์ ๊ต์ฒดํ ์ง ์ฌ๋ถ์ ๋๋ค. ์ฆ, ์ถ๊ฐ ์ด๋ํฐ๋ฅผ ๋ก๋ํ๋ ๋์ ๊ธฐ์กด ์ด๋ํฐ์ ๊ฐ์ค์น๋ฅผ ์ ์ด๋ํฐ์ ๊ฐ์ค์น๋ก ๋์ฒดํฉ๋๋ค. ์ด๋ ๋ ๋น ๋ฅด๊ณ ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ผ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํซ์ค์์ ์ฃผ์ ์ด์ ์ ๋ชจ๋ธ์ด torch.compile๋ก ์ปดํ์ผ๋ ๊ฒฝ์ฐ, ์ ์ด๋ํฐ๋ฅผ ๋ก๋ํ ๋ ๋ชจ๋ธ์ ์ฌ์ปดํ์ผ์ด ํ์ํ์ง ์๋ค๋ ์ ์ ๋๋ค. ํซ์ค์์ ์ฌ์ฉํ ๋ ์ ๋ฌํ๋ `adapter_name`์ ์ด๋ฏธ ๋ก๋๋ ์ด๋ํฐ์ ์ด๋ฆ์ด์ด์ผ ํฉ๋๋ค. ์ ์ด๋ํฐ์ ๊ธฐ์กด ์ด๋ํฐ์ ๋ญํฌ์/๋๋ LoRA ์ํ(์ฆ, ์ค์ผ์ผ๋ง)๊ฐ ๋ค๋ฅธ ๊ฒฝ์ฐ, ์ด๋ํฐ๋ฅผ ๋ก๋ํ๊ธฐ ์ ์ ์ถ๊ฐ ๋ฉ์๋๋ฅผ ํธ์ถํด์ผ ํฉ๋๋ค: ```py pipeline = ... # load diffusers pipeline max_rank = ... # the highest rank among all LoRAs that you want to load # call *before* compiling and loading the LoRA adapter pipeline.enable_lora_hotswap(target_rank=max_rank) pipeline.load_lora_weights(file_name) # optionally compile the model now ``` ํ ์คํธ ์ธ์ฝ๋์ ์ด๋ํฐ ํซ์ค์์ ์์ง ์ง์๋์ง ์์ต๋๋ค. ์ด ๊ธฐ๋ฒ์๋ ๋ช ๊ฐ์ง ์ถ๊ฐ ์ ํ ์ฌํญ์ด ์์ผ๋ฉฐ, ์ฌ๊ธฐ์์ ๋ฌธ์ํ๋์ด ์์ต๋๋ค: https://huggingface.co/docs/peft/main/en/package_reference/hotswap | |
| kwargs (`dict`, *์ ํ ์ฌํญ*) : [lora_state_dict()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.lora_state_dict)๋ฅผ ์ฐธ์กฐํ์ธ์. | |
| `pretrained_model_name_or_path_or_dict`์ ์ง์ ๋ LoRA ๊ฐ์ค์น๋ฅผ `self.unet`์ `self.text_encoder`์ ๋ก๋ํฉ๋๋ค. | |
| ๋ชจ๋ kwargs๋ `self.lora_state_dict`๋ก ์ ๋ฌ๋ฉ๋๋ค. | |
| state dict๊ฐ ๋ก๋๋๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ [lora_state_dict()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.lora_state_dict)์ ์ฐธ์กฐํ์ธ์. | |
| `self.unet`์ ์ํ ์ฌ์ ์ด ๋ก๋๋๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ [load_lora_into_unet()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_into_unet)์ ์ฐธ์กฐํ์ญ์์ค. | |
| `self.text_encoder`์ state dict๊ฐ ๋ก๋๋๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ [load_lora_into_text_encoder()](/docs/diffusers/main/ko/api/loaders/lora#diffusers.loaders.StableDiffusionLoraLoaderMixin.load_lora_into_text_encoder)๋ฅผ ์ฐธ์กฐํ์ธ์. | |
| #### save_lora_weights[[diffusers.StableDiffusionImg2ImgPipeline.save_lora_weights]] | |
| ```python | |
| save_lora_weights(save_directory: str | os.PathLike, unet_lora_layers: dict[str, typing.Union[torch.nn.Module, torch.Tensor]] = None, text_encoder_lora_layers: dict[str, torch.nn.Module] = None, is_main_process: bool = True, weight_name: str = None, save_function: typing.Callable = None, safe_serialization: bool = True, unet_lora_adapter_metadata = None, text_encoder_lora_adapter_metadata = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/lora_pipeline.py#L469) | |
| **๋งค๊ฐ๋ณ์:** | |
| save_directory (`str` ๋๋ `os.PathLike`) : LoRA ํ๋ผ๋ฏธํฐ๋ฅผ ์ ์ฅํ ๋๋ ํฐ๋ฆฌ์ ๋๋ค. ์กด์ฌํ์ง ์์ผ๋ฉด ์์ฑ๋ฉ๋๋ค. | |
| unet_lora_layers (`dict[str, torch.nn.Module]` ๋๋ `dict[str, torch.Tensor]`) : `unet`์ ํด๋นํ๋ LoRA ๋ ์ด์ด์ state dict์ ๋๋ค. | |
| text_encoder_lora_layers (`dict[str, torch.nn.Module]` ๋๋ `dict[str, torch.Tensor]`) : `text_encoder`์ ํด๋นํ๋ LoRA ๋ ์ด์ด์ state dict์ ๋๋ค. ๐ค Transformers์์ ๊ฐ์ ธ์ค๋ฏ๋ก text encoder LoRA state dict๋ฅผ ๋ช ์์ ์ผ๋ก ์ ๋ฌํด์ผ ํฉ๋๋ค. | |
| is_main_process (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : ์ด ํจ์๋ฅผ ํธ์ถํ๋ ํ๋ก์ธ์ค๊ฐ ๋ฉ์ธ ํ๋ก์ธ์ค์ธ์ง ์ฌ๋ถ์ ๋๋ค. ๋ถ์ฐ ํ์ต ์ค์ ๋ชจ๋ ํ๋ก์ธ์ค์์ ์ด ํจ์๋ฅผ ํธ์ถํด์ผ ํ๋ ๊ฒฝ์ฐ ์ ์ฉํฉ๋๋ค. ์ด ๊ฒฝ์ฐ ๋ ์ด์ค ์กฐ๊ฑด์ ๋ฐฉ์งํ๊ธฐ ์ํด ๋ฉ์ธ ํ๋ก์ธ์ค์์๋ง `is_main_process=True`๋ก ์ค์ ํ์ธ์. | |
| save_function (`Callable`) : ์ํ ์ฌ์ (state dictionary)์ ์ ์ฅํ๋ ๋ฐ ์ฌ์ฉํ ํจ์์ ๋๋ค. ๋ถ์ฐ ํ์ต ์ค์ `torch.save`๋ฅผ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ๋์ฒดํด์ผ ํ๋ ๊ฒฝ์ฐ ์ ์ฉํฉ๋๋ค. ํ๊ฒฝ ๋ณ์ `DIFFUSERS_SAVE_MODE`๋ก ์ค์ ํ ์ ์์ต๋๋ค. | |
| safe_serialization (`bool`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `True`) : `safetensors` ๋๋ `pickle`๋ฅผ ์ฌ์ฉํ ์ ํต์ ์ธ PyTorch ๋ฐฉ์์ผ๋ก ๋ชจ๋ธ์ ์ ์ฅํ ์ง ์ฌ๋ถ. | |
| unet_lora_adapter_metadata : state dict์ ํจ๊ป ์ง๋ ฌํ๋ unet์ ์ฐ๊ฒฐ๋ LoRA ์ด๋ํฐ ๋ฉํ๋ฐ์ดํฐ. | |
| text_encoder_lora_adapter_metadata : state dict์ ํจ๊ป ์ง๋ ฌํ๋ ํ ์คํธ ์ธ์ฝ๋์ ๊ด๋ จ๋ LoRA ์ด๋ํฐ ๋ฉํ๋ฐ์ดํฐ. | |
| UNet๊ณผ ํ ์คํธ ์ธ์ฝ๋์ ํด๋นํ๋ LoRA ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ฅํฉ๋๋ค. | |
| #### encode_prompt[[diffusers.StableDiffusionImg2ImgPipeline.encode_prompt]] | |
| ```python | |
| encode_prompt(prompt, device, num_images_per_prompt, do_classifier_free_guidance, negative_prompt = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, lora_scale: float | None = None, clip_skip: int | None = None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L358) | |
| **๋งค๊ฐ๋ณ์:** | |
| prompt (`str` ๋๋ `list[str]`, *์ ํ ์ฌํญ*) : ์ธ์ฝ๋ฉํ ํ๋กฌํํธ | |
| device : (`torch.device`): torch ๋๋ฐ์ด์ค | |
| num_images_per_prompt (`int`) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง ์ | |
| do_classifier_free_guidance (`bool`) : classifier free guidance๋ฅผ ์ฌ์ฉํ ์ง ์ฌ๋ถ | |
| negative_prompt (`str` ๋๋ `list[str]`, *์ ํ ์ฌํญ*) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์ ๋๋ค. ์ ์๋์ง ์์ ๊ฒฝ์ฐ ๋์ `negative_prompt_embeds`๋ฅผ ์ ๋ฌํด์ผ ํฉ๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, `guidance_scale`์ด `1`๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค). | |
| prompt_embeds (`torch.Tensor`, *์ ํ ์ฌํญ*) : ๋ฏธ๋ฆฌ ์์ฑ๋ ํ ์คํธ ์๋ฒ ๋ฉ์ ๋๋ค. *์๋ฅผ ๋ค์ด* ํ๋กฌํํธ ๊ฐ์ค์น์ ๊ฐ์ ํ ์คํธ ์ ๋ ฅ์ ์ฝ๊ฒ ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด `prompt` ์ ๋ ฅ ์ธ์์์ ํ ์คํธ ์๋ฒ ๋ฉ์ด ์์ฑ๋ฉ๋๋ค. | |
| negative_prompt_embeds (`torch.Tensor`, *์ ํ ์ฌํญ*) : ๋ฏธ๋ฆฌ ์์ฑ๋ ๋ถ์ ํ ์คํธ ์๋ฒ ๋ฉ์ ๋๋ค. ํ ์คํธ ์ ๋ ฅ์ ์ฝ๊ฒ ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, *์๋ฅผ ๋ค์ด* ํ๋กฌํํธ ๊ฐ์ค์น ์ค์ ์ ํ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด `negative_prompt` ์ ๋ ฅ ์ธ์์์ negative_prompt_embeds๊ฐ ์์ฑ๋ฉ๋๋ค. | |
| lora_scale (`float`, *์ ํ ์ฌํญ*) : LoRA ๋ ์ด์ด๊ฐ ๋ก๋๋ ๊ฒฝ์ฐ ํ ์คํธ ์ธ์ฝ๋์ ๋ชจ๋ LoRA ๋ ์ด์ด์ ์ ์ฉ๋ LoRA ์ค์ผ์ผ์ ๋๋ค. | |
| clip_skip (`int`, *์ ํ ์ฌํญ*) : ํ๋กฌํํธ ์๋ฒ ๋ฉ์ ๊ณ์ฐํ ๋ CLIP์์ ๊ฑด๋๋ธ ๋ ์ด์ด ์. ๊ฐ์ด 1์ด๋ฉด ์ต์ข ๋ ์ด์ด ๋ฐ๋ก ์ด์ ๋ ์ด์ด์ ์ถ๋ ฅ์ ํ๋กฌํํธ ์๋ฒ ๋ฉ ๊ณ์ฐ์ ์ฌ์ฉํฉ๋๋ค. | |
| ํ๋กฌํํธ๋ฅผ ํ ์คํธ ์ธ์ฝ๋์ ํ๋ ์ํ๋ก ์ธ์ฝ๋ฉํฉ๋๋ค. | |
| #### get_guidance_scale_embedding[[diffusers.StableDiffusionImg2ImgPipeline.get_guidance_scale_embedding]] | |
| ```python | |
| get_guidance_scale_embedding(w: Tensor, embedding_dim: int = 512, dtype: dtype = torch.float32) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L801) | |
| **๋งค๊ฐ๋ณ์:** | |
| w (`torch.Tensor`) : ์ง์ ๋ guidance scale์ ์ฌ์ฉํ์ฌ ์๋ฒ ๋ฉ ๋ฒกํฐ๋ฅผ ์์ฑํ๊ณ , ์ด๋ฅผ ํตํด timestep ์๋ฒ ๋ฉ์ ํ๋ถํ๊ฒ ๋ง๋ญ๋๋ค. | |
| embedding_dim (`int`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑํ ์๋ฒ ๋ฉ์ ์ฐจ์. | |
| dtype (`torch.dtype`, *์ ํ ์ฌํญ*, ๊ธฐ๋ณธ๊ฐ `torch.float32`) : ์์ฑ๋ ์๋ฒ ๋ฉ์ ๋ฐ์ดํฐ ์ ํ์ ๋๋ค. | |
| **๋ฐํ๊ฐ:** `torch.Tensor` | |
| `(len(w), embedding_dim)` ํํ์ ์๋ฒ ๋ฉ ๋ฒกํฐ. | |
| https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298 ๋ฅผ ์ฐธ์กฐํ์ธ์. | |
| ## StableDiffusionPipelineOutput[[diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput]] | |
| #### diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput[[diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput]] | |
| ```python | |
| diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray, nsfw_content_detected: list[bool] | None) | |
| ``` | |
| [์์ค](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_output.py#L10) | |
| **๋งค๊ฐ๋ณ์:** | |
| images (`list[PIL.Image.Image]` ๋๋ `np.ndarray`) : `batch_size` ๊ธธ์ด์ ๋ ธ์ด์ฆ ์ ๊ฑฐ๋ PIL ์ด๋ฏธ์ง ๋ชฉ๋ก ๋๋ `(batch_size, height, width, num_channels)` ๋ชจ์์ NumPy ๋ฐฐ์ด. | |
| nsfw_content_detected (`list[bool]`) : ํด๋น ์์ฑ๋ ์ด๋ฏธ์ง์ "not-safe-for-work"(nsfw) ์ฝํ ์ธ ๊ฐ ํฌํจ๋์ด ์๋์ง ์ฌ๋ถ๋ฅผ ๋ํ๋ด๋ ๋ฆฌ์คํธ. ์์ ๊ฒ์ฌ๋ฅผ ์ํํ ์ ์๋ ๊ฒฝ์ฐ `None`. | |
| Stable Diffusion ํ์ดํ๋ผ์ธ์ ์ถ๋ ฅ ํด๋์ค์ ๋๋ค. | |
Xet Storage Details
- Size:
- 40.8 kB
- Xet hash:
- 1190604da8f2c3c285de644950424648ba623564fd5c05e2e0693072b3293921
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.