Buckets:
| # Textual Inversion | |
| Textual Inversion은 몇 개의 예시 이미지에서 새로운 텍스트 임베딩을 학습하여 모델을 개인화하는 학습 방법입니다. 학습 과정에서 생성되는 파일은 매우 작으며(수 KB) 새로운 임베딩은 텍스트 인코더에 로드할 수 있습니다. | |
| `TextualInversionLoaderMixin`은 Diffusers와 Automatic1111에서 Textual Inversion 임베딩을 텍스트 인코더로 로드하고, 해당 임베딩을 활성화하는 특수 토큰을 로드하는 기능을 제공합니다. | |
| > [!TIP] | |
| > Textual Inversion 임베딩을 로드하는 방법에 대해 자세히 알아보려면 [Textual Inversion](../../using-diffusers/legacy_adapters#textual-inversion) 로드 가이드를 참조하세요. | |
| ## TextualInversionLoaderMixin[[diffusers.loaders.TextualInversionLoaderMixin]] | |
| #### diffusers.loaders.TextualInversionLoaderMixin[[diffusers.loaders.TextualInversionLoaderMixin]] | |
| ```python | |
| diffusers.loaders.TextualInversionLoaderMixin() | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L118) | |
| Textual Inversion 토큰과 임베딩을 토크나이저와 텍스트 인코더에 로드합니다. | |
| #### load_textual_inversion[[diffusers.loaders.TextualInversionLoaderMixin.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#L271) | |
| **매개변수:** | |
| 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") | |
| ``` | |
| #### maybe_convert_prompt[[diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt]] | |
| ```python | |
| maybe_convert_prompt(prompt: str | list[str], tokenizer: 'PreTrainedTokenizer') | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L123) | |
| **매개변수:** | |
| prompt (`str` 또는 `str` 목록) : 이미지 생성을 안내하는 프롬프트입니다. | |
| tokenizer (`PreTrainedTokenizer`) : 프롬프트를 입력 토큰으로 인코딩하는 역할을 담당하는 토크나이저입니다. | |
| **반환값:** `str` 또는 `str` 목록 | |
| 변환된 프롬프트 | |
| 멀티 벡터 텍스트 인버전 임베딩에 해당하는 특수 토큰을 포함하는 프롬프트를 처리하며, 해당 특수 토큰을 각 벡터에 하나씩 대응하는 여러 특수 토큰으로 대체합니다. 프롬프트에 텍스트 인버전 토큰이 없거나 텍스트 인버전 토큰이 단일 벡터인 경우, 입력 프롬프트를 반환합니다. | |
| #### unload_textual_inversion[[diffusers.loaders.TextualInversionLoaderMixin.unload_textual_inversion]] | |
| ```python | |
| unload_textual_inversion(tokens: str | list[str] | None = None, tokenizer: 'PreTrainedTokenizer' | None = None, text_encoder: 'PreTrainedModel' | None = None) | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L467) | |
| [StableDiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline)의 텍스트 인코더에서 Textual Inversion 임베딩을 언로드합니다 | |
| 예: | |
| ```py | |
| from diffusers import AutoPipelineForText2Image | |
| import torch | |
| pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5") | |
| # Example 1 | |
| pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork") | |
| pipeline.load_textual_inversion("sd-concepts-library/moeb-style") | |
| # Remove all token embeddings | |
| pipeline.unload_textual_inversion() | |
| # Example 2 | |
| pipeline.load_textual_inversion("sd-concepts-library/moeb-style") | |
| pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork") | |
| # Remove just one token | |
| pipeline.unload_textual_inversion("<moe-bius>") | |
| # Example 3: unload from SDXL | |
| pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0") | |
| embedding_path = hf_hub_download( | |
| repo_id="linoyts/web_y2k", filename="web_y2k_emb.safetensors", repo_type="model" | |
| ) | |
| # load embeddings to the text encoders | |
| state_dict = load_file(embedding_path) | |
| # load embeddings of text_encoder 1 (CLIP ViT-L/14) | |
| pipeline.load_textual_inversion( | |
| state_dict["clip_l"], | |
| tokens=["<s0>", "<s1>"], | |
| text_encoder=pipeline.text_encoder, | |
| tokenizer=pipeline.tokenizer, | |
| ) | |
| # load embeddings of text_encoder 2 (CLIP ViT-G/14) | |
| pipeline.load_textual_inversion( | |
| state_dict["clip_g"], | |
| tokens=["<s0>", "<s1>"], | |
| text_encoder=pipeline.text_encoder_2, | |
| tokenizer=pipeline.tokenizer_2, | |
| ) | |
| # Unload explicitly from both text encoders and tokenizers | |
| pipeline.unload_textual_inversion( | |
| tokens=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder, tokenizer=pipeline.tokenizer | |
| ) | |
| pipeline.unload_textual_inversion( | |
| tokens=["<s0>", "<s1>"], text_encoder=pipeline.text_encoder_2, tokenizer=pipeline.tokenizer_2 | |
| ) | |
| ``` | |
Xet Storage Details
- Size:
- 10.1 kB
- Xet hash:
- 9e553b60ed34a84996648bff27399365ad2876b787a047a9c96b6751da048c08
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.