import{s as ee,o as se,n as le}from"../chunks/scheduler.9bc65507.js";import{S as ae,i as ne,g as p,s as a,r,A as pe,h as i,f as s,c as n,j as te,u as c,x as m,k as O,y as ie,a as l,v as g,d as f,t as h,w as u}from"../chunks/index.707bf1b6.js";import{T as me}from"../chunks/Tip.c2ecdbf4.js";import{C as M}from"../chunks/CodeBlock.54a9f38d.js";import{H as Gt,E as oe}from"../chunks/EditOnGithub.922df6ba.js";function re(tt){let o,b='このタスクと互換性のあるすべてのアーキテクチャとチェックポイントを確認するには、<a href="https://huggingface.co/tasks/depth-estimation" rel="nofollow">タスクページ</a> を確認することをお勧めします。';return{c(){o=p("p"),o.innerHTML=b},l(d){o=i(d,"P",{"data-svelte-h":!0}),m(o)!=="svelte-16h0jqp"&&(o.innerHTML=b)},m(d,D){l(d,o,D)},p:le,d(d){d&&s(o)}}}function ce(tt){let o,b,d,D,J,et,U,Bt=`単眼奥行き推定は、シーンの奥行き情報を画像から予測することを含むコンピューター ビジョン タスクです。
単一の画像。言い換えれば、シーン内のオブジェクトの距離を距離から推定するプロセスです。
単一カメラの視点。`,st,v,Ht=`単眼奥行き推定には、3D 再構築、拡張現実、自動運転、
そしてロボット工学。モデルがオブジェクト間の複雑な関係を理解する必要があるため、これは困難な作業です。
シーンとそれに対応する深度情報（照明条件などの要因の影響を受ける可能性があります）
オクルージョンとテクスチャ。`,lt,y,at,T,It="このガイドでは、次の方法を学びます。",nt,C,Et="<li>深度推定パイプラインを作成する</li> <li>手動で深度推定推論を実行します</li>",pt,Z,Vt="始める前に、必要なライブラリがすべてインストールされていることを確認してください。",it,x,mt,k,ot,W,zt=`深度推定をサポートするモデルで推論を試す最も簡単な方法は、対応する <a href="/docs/transformers/pr_31172/ja/main_classes/pipelines#transformers.pipeline">pipeline()</a> を使用することです。
<a href="https://huggingface.co/models?pipeline_tag=Depth-estimation&amp;sort=downloads" rel="nofollow">Hugging Face Hub のチェックポイント</a> からパイプラインをインスタンス化します。`,rt,R,ct,_,Xt="次に、分析する画像を選択します。",gt,G,ft,$,Nt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-estimation-example.jpg" alt="Photo of a busy street"/>',ht,B,Qt="画像をパイプラインに渡します。",ut,H,dt,I,Ft=`パイプラインは 2 つのエントリを含む辞書を返します。最初のものは<code>predicted_ Depth</code>と呼ばれ、次の値を持つテンソルです。
深さは各ピクセルのメートル単位で表されます。
2 番目の<code>depth</code>は、深度推定結果を視覚化する PIL 画像です。`,Mt,E,Yt="視覚化された結果を見てみましょう。",yt,V,$t,w,St='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-visualization.png" alt="Depth estimation visualization"/>',wt,z,jt,X,Lt="深度推定パイプラインの使用方法を理解したので、同じ結果を手動で複製する方法を見てみましょう。",bt,N,qt=`まず、<a href="https://huggingface.co/models?pipeline_tag=Depth-estimation&amp;sort=downloads" rel="nofollow">Hugging Face Hub のチェックポイント</a> からモデルと関連プロセッサをロードします。
ここでは、前と同じチェックポイントを使用します。`,Jt,Q,Ut,F,At=`必要な画像変換を処理する<code>image_processor</code>を使用して、モデルの画像入力を準備します。
サイズ変更や正規化など:`,vt,Y,Tt,S,Pt="準備された入力をモデルに渡します。",Ct,L,Zt,q,Dt="結果を視覚化します。",xt,A,kt,j,Kt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-visualization.png" alt="Depth estimation visualization"/>',Wt,P,Rt,K,_t;return J=new Gt({props:{title:"Monocular depth estimation",local:"monocular-depth-estimation",headingTag:"h1"}}),y=new me({props:{$$slots:{default:[re]},$$scope:{ctx:tt}}}),x=new M({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwdHJhbnNmb3JtZXJz",highlighted:"pip install -q transformers",wrap:!1}}),k=new Gt({props:{title:"Depth estimation pipeline",local:"depth-estimation-pipeline",headingTag:"h2"}}),R=new M({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBY2hlY2twb2ludCUyMCUzRCUyMCUyMnZpbnZpbm8wMiUyRmdscG4tbnl1JTIyJTBBZGVwdGhfZXN0aW1hdG9yJTIwJTNEJTIwcGlwZWxpbmUoJTIyZGVwdGgtZXN0aW1hdGlvbiUyMiUyQyUyMG1vZGVsJTNEY2hlY2twb2ludCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;vinvino02/glpn-nyu&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>depth_estimator = pipeline(<span class="hljs-string">&quot;depth-estimation&quot;</span>, model=checkpoint)`,wrap:!1}}),G=new M({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRnVuc3BsYXNoLmNvbSUyRnBob3RvcyUyRkh3QkFzU2JQQkRVJTJGZG93bmxvYWQlM0ZpeGlkJTNETW53eE1qQTNmREI4TVh4elpXRnlZMmg4TXpSOGZHTmhjaVV5TUdsdUpUSXdkR2hsSlRJd2MzUnlaV1YwZkdWdWZEQjhNSHg4ZkRFMk56ZzVNREV3T0RnJTI2Zm9yY2UlM0R0cnVlJTI2dyUzRDY0MCUyMiUwQWltYWdlJTIwJTNEJTIwSW1hZ2Uub3BlbihyZXF1ZXN0cy5nZXQodXJsJTJDJTIwc3RyZWFtJTNEVHJ1ZSkucmF3KSUwQWltYWdl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://unsplash.com/photos/HwBAsSbPBDU/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8MzR8fGNhciUyMGluJTIwdGhlJTIwc3RyZWV0fGVufDB8MHx8fDE2Nzg5MDEwODg&amp;force=true&amp;w=640&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
<span class="hljs-meta">&gt;&gt;&gt; </span>image`,wrap:!1}}),H=new M({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjBkZXB0aF9lc3RpbWF0b3IoaW1hZ2Up",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>predictions = depth_estimator(image)',wrap:!1}}),V=new M({props:{code:"cHJlZGljdGlvbnMlNUIlMjJkZXB0aCUyMiU1RA==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>predictions[<span class="hljs-string">&quot;depth&quot;</span>]',wrap:!1}}),z=new Gt({props:{title:"Depth estimation inference by hand",local:"depth-estimation-inference-by-hand",headingTag:"h2"}}),Q=new M({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMEF1dG9Nb2RlbEZvckRlcHRoRXN0aW1hdGlvbiUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJ2aW52aW5vMDIlMkZnbHBuLW55dSUyMiUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckRlcHRoRXN0aW1hdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoModelForDepthEstimation

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;vinvino02/glpn-nyu&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForDepthEstimation.from_pretrained(checkpoint)`,wrap:!1}}),Y=new M({props:{code:"cGl4ZWxfdmFsdWVzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikucGl4ZWxfdmFsdWVz",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values',wrap:!1}}),L=new M({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKHBpeGVsX3ZhbHVlcyklMEElMjAlMjAlMjAlMjBwcmVkaWN0ZWRfZGVwdGglMjAlM0QlMjBvdXRwdXRzLnByZWRpY3RlZF9kZXB0aA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(pixel_values)
<span class="hljs-meta">... </span>    predicted_depth = outputs.predicted_depth`,wrap:!1}}),A=new M({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTIzJTIwaW50ZXJwb2xhdGUlMjB0byUyMG9yaWdpbmFsJTIwc2l6ZSUwQXByZWRpY3Rpb24lMjAlM0QlMjB0b3JjaC5ubi5mdW5jdGlvbmFsLmludGVycG9sYXRlKCUwQSUyMCUyMCUyMCUyMHByZWRpY3RlZF9kZXB0aC51bnNxdWVlemUoMSklMkMlMEElMjAlMjAlMjAlMjBzaXplJTNEaW1hZ2Uuc2l6ZSU1QiUzQSUzQS0xJTVEJTJDJTBBJTIwJTIwJTIwJTIwbW9kZSUzRCUyMmJpY3ViaWMlMjIlMkMlMEElMjAlMjAlMjAlMjBhbGlnbl9jb3JuZXJzJTNERmFsc2UlMkMlMEEpLnNxdWVlemUoKSUwQW91dHB1dCUyMCUzRCUyMHByZWRpY3Rpb24ubnVtcHkoKSUwQSUwQWZvcm1hdHRlZCUyMCUzRCUyMChvdXRwdXQlMjAqJTIwMjU1JTIwJTJGJTIwbnAubWF4KG91dHB1dCkpLmFzdHlwZSglMjJ1aW50OCUyMiklMEFkZXB0aCUyMCUzRCUyMEltYWdlLmZyb21hcnJheShmb3JtYXR0ZWQpJTBBZGVwdGg=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># interpolate to original size</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>prediction = torch.nn.functional.interpolate(
<span class="hljs-meta">... </span>    predicted_depth.unsqueeze(<span class="hljs-number">1</span>),
<span class="hljs-meta">... </span>    size=image.size[::-<span class="hljs-number">1</span>],
<span class="hljs-meta">... </span>    mode=<span class="hljs-string">&quot;bicubic&quot;</span>,
<span class="hljs-meta">... </span>    align_corners=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>).squeeze()
<span class="hljs-meta">&gt;&gt;&gt; </span>output = prediction.numpy()

<span class="hljs-meta">&gt;&gt;&gt; </span>formatted = (output * <span class="hljs-number">255</span> / np.<span class="hljs-built_in">max</span>(output)).astype(<span class="hljs-string">&quot;uint8&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>depth = Image.fromarray(formatted)
<span class="hljs-meta">&gt;&gt;&gt; </span>depth`,wrap:!1}}),P=new oe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ja/tasks/monocular_depth_estimation.md"}}),{c(){o=p("meta"),b=a(),d=p("p"),D=a(),r(J.$$.fragment),et=a(),U=p("p"),U.textContent=Bt,st=a(),v=p("p"),v.textContent=Ht,lt=a(),r(y.$$.fragment),at=a(),T=p("p"),T.textContent=It,nt=a(),C=p("ul"),C.innerHTML=Et,pt=a(),Z=p("p"),Z.textContent=Vt,it=a(),r(x.$$.fragment),mt=a(),r(k.$$.fragment),ot=a(),W=p("p"),W.innerHTML=zt,rt=a(),r(R.$$.fragment),ct=a(),_=p("p"),_.textContent=Xt,gt=a(),r(G.$$.fragment),ft=a(),$=p("div"),$.innerHTML=Nt,ht=a(),B=p("p"),B.textContent=Qt,ut=a(),r(H.$$.fragment),dt=a(),I=p("p"),I.innerHTML=Ft,Mt=a(),E=p("p"),E.textContent=Yt,yt=a(),r(V.$$.fragment),$t=a(),w=p("div"),w.innerHTML=St,wt=a(),r(z.$$.fragment),jt=a(),X=p("p"),X.textContent=Lt,bt=a(),N=p("p"),N.innerHTML=qt,Jt=a(),r(Q.$$.fragment),Ut=a(),F=p("p"),F.innerHTML=At,vt=a(),r(Y.$$.fragment),Tt=a(),S=p("p"),S.textContent=Pt,Ct=a(),r(L.$$.fragment),Zt=a(),q=p("p"),q.textContent=Dt,xt=a(),r(A.$$.fragment),kt=a(),j=p("div"),j.innerHTML=Kt,Wt=a(),r(P.$$.fragment),Rt=a(),K=p("p"),this.h()},l(t){const e=pe("svelte-u9bgzb",document.head);o=i(e,"META",{name:!0,content:!0}),e.forEach(s),b=n(t),d=i(t,"P",{}),te(d).forEach(s),D=n(t),c(J.$$.fragment,t),et=n(t),U=i(t,"P",{"data-svelte-h":!0}),m(U)!=="svelte-9fs1p5"&&(U.textContent=Bt),st=n(t),v=i(t,"P",{"data-svelte-h":!0}),m(v)!=="svelte-1tgyug5"&&(v.textContent=Ht),lt=n(t),c(y.$$.fragment,t),at=n(t),T=i(t,"P",{"data-svelte-h":!0}),m(T)!=="svelte-tlz6vm"&&(T.textContent=It),nt=n(t),C=i(t,"UL",{"data-svelte-h":!0}),m(C)!=="svelte-1gu43po"&&(C.innerHTML=Et),pt=n(t),Z=i(t,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-1lya3k8"&&(Z.textContent=Vt),it=n(t),c(x.$$.fragment,t),mt=n(t),c(k.$$.fragment,t),ot=n(t),W=i(t,"P",{"data-svelte-h":!0}),m(W)!=="svelte-kkdoco"&&(W.innerHTML=zt),rt=n(t),c(R.$$.fragment,t),ct=n(t),_=i(t,"P",{"data-svelte-h":!0}),m(_)!=="svelte-1n3gtfx"&&(_.textContent=Xt),gt=n(t),c(G.$$.fragment,t),ft=n(t),$=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m($)!=="svelte-10bakl"&&($.innerHTML=Nt),ht=n(t),B=i(t,"P",{"data-svelte-h":!0}),m(B)!=="svelte-vb0w5q"&&(B.textContent=Qt),ut=n(t),c(H.$$.fragment,t),dt=n(t),I=i(t,"P",{"data-svelte-h":!0}),m(I)!=="svelte-1s2udfg"&&(I.innerHTML=Ft),Mt=n(t),E=i(t,"P",{"data-svelte-h":!0}),m(E)!=="svelte-x30tw4"&&(E.textContent=Yt),yt=n(t),c(V.$$.fragment,t),$t=n(t),w=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m(w)!=="svelte-43wxxb"&&(w.innerHTML=St),wt=n(t),c(z.$$.fragment,t),jt=n(t),X=i(t,"P",{"data-svelte-h":!0}),m(X)!=="svelte-1nhrkgu"&&(X.textContent=Lt),bt=n(t),N=i(t,"P",{"data-svelte-h":!0}),m(N)!=="svelte-1q9460k"&&(N.innerHTML=qt),Jt=n(t),c(Q.$$.fragment,t),Ut=n(t),F=i(t,"P",{"data-svelte-h":!0}),m(F)!=="svelte-povovq"&&(F.innerHTML=At),vt=n(t),c(Y.$$.fragment,t),Tt=n(t),S=i(t,"P",{"data-svelte-h":!0}),m(S)!=="svelte-1u18nel"&&(S.textContent=Pt),Ct=n(t),c(L.$$.fragment,t),Zt=n(t),q=i(t,"P",{"data-svelte-h":!0}),m(q)!=="svelte-8h8zfm"&&(q.textContent=Dt),xt=n(t),c(A.$$.fragment,t),kt=n(t),j=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m(j)!=="svelte-43wxxb"&&(j.innerHTML=Kt),Wt=n(t),c(P.$$.fragment,t),Rt=n(t),K=i(t,"P",{}),te(K).forEach(s),this.h()},h(){O(o,"name","hf:doc:metadata"),O(o,"content",ge),O($,"class","flex justify-center"),O(w,"class","flex justify-center"),O(j,"class","flex justify-center")},m(t,e){ie(document.head,o),l(t,b,e),l(t,d,e),l(t,D,e),g(J,t,e),l(t,et,e),l(t,U,e),l(t,st,e),l(t,v,e),l(t,lt,e),g(y,t,e),l(t,at,e),l(t,T,e),l(t,nt,e),l(t,C,e),l(t,pt,e),l(t,Z,e),l(t,it,e),g(x,t,e),l(t,mt,e),g(k,t,e),l(t,ot,e),l(t,W,e),l(t,rt,e),g(R,t,e),l(t,ct,e),l(t,_,e),l(t,gt,e),g(G,t,e),l(t,ft,e),l(t,$,e),l(t,ht,e),l(t,B,e),l(t,ut,e),g(H,t,e),l(t,dt,e),l(t,I,e),l(t,Mt,e),l(t,E,e),l(t,yt,e),g(V,t,e),l(t,$t,e),l(t,w,e),l(t,wt,e),g(z,t,e),l(t,jt,e),l(t,X,e),l(t,bt,e),l(t,N,e),l(t,Jt,e),g(Q,t,e),l(t,Ut,e),l(t,F,e),l(t,vt,e),g(Y,t,e),l(t,Tt,e),l(t,S,e),l(t,Ct,e),g(L,t,e),l(t,Zt,e),l(t,q,e),l(t,xt,e),g(A,t,e),l(t,kt,e),l(t,j,e),l(t,Wt,e),g(P,t,e),l(t,Rt,e),l(t,K,e),_t=!0},p(t,[e]){const Ot={};e&2&&(Ot.$$scope={dirty:e,ctx:t}),y.$set(Ot)},i(t){_t||(f(J.$$.fragment,t),f(y.$$.fragment,t),f(x.$$.fragment,t),f(k.$$.fragment,t),f(R.$$.fragment,t),f(G.$$.fragment,t),f(H.$$.fragment,t),f(V.$$.fragment,t),f(z.$$.fragment,t),f(Q.$$.fragment,t),f(Y.$$.fragment,t),f(L.$$.fragment,t),f(A.$$.fragment,t),f(P.$$.fragment,t),_t=!0)},o(t){h(J.$$.fragment,t),h(y.$$.fragment,t),h(x.$$.fragment,t),h(k.$$.fragment,t),h(R.$$.fragment,t),h(G.$$.fragment,t),h(H.$$.fragment,t),h(V.$$.fragment,t),h(z.$$.fragment,t),h(Q.$$.fragment,t),h(Y.$$.fragment,t),h(L.$$.fragment,t),h(A.$$.fragment,t),h(P.$$.fragment,t),_t=!1},d(t){t&&(s(b),s(d),s(D),s(et),s(U),s(st),s(v),s(lt),s(at),s(T),s(nt),s(C),s(pt),s(Z),s(it),s(mt),s(ot),s(W),s(rt),s(ct),s(_),s(gt),s(ft),s($),s(ht),s(B),s(ut),s(dt),s(I),s(Mt),s(E),s(yt),s($t),s(w),s(wt),s(jt),s(X),s(bt),s(N),s(Jt),s(Ut),s(F),s(vt),s(Tt),s(S),s(Ct),s(Zt),s(q),s(xt),s(kt),s(j),s(Wt),s(Rt),s(K)),s(o),u(J,t),u(y,t),u(x,t),u(k,t),u(R,t),u(G,t),u(H,t),u(V,t),u(z,t),u(Q,t),u(Y,t),u(L,t),u(A,t),u(P,t)}}}const ge='{"title":"Monocular depth estimation","local":"monocular-depth-estimation","sections":[{"title":"Depth estimation pipeline","local":"depth-estimation-pipeline","sections":[],"depth":2},{"title":"Depth estimation inference by hand","local":"depth-estimation-inference-by-hand","sections":[],"depth":2}],"depth":1}';function fe(tt){return se(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $e extends ae{constructor(o){super(),ne(this,o,fe,ce,ee,{})}}export{$e as component};
