import{s as ge,n as Ue,o as we}from"../chunks/scheduler.23542ac5.js";import{S as he,i as _e,e as i,s as n,c as p,h as je,a as o,d as l,b as a,f as be,g as r,j as d,k as ie,l as ve,m as s,n as m,t as c,o as f,p as M}from"../chunks/index.9b1f405b.js";import{C as $e,H as Te,E as ke}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.a0107385.js";import{C as Q}from"../chunks/CodeBlock.a47c827a.js";import{D as Ce}from"../chunks/DocNotebookDropdown.68a629d2.js";function Je(oe){let u,z,S,I,b,F,g,H,U,L,w,pe='<code>StableDiffusionPipeline</code>은  textual-inversion을 지원하는데, 이는 몇 개의 샘플 이미지만으로 stable diffusion과 같은 모델이 새로운 컨셉을 학습할 수 있도록 하는 기법입니다. 이를 통해 생성된 이미지를 더 잘 제어하고 특정 컨셉에 맞게 모델을 조정할 수 있습니다. 커뮤니티에서 만들어진 컨셉들의 컬렉션은 <a href="https://huggingface.co/spaces/sd-concepts-library/stable-diffusion-conceptualizer" rel="nofollow">Stable Diffusion Conceptualizer</a>를 통해 빠르게 사용해볼 수 있습니다.',R,h,re='이 가이드에서는 Stable Diffusion Conceptualizer에서 사전학습한 컨셉을 사용하여 textual-inversion으로 추론을 실행하는 방법을 보여드립니다. textual-inversion으로 모델에 새로운 컨셉을 학습시키는 데 관심이 있으시다면,  <a href="./training/text_inversion">Textual Inversion</a>  훈련 가이드를 참조하세요.',Y,_,me="Hugging Face 계정으로 로그인하세요:",V,j,E,v,ce="필요한 라이브러리를 불러오고 생성된 이미지를 시각화하기 위한 도우미 함수 <code>image_grid</code>를 만듭니다:",P,$,N,T,fe='Stable Diffusion과 <a href="https://huggingface.co/spaces/sd-concepts-library/stable-diffusion-conceptualizer" rel="nofollow">Stable Diffusion Conceptualizer</a>에서 사전학습된 컨셉을 선택합니다:',D,k,K,C,Me="이제 파이프라인을 로드하고 사전학습된 컨셉을 파이프라인에 전달할 수 있습니다:",q,J,A,W,ue="특별한 placeholder token ’<code>&lt;cat-toy&gt;</code>‘를 사용하여 사전학습된 컨셉으로 프롬프트를 만들고, 생성할 샘플의 수와 이미지 행의 수를 선택합니다:",O,x,ee,B,de="그런 다음 파이프라인을 실행하고, 생성된 이미지들을 저장합니다. 그리고 처음에 만들었던 도우미 함수 <code>image_grid</code>를 사용하여 생성 결과들을 시각화합니다. 이 때 <code>num_inference_steps</code>와 <code>guidance_scale</code>과 같은 매개 변수들을 조정하여, 이것들이 이미지 품질에 어떠한 영향을 미치는지를 자유롭게 확인해보시기 바랍니다.",te,Z,le,y,ye='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/textual_inversion_inference.png"/>',se,G,ne,X,ae;return b=new $e({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new Ce({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/textual_inversion_inference.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/textual_inversion_inference.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/textual_inversion_inference.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/textual_inversion_inference.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/textual_inversion_inference.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/textual_inversion_inference.ipynb"}]}}),U=new Te({props:{title:"Textual inversion",local:"textual-inversion",headingTag:"h1"}}),j=new Q({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),$=new Q({props:{code:"aW1wb3J0JTIwb3MlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQWltcG9ydCUyMFBJTCUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBDTElQSW1hZ2VQcm9jZXNzb3IlMkMlMjBDTElQVGV4dE1vZGVsJTJDJTIwQ0xJUFRva2VuaXplciUwQSUwQSUwQWRlZiUyMGltYWdlX2dyaWQoaW1ncyUyQyUyMHJvd3MlMkMlMjBjb2xzKSUzQSUwQSUyMCUyMCUyMCUyMGFzc2VydCUyMGxlbihpbWdzKSUyMCUzRCUzRCUyMHJvd3MlMjAqJTIwY29scyUwQSUwQSUyMCUyMCUyMCUyMHclMkMlMjBoJTIwJTNEJTIwaW1ncyU1QjAlNUQuc2l6ZSUwQSUyMCUyMCUyMCUyMGdyaWQlMjAlM0QlMjBJbWFnZS5uZXcoJTIyUkdCJTIyJTJDJTIwc2l6ZSUzRChjb2xzJTIwKiUyMHclMkMlMjByb3dzJTIwKiUyMGgpKSUwQSUyMCUyMCUyMCUyMGdyaWRfdyUyQyUyMGdyaWRfaCUyMCUzRCUyMGdyaWQuc2l6ZSUwQSUwQSUyMCUyMCUyMCUyMGZvciUyMGklMkMlMjBpbWclMjBpbiUyMGVudW1lcmF0ZShpbWdzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdyaWQucGFzdGUoaW1nJTJDJTIwYm94JTNEKGklMjAlMjUlMjBjb2xzJTIwKiUyMHclMkMlMjBpJTIwJTJGJTJGJTIwY29scyUyMColMjBoKSklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBncmlk",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">import</span> PIL
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CLIPImageProcessor, CLIPTextModel, CLIPTokenizer


<span class="hljs-keyword">def</span> <span class="hljs-title function_">image_grid</span>(<span class="hljs-params">imgs, rows, cols</span>):
    <span class="hljs-keyword">assert</span> <span class="hljs-built_in">len</span>(imgs) == rows * cols

    w, h = imgs[<span class="hljs-number">0</span>].size
    grid = Image.new(<span class="hljs-string">&quot;RGB&quot;</span>, size=(cols * w, rows * h))
    grid_w, grid_h = grid.size

    <span class="hljs-keyword">for</span> i, img <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(imgs):
        grid.paste(img, box=(i % cols * w, i // cols * h))
    <span class="hljs-keyword">return</span> grid`,wrap:!1}}),k=new Q({props:{code:"cHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEFyZXBvX2lkX2VtYmVkcyUyMCUzRCUyMCUyMnNkLWNvbmNlcHRzLWxpYnJhcnklMkZjYXQtdG95JTIy",highlighted:`pretrained_model_name_or_path = <span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
repo_id_embeds = <span class="hljs-string">&quot;sd-concepts-library/cat-toy&quot;</span>`,wrap:!1}}),J=new Q({props:{code:"cGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQocHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBJTBBcGlwZWxpbmUubG9hZF90ZXh0dWFsX2ludmVyc2lvbihyZXBvX2lkX2VtYmVkcyk=",highlighted:`pipeline = StableDiffusionPipeline.from_pretrained(pretrained_model_name_or_path, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)

pipeline.load_textual_inversion(repo_id_embeds)`,wrap:!1}}),x=new Q({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyYSUyMGdyYWZpdHRpJTIwaW4lMjBhJTIwZmF2ZWxhJTIwd2FsbCUyMHdpdGglMjBhJTIwJTNDY2F0LXRveSUzRSUyMG9uJTIwaXQlMjIlMEElMEFudW1fc2FtcGxlcyUyMCUzRCUyMDIlMEFudW1fcm93cyUyMCUzRCUyMDI=",highlighted:`prompt = <span class="hljs-string">&quot;a grafitti in a favela wall with a &lt;cat-toy&gt; on it&quot;</span>

num_samples = <span class="hljs-number">2</span>
num_rows = <span class="hljs-number">2</span>`,wrap:!1}}),Z=new Q({props:{code:"YWxsX2ltYWdlcyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMF8lMjBpbiUyMHJhbmdlKG51bV9yb3dzKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2ltYWdlc19wZXJfcHJvbXB0JTNEbnVtX3NhbXBsZXMlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSkuaW1hZ2VzJTBBJTIwJTIwJTIwJTIwYWxsX2ltYWdlcy5leHRlbmQoaW1hZ2VzKSUwQSUwQWdyaWQlMjAlM0QlMjBpbWFnZV9ncmlkKGFsbF9pbWFnZXMlMkMlMjBudW1fc2FtcGxlcyUyQyUyMG51bV9yb3dzKSUwQWdyaWQ=",highlighted:`all_images = []
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_rows):
    images = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=<span class="hljs-number">50</span>, guidance_scale=<span class="hljs-number">7.5</span>).images
    all_images.extend(images)

grid = image_grid(all_images, num_samples, num_rows)
grid`,wrap:!1}}),G=new ke({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/using-diffusers/textual_inversion_inference.md"}}),{c(){u=i("meta"),z=n(),S=i("p"),I=n(),p(b.$$.fragment),F=n(),p(g.$$.fragment),H=n(),p(U.$$.fragment),L=n(),w=i("p"),w.innerHTML=pe,R=n(),h=i("p"),h.innerHTML=re,Y=n(),_=i("p"),_.textContent=me,V=n(),p(j.$$.fragment),E=n(),v=i("p"),v.innerHTML=ce,P=n(),p($.$$.fragment),N=n(),T=i("p"),T.innerHTML=fe,D=n(),p(k.$$.fragment),K=n(),C=i("p"),C.textContent=Me,q=n(),p(J.$$.fragment),A=n(),W=i("p"),W.innerHTML=ue,O=n(),p(x.$$.fragment),ee=n(),B=i("p"),B.innerHTML=de,te=n(),p(Z.$$.fragment),le=n(),y=i("div"),y.innerHTML=ye,se=n(),p(G.$$.fragment),ne=n(),X=i("p"),this.h()},l(e){const t=je("svelte-u9bgzb",document.head);u=o(t,"META",{name:!0,content:!0}),t.forEach(l),z=a(e),S=o(e,"P",{}),be(S).forEach(l),I=a(e),r(b.$$.fragment,e),F=a(e),r(g.$$.fragment,e),H=a(e),r(U.$$.fragment,e),L=a(e),w=o(e,"P",{"data-svelte-h":!0}),d(w)!=="svelte-nm7oku"&&(w.innerHTML=pe),R=a(e),h=o(e,"P",{"data-svelte-h":!0}),d(h)!=="svelte-6ecc9h"&&(h.innerHTML=re),Y=a(e),_=o(e,"P",{"data-svelte-h":!0}),d(_)!=="svelte-1nfmd9t"&&(_.textContent=me),V=a(e),r(j.$$.fragment,e),E=a(e),v=o(e,"P",{"data-svelte-h":!0}),d(v)!=="svelte-1etucvv"&&(v.innerHTML=ce),P=a(e),r($.$$.fragment,e),N=a(e),T=o(e,"P",{"data-svelte-h":!0}),d(T)!=="svelte-5ws1w4"&&(T.innerHTML=fe),D=a(e),r(k.$$.fragment,e),K=a(e),C=o(e,"P",{"data-svelte-h":!0}),d(C)!=="svelte-rgvcdq"&&(C.textContent=Me),q=a(e),r(J.$$.fragment,e),A=a(e),W=o(e,"P",{"data-svelte-h":!0}),d(W)!=="svelte-g8ujvg"&&(W.innerHTML=ue),O=a(e),r(x.$$.fragment,e),ee=a(e),B=o(e,"P",{"data-svelte-h":!0}),d(B)!=="svelte-1fnsviy"&&(B.innerHTML=de),te=a(e),r(Z.$$.fragment,e),le=a(e),y=o(e,"DIV",{class:!0,"data-svelte-h":!0}),d(y)!=="svelte-1r5zq0s"&&(y.innerHTML=ye),se=a(e),r(G.$$.fragment,e),ne=a(e),X=o(e,"P",{}),be(X).forEach(l),this.h()},h(){ie(u,"name","hf:doc:metadata"),ie(u,"content",We),ie(y,"class","flex justify-center")},m(e,t){ve(document.head,u),s(e,z,t),s(e,S,t),s(e,I,t),m(b,e,t),s(e,F,t),m(g,e,t),s(e,H,t),m(U,e,t),s(e,L,t),s(e,w,t),s(e,R,t),s(e,h,t),s(e,Y,t),s(e,_,t),s(e,V,t),m(j,e,t),s(e,E,t),s(e,v,t),s(e,P,t),m($,e,t),s(e,N,t),s(e,T,t),s(e,D,t),m(k,e,t),s(e,K,t),s(e,C,t),s(e,q,t),m(J,e,t),s(e,A,t),s(e,W,t),s(e,O,t),m(x,e,t),s(e,ee,t),s(e,B,t),s(e,te,t),m(Z,e,t),s(e,le,t),s(e,y,t),s(e,se,t),m(G,e,t),s(e,ne,t),s(e,X,t),ae=!0},p:Ue,i(e){ae||(c(b.$$.fragment,e),c(g.$$.fragment,e),c(U.$$.fragment,e),c(j.$$.fragment,e),c($.$$.fragment,e),c(k.$$.fragment,e),c(J.$$.fragment,e),c(x.$$.fragment,e),c(Z.$$.fragment,e),c(G.$$.fragment,e),ae=!0)},o(e){f(b.$$.fragment,e),f(g.$$.fragment,e),f(U.$$.fragment,e),f(j.$$.fragment,e),f($.$$.fragment,e),f(k.$$.fragment,e),f(J.$$.fragment,e),f(x.$$.fragment,e),f(Z.$$.fragment,e),f(G.$$.fragment,e),ae=!1},d(e){e&&(l(z),l(S),l(I),l(F),l(H),l(L),l(w),l(R),l(h),l(Y),l(_),l(V),l(E),l(v),l(P),l(N),l(T),l(D),l(K),l(C),l(q),l(A),l(W),l(O),l(ee),l(B),l(te),l(le),l(y),l(se),l(ne),l(X)),l(u),M(b,e),M(g,e),M(U,e),M(j,e),M($,e),M(k,e),M(J,e),M(x,e),M(Z,e),M(G,e)}}}const We='{"title":"Textual inversion","local":"textual-inversion","sections":[],"depth":1}';function xe(oe){return we(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Xe extends he{constructor(u){super(),_e(this,u,xe,Je,ge,{})}}export{Xe as component};
