Buckets:

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

Xet Storage Details

Size:
10.6 kB
·
Xet hash:
5a4efb3299a8d4edc64f8ac4f6b88b2cd805c8255a49a08f94d376e810bf81cd

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