import{s as Kt,o as Ot,n as te}from"../chunks/scheduler.56730f09.js";import{S as ee,i as se,g as p,s as a,r as c,A as le,h as i,f as s,c as n,j as Dt,u as g,x as m,k as K,y as ae,a as l,v as r,d as u,t as f,w as d}from"../chunks/index.1f144517.js";import{T as ne}from"../chunks/Tip.41e845e5.js";import{C as y}from"../chunks/CodeBlock.738eeccb.js";import{H as Gt,E as pe}from"../chunks/EditOnGithub.854793f1.js";function ie(O){let o,T='이 작업과 호환되는 모든 아키텍처와 체크포인트를 보려면 <a href="https://huggingface.co/tasks/depth-estimation" rel="nofollow">작업 페이지</a>를 확인하는 것이 좋습니다.';return{c(){o=p("p"),o.innerHTML=T},l(h){o=i(h,"P",{"data-svelte-h":!0}),m(o)!=="svelte-e4qzyu"&&(o.innerHTML=T)},m(h,A){l(h,o,A)},p:te,d(h){h&&s(o)}}}function me(O){let o,T,h,A,U,tt,j,_t=`단일 영상 기반 깊이 추정은 한 장면의 단일 이미지에서 장면의 깊이 정보를 예측하는 컴퓨터 비전 작업입니다.
즉, 단일 카메라 시점의 장면에 있는 물체의 거리를 예측하는 과정입니다.`,et,b,It=`단일 영상 기반 깊이 추정은 3D 재구성, 증강 현실, 자율 주행, 로봇 공학 등 다양한 분야에서 응용됩니다.
조명 조건, 가려짐, 텍스처와 같은 요소의 영향을 받을 수 있는 장면 내 물체와 해당 깊이 정보 간의 복잡한 관계를 모델이 이해해야 하므로 까다로운 작업입니다.`,st,J,lt,v,Bt="이번 가이드에서 배울 내용은 다음과 같습니다:",at,C,Rt="<li>깊이 추정 파이프라인 만들기</li> <li>직접 깊이 추정 추론하기</li>",nt,Z,Vt="시작하기 전에, 필요한 모든 라이브러리가 설치되어 있는지 확인하세요:",pt,k,it,x,mt,W,Ht=`깊이 추정을 추론하는 가장 간단한 방법은 해당 기능을 제공하는 <code>pipeline()</code>을 사용하는 것입니다.
<a href="https://huggingface.co/models?pipeline_tag=depth-estimation&amp;sort=downloads" rel="nofollow">Hugging Face Hub 체크포인트</a>에서 파이프라인을 초기화합니다:`,ot,G,ct,_,Et="다음으로, 분석할 이미지를 한 장 선택하세요:",gt,I,rt,w,Nt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-estimation-example.jpg" alt="Photo of a busy street"/>',ut,B,zt="이미지를 파이프라인으로 전달합니다.",ft,R,dt,V,Ft=`파이프라인은 두 개의 항목을 가지는 딕셔너리를 반환합니다.
첫 번째는 <code>predicted_depth</code>로 각 픽셀의 깊이를 미터로 표현한 값을 가지는 텐서입니다.
두 번째는 <code>depth</code>로 깊이 추정 결과를 시각화하는 PIL 이미지입니다.`,ht,H,Xt="이제 시각화한 결과를 살펴보겠습니다:",yt,E,Jt,M,Yt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-visualization.png" alt="Depth estimation visualization"/>',wt,N,Mt,z,Qt=`이제 깊이 추정 파이프라인 사용법을 살펴보았으니 동일한 결과를 복제하는 방법을 살펴보겠습니다.
<a href="https://huggingface.co/models?pipeline_tag=depth-estimation&amp;sort=downloads" rel="nofollow">Hugging Face Hub 체크포인트</a>에서 모델과 관련 프로세서를 가져오는 것부터 시작합니다.
여기서 이전에 사용한 체크포인트와 동일한 것을 사용합니다:`,$t,F,Tt,X,St=`필요한 이미지 변환을 처리하는 <code>image_processor</code>를 사용하여 모델에 대한 이미지 입력을 준비합니다.
<code>image_processor</code>는 크기 조정 및 정규화 등 필요한 이미지 변환을 처리합니다:`,Ut,Y,jt,Q,Lt="준비한 입력을 모델로 전달합니다:",bt,S,vt,L,qt="결과를 시각화합니다:",Ct,q,Zt,$,Pt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/depth-visualization.png" alt="Depth estimation visualization"/>',kt,P,xt,D,Wt;return U=new Gt({props:{title:"단일 영상 기반 깊이 추정",local:"depth-estimation-pipeline",headingTag:"h1"}}),J=new ne({props:{$$slots:{default:[ie]},$$scope:{ctx:O}}}),k=new y({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwdHJhbnNmb3JtZXJz",highlighted:"pip install -q transformers",wrap:!1}}),x=new Gt({props:{title:"깊이 추정 파이프라인",local:"depth-estimation-inference-by-hand",headingTag:"h2"}}),G=new y({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}}),I=new y({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}}),R=new y({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjBkZXB0aF9lc3RpbWF0b3IoaW1hZ2Up",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>predictions = depth_estimator(image)',wrap:!1}}),E=new y({props:{code:"cHJlZGljdGlvbnMlNUIlMjJkZXB0aCUyMiU1RA==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>predictions[<span class="hljs-string">&quot;depth&quot;</span>]',wrap:!1}}),N=new Gt({props:{title:"직접 깊이 추정 추론하기",local:"depth-estimation-inference-by-hand",headingTag:"h2"}}),F=new y({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 y({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}}),S=new y({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}}),q=new y({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTIzJTIwJUVDJTlCJTkwJUVCJUIzJUI4JTIwJUVDJTgyJUFDJUVDJTlEJUI0JUVDJUE2JTg4JUVCJUExJTlDJTIwJUVCJUIzJUI1JUVDJTlCJTkwJTBBcHJlZGljdGlvbiUyMCUzRCUyMHRvcmNoLm5uLmZ1bmN0aW9uYWwuaW50ZXJwb2xhdGUoJTBBJTIwJTIwJTIwJTIwcHJlZGljdGVkX2RlcHRoLnVuc3F1ZWV6ZSgxKSUyQyUwQSUyMCUyMCUyMCUyMHNpemUlM0RpbWFnZS5zaXplJTVCJTNBJTNBLTElNUQlMkMlMEElMjAlMjAlMjAlMjBtb2RlJTNEJTIyYmljdWJpYyUyMiUyQyUwQSUyMCUyMCUyMCUyMGFsaWduX2Nvcm5lcnMlM0RGYWxzZSUyQyUwQSkuc3F1ZWV6ZSgpJTBBb3V0cHV0JTIwJTNEJTIwcHJlZGljdGlvbi5udW1weSgpJTBBJTBBZm9ybWF0dGVkJTIwJTNEJTIwKG91dHB1dCUyMColMjAyNTUlMjAlMkYlMjBucC5tYXgob3V0cHV0KSkuYXN0eXBlKCUyMnVpbnQ4JTIyKSUwQWRlcHRoJTIwJTNEJTIwSW1hZ2UuZnJvbWFycmF5KGZvcm1hdHRlZCklMEFkZXB0aA==",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"># 원본 사이즈로 복원</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 pe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/tasks/monocular_depth_estimation.md"}}),{c(){o=p("meta"),T=a(),h=p("p"),A=a(),c(U.$$.fragment),tt=a(),j=p("p"),j.textContent=_t,et=a(),b=p("p"),b.textContent=It,st=a(),c(J.$$.fragment),lt=a(),v=p("p"),v.textContent=Bt,at=a(),C=p("ul"),C.innerHTML=Rt,nt=a(),Z=p("p"),Z.textContent=Vt,pt=a(),c(k.$$.fragment),it=a(),c(x.$$.fragment),mt=a(),W=p("p"),W.innerHTML=Ht,ot=a(),c(G.$$.fragment),ct=a(),_=p("p"),_.textContent=Et,gt=a(),c(I.$$.fragment),rt=a(),w=p("div"),w.innerHTML=Nt,ut=a(),B=p("p"),B.textContent=zt,ft=a(),c(R.$$.fragment),dt=a(),V=p("p"),V.innerHTML=Ft,ht=a(),H=p("p"),H.textContent=Xt,yt=a(),c(E.$$.fragment),Jt=a(),M=p("div"),M.innerHTML=Yt,wt=a(),c(N.$$.fragment),Mt=a(),z=p("p"),z.innerHTML=Qt,$t=a(),c(F.$$.fragment),Tt=a(),X=p("p"),X.innerHTML=St,Ut=a(),c(Y.$$.fragment),jt=a(),Q=p("p"),Q.textContent=Lt,bt=a(),c(S.$$.fragment),vt=a(),L=p("p"),L.textContent=qt,Ct=a(),c(q.$$.fragment),Zt=a(),$=p("div"),$.innerHTML=Pt,kt=a(),c(P.$$.fragment),xt=a(),D=p("p"),this.h()},l(t){const e=le("svelte-u9bgzb",document.head);o=i(e,"META",{name:!0,content:!0}),e.forEach(s),T=n(t),h=i(t,"P",{}),Dt(h).forEach(s),A=n(t),g(U.$$.fragment,t),tt=n(t),j=i(t,"P",{"data-svelte-h":!0}),m(j)!=="svelte-18h62fn"&&(j.textContent=_t),et=n(t),b=i(t,"P",{"data-svelte-h":!0}),m(b)!=="svelte-jyvqzi"&&(b.textContent=It),st=n(t),g(J.$$.fragment,t),lt=n(t),v=i(t,"P",{"data-svelte-h":!0}),m(v)!=="svelte-pdyjx9"&&(v.textContent=Bt),at=n(t),C=i(t,"UL",{"data-svelte-h":!0}),m(C)!=="svelte-1c78wn8"&&(C.innerHTML=Rt),nt=n(t),Z=i(t,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-1bc8bfk"&&(Z.textContent=Vt),pt=n(t),g(k.$$.fragment,t),it=n(t),g(x.$$.fragment,t),mt=n(t),W=i(t,"P",{"data-svelte-h":!0}),m(W)!=="svelte-euk5zr"&&(W.innerHTML=Ht),ot=n(t),g(G.$$.fragment,t),ct=n(t),_=i(t,"P",{"data-svelte-h":!0}),m(_)!=="svelte-16p0hj9"&&(_.textContent=Et),gt=n(t),g(I.$$.fragment,t),rt=n(t),w=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m(w)!=="svelte-10bakl"&&(w.innerHTML=Nt),ut=n(t),B=i(t,"P",{"data-svelte-h":!0}),m(B)!=="svelte-85qecv"&&(B.textContent=zt),ft=n(t),g(R.$$.fragment,t),dt=n(t),V=i(t,"P",{"data-svelte-h":!0}),m(V)!=="svelte-wagku9"&&(V.innerHTML=Ft),ht=n(t),H=i(t,"P",{"data-svelte-h":!0}),m(H)!=="svelte-orw6zi"&&(H.textContent=Xt),yt=n(t),g(E.$$.fragment,t),Jt=n(t),M=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m(M)!=="svelte-43wxxb"&&(M.innerHTML=Yt),wt=n(t),g(N.$$.fragment,t),Mt=n(t),z=i(t,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1ktk46w"&&(z.innerHTML=Qt),$t=n(t),g(F.$$.fragment,t),Tt=n(t),X=i(t,"P",{"data-svelte-h":!0}),m(X)!=="svelte-1hncez5"&&(X.innerHTML=St),Ut=n(t),g(Y.$$.fragment,t),jt=n(t),Q=i(t,"P",{"data-svelte-h":!0}),m(Q)!=="svelte-1wdrd3"&&(Q.textContent=Lt),bt=n(t),g(S.$$.fragment,t),vt=n(t),L=i(t,"P",{"data-svelte-h":!0}),m(L)!=="svelte-k6e5ui"&&(L.textContent=qt),Ct=n(t),g(q.$$.fragment,t),Zt=n(t),$=i(t,"DIV",{class:!0,"data-svelte-h":!0}),m($)!=="svelte-43wxxb"&&($.innerHTML=Pt),kt=n(t),g(P.$$.fragment,t),xt=n(t),D=i(t,"P",{}),Dt(D).forEach(s),this.h()},h(){K(o,"name","hf:doc:metadata"),K(o,"content",oe),K(w,"class","flex justify-center"),K(M,"class","flex justify-center"),K($,"class","flex justify-center")},m(t,e){ae(document.head,o),l(t,T,e),l(t,h,e),l(t,A,e),r(U,t,e),l(t,tt,e),l(t,j,e),l(t,et,e),l(t,b,e),l(t,st,e),r(J,t,e),l(t,lt,e),l(t,v,e),l(t,at,e),l(t,C,e),l(t,nt,e),l(t,Z,e),l(t,pt,e),r(k,t,e),l(t,it,e),r(x,t,e),l(t,mt,e),l(t,W,e),l(t,ot,e),r(G,t,e),l(t,ct,e),l(t,_,e),l(t,gt,e),r(I,t,e),l(t,rt,e),l(t,w,e),l(t,ut,e),l(t,B,e),l(t,ft,e),r(R,t,e),l(t,dt,e),l(t,V,e),l(t,ht,e),l(t,H,e),l(t,yt,e),r(E,t,e),l(t,Jt,e),l(t,M,e),l(t,wt,e),r(N,t,e),l(t,Mt,e),l(t,z,e),l(t,$t,e),r(F,t,e),l(t,Tt,e),l(t,X,e),l(t,Ut,e),r(Y,t,e),l(t,jt,e),l(t,Q,e),l(t,bt,e),r(S,t,e),l(t,vt,e),l(t,L,e),l(t,Ct,e),r(q,t,e),l(t,Zt,e),l(t,$,e),l(t,kt,e),r(P,t,e),l(t,xt,e),l(t,D,e),Wt=!0},p(t,[e]){const At={};e&2&&(At.$$scope={dirty:e,ctx:t}),J.$set(At)},i(t){Wt||(u(U.$$.fragment,t),u(J.$$.fragment,t),u(k.$$.fragment,t),u(x.$$.fragment,t),u(G.$$.fragment,t),u(I.$$.fragment,t),u(R.$$.fragment,t),u(E.$$.fragment,t),u(N.$$.fragment,t),u(F.$$.fragment,t),u(Y.$$.fragment,t),u(S.$$.fragment,t),u(q.$$.fragment,t),u(P.$$.fragment,t),Wt=!0)},o(t){f(U.$$.fragment,t),f(J.$$.fragment,t),f(k.$$.fragment,t),f(x.$$.fragment,t),f(G.$$.fragment,t),f(I.$$.fragment,t),f(R.$$.fragment,t),f(E.$$.fragment,t),f(N.$$.fragment,t),f(F.$$.fragment,t),f(Y.$$.fragment,t),f(S.$$.fragment,t),f(q.$$.fragment,t),f(P.$$.fragment,t),Wt=!1},d(t){t&&(s(T),s(h),s(A),s(tt),s(j),s(et),s(b),s(st),s(lt),s(v),s(at),s(C),s(nt),s(Z),s(pt),s(it),s(mt),s(W),s(ot),s(ct),s(_),s(gt),s(rt),s(w),s(ut),s(B),s(ft),s(dt),s(V),s(ht),s(H),s(yt),s(Jt),s(M),s(wt),s(Mt),s(z),s($t),s(Tt),s(X),s(Ut),s(jt),s(Q),s(bt),s(vt),s(L),s(Ct),s(Zt),s($),s(kt),s(xt),s(D)),s(o),d(U,t),d(J,t),d(k,t),d(x,t),d(G,t),d(I,t),d(R,t),d(E,t),d(N,t),d(F,t),d(Y,t),d(S,t),d(q,t),d(P,t)}}}const oe='{"title":"단일 영상 기반 깊이 추정","local":"depth-estimation-pipeline","sections":[{"title":"깊이 추정 파이프라인","local":"depth-estimation-inference-by-hand","sections":[],"depth":2},{"title":"직접 깊이 추정 추론하기","local":"depth-estimation-inference-by-hand","sections":[],"depth":2}],"depth":1}';function ce(O){return Ot(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class he extends ee{constructor(o){super(),se(this,o,ce,me,Kt,{})}}export{he as component};
