Buckets:

hf-doc-build/doc / diffusers /main /en /_app /pages /using-diffusers /control_brightness.mdx-hf-doc-builder.js
rtrm's picture
download
raw
10.7 kB
import{S as Tt,i as jt,s as xt,e as o,k as u,w as ee,t as l,M as Dt,c as r,d as s,m as d,a as n,x as te,h as a,b as c,N as Ut,G as t,g as p,y as se,q as le,o as ae,B as oe,v as St}from"../../chunks/vendor-hf-doc-builder.js";import{T as kt}from"../../chunks/Tip-hf-doc-builder.js";import{I as It}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as at}from"../../chunks/CodeBlock-hf-doc-builder.js";function Zt(re){let h,b;return{c(){h=o("p"),b=l("\u{1F4A1} Take a look at the paper linked above for more details about the proposed solutions!")},l(m){h=r(m,"P",{});var _=n(h);b=a(_,"\u{1F4A1} Take a look at the paper linked above for more details about the proposed solutions!"),_.forEach(s)},m(m,_){p(m,h,_),t(h,b)},d(m){m&&s(h)}}}function Gt(re){let h,b,m,_,R,J,Me,F,Ee,ie,y,$e,T,Je,Te,G,je,xe,ne,w,pe,f,De,A,Ue,Se,z,ke,Ie,j,q,Ze,Ge,x,X,Ve,We,P,Be,Ne,ce,D,he,v,Ce,U,Y,Re,Fe,O,Ae,ze,fe,M,qe,V,Xe,Pe,me,E,W,Q,Ye,Oe,Qe,B,H,He,Le,ue,S,de,$,Ke,L,et,tt,_e,k,ge,I,K,ot,ye;return J=new It({}),w=new kt({props:{$$slots:{default:[Zt]},$$scope:{ctx:re}}}),D=new at({props:{code:"LS1wcmVkaWN0aW9uX3R5cGUlM0QlMjJ2X3ByZWRpY3Rpb24lMjI=",highlighted:'--prediction_type=<span class="hljs-string">&quot;v_prediction&quot;</span>'}}),S=new at({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTJDJTIwRERJTVNjaGVkdWxlciUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMnB0eDAlMkZwc2V1ZG8tam91cm5leS12MiUyMiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBJTBBcGlwZWxpbmUuc2NoZWR1bGVyJTIwJTNEJTIwRERJTVNjaGVkdWxlci5mcm9tX2NvbmZpZyglMEElMjAlMjAlMjAlMjBwaXBlbGluZS5zY2hlZHVsZXIuY29uZmlnJTJDJTIwcmVzY2FsZV9iZXRhc196ZXJvX3NuciUzRFRydWUlMkMlMjB0aW1lc3RlcF9zcGFjaW5nJTNEJTIydHJhaWxpbmclMjIlMEEpJTBBcGlwZWxpbmUudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline, DDIMScheduler
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;ptx0/pseudo-journey-v2&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
<span class="hljs-comment"># switch the scheduler in the pipeline to use the DDIMScheduler</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(
<span class="hljs-meta">... </span> pipeline.scheduler.config, rescale_betas_zero_snr=<span class="hljs-literal">True</span>, timestep_spacing=<span class="hljs-string">&quot;trailing&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),k=new at({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyQSUyMGxpb24lMjBpbiUyMGdhbGF4aWVzJTJDJTIwc3BpcmFscyUyQyUyMG5lYnVsYWUlMkMlMjBzdGFycyUyQyUyMHNtb2tlJTJDJTIwaXJpZGVzY2VudCUyQyUyMGludHJpY2F0ZSUyMGRldGFpbCUyQyUyMG9jdGFuZSUyMHJlbmRlciUyQyUyMDhrJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBndWlkYW5jZV9yZXNjYWxlJTNEMC43KS5pbWFnZXMlNUIwJTVE",highlighted:`prompt = <span class="hljs-string">&quot;A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k&quot;</span>
image = pipeline(prompt, guidance_rescale=<span class="hljs-number">0.7</span>).images[<span class="hljs-number">0</span>]`}}),{c(){h=o("meta"),b=u(),m=o("h1"),_=o("a"),R=o("span"),ee(J.$$.fragment),Me=u(),F=o("span"),Ee=l("Control image brightness"),ie=u(),y=o("p"),$e=l("The Stable Diffusion pipeline is mediocre at generating images that are either very bright or dark as explained in the "),T=o("a"),Je=l("Common Diffusion Noise Schedules and Sample Steps are Flawed"),Te=l(" paper. The solutions proposed in the paper are currently implemented in the "),G=o("a"),je=l("DDIMScheduler"),xe=l(" which you can use to improve the lighting in your images."),ne=u(),ee(w.$$.fragment),pe=u(),f=o("p"),De=l("One of the solutions is to train a model with "),A=o("em"),Ue=l("v prediction"),Se=l(" and "),z=o("em"),ke=l("v loss"),Ie=l(". Add the following flag to the "),j=o("a"),q=o("code"),Ze=l("train_text_to_image.py"),Ge=l(" or "),x=o("a"),X=o("code"),Ve=l("train_text_to_image_lora.py"),We=l(" scripts to enable "),P=o("code"),Be=l("v_prediction"),Ne=l(":"),ce=u(),ee(D.$$.fragment),he=u(),v=o("p"),Ce=l("For example, let\u2019s use the "),U=o("a"),Y=o("code"),Re=l("ptx0/pseudo-journey-v2"),Fe=l(" checkpoint which has been finetuned with "),O=o("code"),Ae=l("v_prediction"),ze=l("."),fe=u(),M=o("p"),qe=l("Next, configure the following parameters in the "),V=o("a"),Xe=l("DDIMScheduler"),Pe=l(":"),me=u(),E=o("ol"),W=o("li"),Q=o("code"),Ye=l("rescale_betas_zero_snr=True"),Oe=l(", rescales the noise schedule to zero terminal signal-to-noise ratio (SNR)"),Qe=u(),B=o("li"),H=o("code"),He=l('timestep_spacing="trailing"'),Le=l(", starts sampling from the last timestep"),ue=u(),ee(S.$$.fragment),de=u(),$=o("p"),Ke=l("Finally, in your call to the pipeline, set "),L=o("code"),et=l("guidance_rescale"),tt=l(" to prevent overexposure:"),_e=u(),ee(k.$$.fragment),ge=u(),I=o("div"),K=o("img"),this.h()},l(e){const i=Dt('[data-svelte="svelte-1phssyn"]',document.head);h=r(i,"META",{name:!0,content:!0}),i.forEach(s),b=d(e),m=r(e,"H1",{class:!0});var Z=n(m);_=r(Z,"A",{id:!0,class:!0,href:!0});var rt=n(_);R=r(rt,"SPAN",{});var it=n(R);te(J.$$.fragment,it),it.forEach(s),rt.forEach(s),Me=d(Z),F=r(Z,"SPAN",{});var nt=n(F);Ee=a(nt,"Control image brightness"),nt.forEach(s),Z.forEach(s),ie=d(e),y=r(e,"P",{});var N=n(y);$e=a(N,"The Stable Diffusion pipeline is mediocre at generating images that are either very bright or dark as explained in the "),T=r(N,"A",{href:!0,rel:!0});var pt=n(T);Je=a(pt,"Common Diffusion Noise Schedules and Sample Steps are Flawed"),pt.forEach(s),Te=a(N," paper. The solutions proposed in the paper are currently implemented in the "),G=r(N,"A",{href:!0});var ct=n(G);je=a(ct,"DDIMScheduler"),ct.forEach(s),xe=a(N," which you can use to improve the lighting in your images."),N.forEach(s),ne=d(e),te(w.$$.fragment,e),pe=d(e),f=r(e,"P",{});var g=n(f);De=a(g,"One of the solutions is to train a model with "),A=r(g,"EM",{});var ht=n(A);Ue=a(ht,"v prediction"),ht.forEach(s),Se=a(g," and "),z=r(g,"EM",{});var ft=n(z);ke=a(ft,"v loss"),ft.forEach(s),Ie=a(g,". Add the following flag to the "),j=r(g,"A",{href:!0,rel:!0});var mt=n(j);q=r(mt,"CODE",{});var ut=n(q);Ze=a(ut,"train_text_to_image.py"),ut.forEach(s),mt.forEach(s),Ge=a(g," or "),x=r(g,"A",{href:!0,rel:!0});var dt=n(x);X=r(dt,"CODE",{});var _t=n(X);Ve=a(_t,"train_text_to_image_lora.py"),_t.forEach(s),dt.forEach(s),We=a(g," scripts to enable "),P=r(g,"CODE",{});var gt=n(P);Be=a(gt,"v_prediction"),gt.forEach(s),Ne=a(g,":"),g.forEach(s),ce=d(e),te(D.$$.fragment,e),he=d(e),v=r(e,"P",{});var C=n(v);Ce=a(C,"For example, let\u2019s use the "),U=r(C,"A",{href:!0,rel:!0});var yt=n(U);Y=r(yt,"CODE",{});var vt=n(Y);Re=a(vt,"ptx0/pseudo-journey-v2"),vt.forEach(s),yt.forEach(s),Fe=a(C," checkpoint which has been finetuned with "),O=r(C,"CODE",{});var bt=n(O);Ae=a(bt,"v_prediction"),bt.forEach(s),ze=a(C,"."),C.forEach(s),fe=d(e),M=r(e,"P",{});var ve=n(M);qe=a(ve,"Next, configure the following parameters in the "),V=r(ve,"A",{href:!0});var wt=n(V);Xe=a(wt,"DDIMScheduler"),wt.forEach(s),Pe=a(ve,":"),ve.forEach(s),me=d(e),E=r(e,"OL",{});var be=n(E);W=r(be,"LI",{});var st=n(W);Q=r(st,"CODE",{});var Mt=n(Q);Ye=a(Mt,"rescale_betas_zero_snr=True"),Mt.forEach(s),Oe=a(st,", rescales the noise schedule to zero terminal signal-to-noise ratio (SNR)"),st.forEach(s),Qe=d(be),B=r(be,"LI",{});var lt=n(B);H=r(lt,"CODE",{});var Et=n(H);He=a(Et,'timestep_spacing="trailing"'),Et.forEach(s),Le=a(lt,", starts sampling from the last timestep"),lt.forEach(s),be.forEach(s),ue=d(e),te(S.$$.fragment,e),de=d(e),$=r(e,"P",{});var we=n($);Ke=a(we,"Finally, in your call to the pipeline, set "),L=r(we,"CODE",{});var $t=n(L);et=a($t,"guidance_rescale"),$t.forEach(s),tt=a(we," to prevent overexposure:"),we.forEach(s),_e=d(e),te(k.$$.fragment,e),ge=d(e),I=r(e,"DIV",{class:!0});var Jt=n(I);K=r(Jt,"IMG",{src:!0}),Jt.forEach(s),this.h()},h(){c(h,"name","hf:doc:metadata"),c(h,"content",JSON.stringify(Vt)),c(_,"id","control-image-brightness"),c(_,"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"),c(_,"href","#control-image-brightness"),c(m,"class","relative group"),c(T,"href","https://huggingface.co/papers/2305.08891"),c(T,"rel","nofollow"),c(G,"href","/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler"),c(j,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image.py"),c(j,"rel","nofollow"),c(x,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py"),c(x,"rel","nofollow"),c(U,"href","https://huggingface.co/ptx0/pseudo-journey-v2"),c(U,"rel","nofollow"),c(V,"href","/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler"),Ut(K.src,ot="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/zero_snr.png")||c(K,"src",ot),c(I,"class","flex justify-center")},m(e,i){t(document.head,h),p(e,b,i),p(e,m,i),t(m,_),t(_,R),se(J,R,null),t(m,Me),t(m,F),t(F,Ee),p(e,ie,i),p(e,y,i),t(y,$e),t(y,T),t(T,Je),t(y,Te),t(y,G),t(G,je),t(y,xe),p(e,ne,i),se(w,e,i),p(e,pe,i),p(e,f,i),t(f,De),t(f,A),t(A,Ue),t(f,Se),t(f,z),t(z,ke),t(f,Ie),t(f,j),t(j,q),t(q,Ze),t(f,Ge),t(f,x),t(x,X),t(X,Ve),t(f,We),t(f,P),t(P,Be),t(f,Ne),p(e,ce,i),se(D,e,i),p(e,he,i),p(e,v,i),t(v,Ce),t(v,U),t(U,Y),t(Y,Re),t(v,Fe),t(v,O),t(O,Ae),t(v,ze),p(e,fe,i),p(e,M,i),t(M,qe),t(M,V),t(V,Xe),t(M,Pe),p(e,me,i),p(e,E,i),t(E,W),t(W,Q),t(Q,Ye),t(W,Oe),t(E,Qe),t(E,B),t(B,H),t(H,He),t(B,Le),p(e,ue,i),se(S,e,i),p(e,de,i),p(e,$,i),t($,Ke),t($,L),t(L,et),t($,tt),p(e,_e,i),se(k,e,i),p(e,ge,i),p(e,I,i),t(I,K),ye=!0},p(e,[i]){const Z={};i&2&&(Z.$$scope={dirty:i,ctx:e}),w.$set(Z)},i(e){ye||(le(J.$$.fragment,e),le(w.$$.fragment,e),le(D.$$.fragment,e),le(S.$$.fragment,e),le(k.$$.fragment,e),ye=!0)},o(e){ae(J.$$.fragment,e),ae(w.$$.fragment,e),ae(D.$$.fragment,e),ae(S.$$.fragment,e),ae(k.$$.fragment,e),ye=!1},d(e){s(h),e&&s(b),e&&s(m),oe(J),e&&s(ie),e&&s(y),e&&s(ne),oe(w,e),e&&s(pe),e&&s(f),e&&s(ce),oe(D,e),e&&s(he),e&&s(v),e&&s(fe),e&&s(M),e&&s(me),e&&s(E),e&&s(ue),oe(S,e),e&&s(de),e&&s($),e&&s(_e),oe(k,e),e&&s(ge),e&&s(I)}}}const Vt={local:"control-image-brightness",title:"Control image brightness"};function Wt(re){return St(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ft extends Tt{constructor(h){super();jt(this,h,Wt,Gt,xt,{})}}export{Ft as default,Vt as metadata};

Xet Storage Details

Size:
10.7 kB
·
Xet hash:
4739c0d664ab6241fd7c2b7964d7dec5ab73e128951f48a4db25900c21d59e1c

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.