import{s as we,n as ye,o as Me}from"../chunks/scheduler.94020406.js";import{S as ge,i as Je,g as i,s as n,r,E as Te,h as o,f as s,c as a,j as be,u as m,x as c,k as ne,y as he,a as l,v as u,d as f,t as d,w as b}from"../chunks/index.a08c8d92.js";import{C as x}from"../chunks/CodeBlock.b23cf525.js";import{D as _e}from"../chunks/DocNotebookDropdown.d8a25975.js";import{H as Ue,E as je}from"../chunks/EditOnGithub.b1bceb47.js";function ve(ae){let p,Q,X,H,y,S,M,z,g,ie='<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>를 통해 빠르게 사용해볼 수 있습니다.',N,J,oe='이 가이드에서는 Stable Diffusion Conceptualizer에서 사전학습한 컨셉을 사용하여 textual-inversion으로 추론을 실행하는 방법을 보여드립니다. textual-inversion으로 모델에 새로운 컨셉을 학습시키는 데 관심이 있으시다면,  <a href="./training/text_inversion">Textual Inversion</a>  훈련 가이드를 참조하세요.',F,T,pe="Hugging Face 계정으로 로그인하세요:",E,h,Y,_,re="필요한 라이브러리를 불러오고 생성된 이미지를 시각화하기 위한 도우미 함수 <code>image_grid</code>를 만듭니다:",R,U,V,j,me='Stable Diffusion과 <a href="https://huggingface.co/spaces/sd-concepts-library/stable-diffusion-conceptualizer" rel="nofollow">Stable Diffusion Conceptualizer</a>에서 사전학습된 컨셉을 선택합니다:',L,v,P,B,ce="이제 파이프라인을 로드하고 사전학습된 컨셉을 파이프라인에 전달할 수 있습니다:",D,I,q,$,ue="특별한 placeholder token ’<code>&lt;cat-toy&gt;</code>‘를 사용하여 사전학습된 컨셉으로 프롬프트를 만들고, 생성할 샘플의 수와 이미지 행의 수를 선택합니다:",K,k,A,Z,fe="그런 다음 파이프라인을 실행하고, 생성된 이미지들을 저장합니다. 그리고 처음에 만들었던 도우미 함수 <code>image_grid</code>를 사용하여 생성 결과들을 시각화합니다. 이 때 <code>num_inference_steps</code>와 <code>guidance_scale</code>과 같은 매개 변수들을 조정하여, 이것들이 이미지 품질에 어떠한 영향을 미치는지를 자유롭게 확인해보시기 바랍니다.",O,W,ee,w,de='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/textual_inversion_inference.png"/>',te,C,se,G,le;return y=new Ue({props:{title:"Textual inversion",local:"textual-inversion",headingTag:"h1"}}),M=new _e({props:{classNames:"absolute z-10 right-0 top-0",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"}]}}),h=new x({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

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