Buckets:
| import{s as we,n as be,o as ve}from"../chunks/scheduler.182ea377.js";import{S as ge,i as _e,g as l,s as i,p as V,A as Te,h as s,f as t,c as o,j as $,q as x,m,k as r,v as u,a,r as B,d as N,t as X,u as I}from"../chunks/index.008d68e4.js";import{I as ye}from"../chunks/IconCopyLink.96bbb92b.js";import{C as ne}from"../chunks/CodeBlock.5ed6eb7b.js";function Ze(ae){let d,Q,p,f,W,M,ee,C,le="Adapt a model to a new task",S,y,se="Many diffusion systems share the same components, allowing you to adapt a pretrained model for one task to an entirely different task.",R,w,ie='This guide will show you how to adapt a pretrained text-to-image model for inpainting by initializing and modifying the architecture of a pretrained <a href="/docs/diffusers/v0.25.0/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>.',E,c,h,G,b,te,J,oe="Configure UNet2DConditionModel parameters",A,v,re='A <a href="/docs/diffusers/v0.25.0/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a> by default accepts 4 channels in the <a href="https://huggingface.co/docs/diffusers/v0.16.0/en/api/models#diffusers.UNet2DConditionModel.in_channels" rel="nofollow">input sample</a>. For example, load a pretrained text-to-image model like <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow"><code>runwayml/stable-diffusion-v1-5</code></a> and take a look at the number of <code>in_channels</code>:',H,g,L,_,de='Inpainting requires 9 channels in the input sample. You can check this value in a pretrained inpainting model like <a href="https://huggingface.co/runwayml/stable-diffusion-inpainting" rel="nofollow"><code>runwayml/stable-diffusion-inpainting</code></a>:',P,T,D,Z,pe="To adapt your text-to-image model for inpainting, you’ll need to change the number of <code>in_channels</code> from 4 to 9.",z,U,ce='Initialize a <a href="/docs/diffusers/v0.25.0/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a> with the pretrained text-to-image model weights, and change <code>in_channels</code> to 9. Changing the number of <code>in_channels</code> means you need to set <code>ignore_mismatched_sizes=True</code> and <code>low_cpu_mem_usage=False</code> to avoid a size mismatch error because the shape is different now.',Y,k,F,j,me="The pretrained weights of the other components from the text-to-image model are initialized from their checkpoints, but the input channel weights (<code>conv_in.weight</code>) of the <code>unet</code> are randomly initialized. It is important to finetune the model for inpainting because otherwise the model returns noise.",q;return M=new ye({}),b=new ye({}),g=new ne({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGVsaW5lLnVuZXQuY29uZmlnJTVCJTIyaW5fY2hhbm5lbHMlMjIlNUQlMEE0",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline | |
| pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">"runwayml/stable-diffusion-v1-5"</span>, use_safetensors=<span class="hljs-literal">True</span>) | |
| pipeline.unet.config[<span class="hljs-string">"in_channels"</span>] | |
| <span class="hljs-number">4</span>`}}),T=new ne({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLWlucGFpbnRpbmclMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGVsaW5lLnVuZXQuY29uZmlnJTVCJTIyaW5fY2hhbm5lbHMlMjIlNUQlMEE5",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline | |
| pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">"runwayml/stable-diffusion-inpainting"</span>, use_safetensors=<span class="hljs-literal">True</span>) | |
| pipeline.unet.config[<span class="hljs-string">"in_channels"</span>] | |
| <span class="hljs-number">9</span>`}}),k=new ne({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFVOZXQyRENvbmRpdGlvbk1vZGVsJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXVuZXQlMjAlM0QlMjBVTmV0MkRDb25kaXRpb25Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfaWQlMkMlMEElMjAlMjAlMjAlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTBBJTIwJTIwJTIwJTIwaW5fY2hhbm5lbHMlM0Q5JTJDJTBBJTIwJTIwJTIwJTIwbG93X2NwdV9tZW1fdXNhZ2UlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGlnbm9yZV9taXNtYXRjaGVkX3NpemVzJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> UNet2DConditionModel | |
| model_id = <span class="hljs-string">"runwayml/stable-diffusion-v1-5"</span> | |
| unet = UNet2DConditionModel.from_pretrained( | |
| model_id, | |
| subfolder=<span class="hljs-string">"unet"</span>, | |
| in_channels=<span class="hljs-number">9</span>, | |
| low_cpu_mem_usage=<span class="hljs-literal">False</span>, | |
| ignore_mismatched_sizes=<span class="hljs-literal">True</span>, | |
| use_safetensors=<span class="hljs-literal">True</span>, | |
| )`}}),{c(){d=l("meta"),Q=i(),p=l("h1"),f=l("a"),W=l("span"),V(M.$$.fragment),ee=i(),C=l("span"),C.textContent=le,S=i(),y=l("p"),y.textContent=se,R=i(),w=l("p"),w.innerHTML=ie,E=i(),c=l("h2"),h=l("a"),G=l("span"),V(b.$$.fragment),te=i(),J=l("span"),J.textContent=oe,A=i(),v=l("p"),v.innerHTML=re,H=i(),V(g.$$.fragment),L=i(),_=l("p"),_.innerHTML=de,P=i(),V(T.$$.fragment),D=i(),Z=l("p"),Z.innerHTML=pe,z=i(),U=l("p"),U.innerHTML=ce,Y=i(),V(k.$$.fragment),F=i(),j=l("p"),j.innerHTML=me,this.h()},l(e){const n=Te("svelte-1phssyn",document.head);d=s(n,"META",{name:!0,content:!0}),n.forEach(t),Q=o(e),p=s(e,"H1",{class:!0});var K=$(p);f=s(K,"A",{id:!0,class:!0,href:!0});var ue=$(f);W=s(ue,"SPAN",{});var fe=$(W);x(M.$$.fragment,fe),fe.forEach(t),ue.forEach(t),ee=o(K),C=s(K,"SPAN",{"data-svelte-h":!0}),m(C)!=="svelte-1a5jey8"&&(C.textContent=le),K.forEach(t),S=o(e),y=s(e,"P",{"data-svelte-h":!0}),m(y)!=="svelte-3om45r"&&(y.textContent=se),R=o(e),w=s(e,"P",{"data-svelte-h":!0}),m(w)!=="svelte-1w33fsd"&&(w.innerHTML=ie),E=o(e),c=s(e,"H2",{class:!0});var O=$(c);h=s(O,"A",{id:!0,class:!0,href:!0});var he=$(h);G=s(he,"SPAN",{});var Me=$(G);x(b.$$.fragment,Me),Me.forEach(t),he.forEach(t),te=o(O),J=s(O,"SPAN",{"data-svelte-h":!0}),m(J)!=="svelte-1f4e8pt"&&(J.textContent=oe),O.forEach(t),A=o(e),v=s(e,"P",{"data-svelte-h":!0}),m(v)!=="svelte-1dr45f2"&&(v.innerHTML=re),H=o(e),x(g.$$.fragment,e),L=o(e),_=s(e,"P",{"data-svelte-h":!0}),m(_)!=="svelte-ph2jy1"&&(_.innerHTML=de),P=o(e),x(T.$$.fragment,e),D=o(e),Z=s(e,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-15mkgo9"&&(Z.innerHTML=pe),z=o(e),U=s(e,"P",{"data-svelte-h":!0}),m(U)!=="svelte-t2tvev"&&(U.innerHTML=ce),Y=o(e),x(k.$$.fragment,e),F=o(e),j=s(e,"P",{"data-svelte-h":!0}),m(j)!=="svelte-6j6lxu"&&(j.innerHTML=me),this.h()},h(){r(d,"name","hf:doc:metadata"),r(d,"content",JSON.stringify(Ue)),r(f,"id","adapt-a-model-to-a-new-task"),r(f,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),r(f,"href","#adapt-a-model-to-a-new-task"),r(p,"class","relative group"),r(h,"id","configure-unet2dconditionmodel-parameters"),r(h,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),r(h,"href","#configure-unet2dconditionmodel-parameters"),r(c,"class","relative group")},m(e,n){u(document.head,d),a(e,Q,n),a(e,p,n),u(p,f),u(f,W),B(M,W,null),u(p,ee),u(p,C),a(e,S,n),a(e,y,n),a(e,R,n),a(e,w,n),a(e,E,n),a(e,c,n),u(c,h),u(h,G),B(b,G,null),u(c,te),u(c,J),a(e,A,n),a(e,v,n),a(e,H,n),B(g,e,n),a(e,L,n),a(e,_,n),a(e,P,n),B(T,e,n),a(e,D,n),a(e,Z,n),a(e,z,n),a(e,U,n),a(e,Y,n),B(k,e,n),a(e,F,n),a(e,j,n),q=!0},p:be,i(e){q||(N(M.$$.fragment,e),N(b.$$.fragment,e),N(g.$$.fragment,e),N(T.$$.fragment,e),N(k.$$.fragment,e),q=!0)},o(e){X(M.$$.fragment,e),X(b.$$.fragment,e),X(g.$$.fragment,e),X(T.$$.fragment,e),X(k.$$.fragment,e),q=!1},d(e){e&&(t(Q),t(p),t(S),t(y),t(R),t(w),t(E),t(c),t(A),t(v),t(H),t(L),t(_),t(P),t(D),t(Z),t(z),t(U),t(Y),t(F),t(j)),t(d),I(M),I(b),I(g,e),I(T,e),I(k,e)}}}const Ue={local:"adapt-a-model-to-a-new-task",sections:[{local:"configure-unet2dconditionmodel-parameters",title:"Configure UNet2DConditionModel parameters"}],title:"Adapt a model to a new task"};function ke(ae){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class We extends ge{constructor(d){super(),_e(this,d,ke,Ze,we,{})}}export{We as component}; | |
Xet Storage Details
- Size:
- 8.89 kB
- Xet hash:
- 0a7e457bf0a2c199b297e7dec1df197a92b11117b2b5cf6b108f66b31b3d06f0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.