import{S as Ml,i as Ul,s as Sl,e as n,k as r,w as _,t as l,M as Hl,c as i,d as s,m as d,a as m,x as g,h as p,b as h,N as fa,G as e,g as o,y as j,L as Jl,q as v,o as y,B as w,v as Wl}from"../chunks/vendor-hf-doc-builder.js";import{I as Kl}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as x}from"../chunks/CodeBlock-hf-doc-builder.js";function Ql(Bt){let I,rs,D,z,ba,F,ie,Ea,oe,ds,ua,me,hs,C,re,ka,de,he,cs,M,fs,U,S,ce,fe,us,A,ue,H,_e,ge,_s,G,je,qa,ve,ye,gs,J,js,_a,we,vs,N,O,Pa,xe,$e,Ia,be,Ee,ke,R,Da,qe,Pe,za,Ie,De,ys,f,ze,Ca,Ce,Ae,Aa,Ge,Ne,Ga,Oe,Re,Na,Le,Te,ws,ga,Be,xs,W,$s,K,Oa,Vt,bs,$,Ve,Ra,Ye,Fe,La,Me,Ue,Ta,Se,He,Es,Q,ks,X,Ba,Yt,qs,b,Je,Va,We,Ke,Ya,Qe,Xe,Z,Ze,at,Ps,aa,Is,sa,Fa,Ft,Ds,ja,st,zs,ea,Cs,ta,Ma,Mt,As,L,et,Ua,tt,lt,Gs,u,Sa,pt,nt,Ha,it,ot,Ja,mt,rt,Wa,dt,ht,Ka,ct,Ns,la,Os,va,ft,Rs,pa,Ls,c,ut,Qa,_t,gt,Xa,jt,vt,Za,yt,wt,as,xt,$t,ss,bt,Et,Ts,ya,kt,Bs,na,Vs,T,qt,wa,Pt,It,Ys,ia,Fs,k,Dt,es,zt,Ct,ts,At,Gt,Ms,oa,Us,ma,ls,Ut,Ss,xa,Nt,Hs,ra,Js,da,ps,St,Ws,B,Ot,ns,Rt,Lt,Ks,ha,Qs,ca,is,Ht,Xs;return F=new Kl({}),M=new x({props:{code:"pip install -U albumentations ",highlighted:"pip install -U albumentations "}}),J=new x({props:{code:`from datasets import load_dataset

train_dataset = load_dataset("sayakpaul/nyu_depth_v2", split="train")
index = 17
example = train_dataset[index]
example`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>train_dataset = load_dataset(<span class="hljs-string">&quot;sayakpaul/nyu_depth_v2&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>index = <span class="hljs-number">17</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>example = train_dataset[index]
<span class="hljs-meta">&gt;&gt;&gt; </span>example
{<span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.PngImagePlugin.PngImageFile image mode=RGB size=640x480&gt;,
 <span class="hljs-string">&#x27;depth_map&#x27;</span>: &lt;PIL.TiffImagePlugin.TiffImageFile image mode=F size=640x480&gt;}`}}),W=new x({props:{code:'example["image"]',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>example[<span class="hljs-string">&quot;image&quot;</span>]'}}),Q=new x({props:{code:'example["depth_map"].convert("RGB")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>example[<span class="hljs-string">&quot;depth_map&quot;</span>].convert(<span class="hljs-string">&quot;RGB&quot;</span>)'}}),aa=new x({props:{code:`import numpy as np
import matplotlib.pyplot as plt

cmap = plt.cm.viridis

def colored_depthmap(depth, d_min=None, d_max=None):
    if d_min is None:
        d_min = np.min(depth)
    if d_max is None:
        d_max = np.max(depth)
    depth_relative = (depth - d_min) / (d_max - d_min)
    return 255 * cmap(depth_relative)[:,:,:3]

def show_depthmap(depth_map):
   if not isinstance(depth_map, np.ndarray):
       depth_map = np.array(depth_map)
   if depth_map.ndim == 3:
       depth_map = depth_map.squeeze()

   d_min = np.min(depth_map)
   d_max = np.max(depth_map)
   depth_map = colored_depthmap(depth_map, d_min, d_max)

   plt.imshow(depth_map.astype("uint8"))
   plt.axis("off")
   plt.show()

show_depthmap(example["depth_map"])`,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-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-meta">&gt;&gt;&gt; </span>cmap = plt.cm.viridis

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">colored_depthmap</span>(<span class="hljs-params">depth, d_min=<span class="hljs-literal">None</span>, d_max=<span class="hljs-literal">None</span></span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> d_min <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-meta">... </span>        d_min = np.<span class="hljs-built_in">min</span>(depth)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> d_max <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-meta">... </span>        d_max = np.<span class="hljs-built_in">max</span>(depth)
<span class="hljs-meta">... </span>    depth_relative = (depth - d_min) / (d_max - d_min)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> <span class="hljs-number">255</span> * cmap(depth_relative)[:,:,:<span class="hljs-number">3</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">show_depthmap</span>(<span class="hljs-params">depth_map</span>):
<span class="hljs-meta">... </span>   <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(depth_map, np.ndarray):
<span class="hljs-meta">... </span>       depth_map = np.array(depth_map)
<span class="hljs-meta">... </span>   <span class="hljs-keyword">if</span> depth_map.ndim == <span class="hljs-number">3</span>:
<span class="hljs-meta">... </span>       depth_map = depth_map.squeeze()

<span class="hljs-meta">... </span>   d_min = np.<span class="hljs-built_in">min</span>(depth_map)
<span class="hljs-meta">... </span>   d_max = np.<span class="hljs-built_in">max</span>(depth_map)
<span class="hljs-meta">... </span>   depth_map = colored_depthmap(depth_map, d_min, d_max)

<span class="hljs-meta">... </span>   plt.imshow(depth_map.astype(<span class="hljs-string">&quot;uint8&quot;</span>))
<span class="hljs-meta">... </span>   plt.axis(<span class="hljs-string">&quot;off&quot;</span>)
<span class="hljs-meta">... </span>   plt.show()

<span class="hljs-meta">&gt;&gt;&gt; </span>show_depthmap(example[<span class="hljs-string">&quot;depth_map&quot;</span>])`}}),ea=new x({props:{code:`def merge_into_row(input_image, depth_target):
    if not isinstance(input_image, np.ndarray):
        input_image = np.array(input_image)
    d_min = np.min(depth_target)
    d_max = np.max(depth_target)
    depth_target_col = colored_depthmap(depth_target, d_min, d_max)
    img_merge = np.hstack([input_image, depth_target_col])
    return img_merge

random_indices = np.random.choice(len(train_dataset), 9).tolist()
plt.figure(figsize=(15, 6))
for i, idx in enumerate(random_indices):
    example = train_dataset[idx]
    ax = plt.subplot(3, 3, i + 1)
    image_viz = merge_into_row(
        example["image"], example["depth_map"]
    )
    plt.imshow(image_viz.astype("uint8"))
    plt.axis("off")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">merge_into_row</span>(<span class="hljs-params">input_image, depth_target</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(input_image, np.ndarray):
<span class="hljs-meta">... </span>        input_image = np.array(input_image)
...
<span class="hljs-meta">... </span>    d_min = np.<span class="hljs-built_in">min</span>(depth_target)
<span class="hljs-meta">... </span>    d_max = np.<span class="hljs-built_in">max</span>(depth_target)
<span class="hljs-meta">... </span>    depth_target_col = colored_depthmap(depth_target, d_min, d_max)
<span class="hljs-meta">... </span>    img_merge = np.hstack([input_image, depth_target_col])
...
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> img_merge

<span class="hljs-meta">&gt;&gt;&gt; </span>random_indices = np.random.choice(<span class="hljs-built_in">len</span>(train_dataset), <span class="hljs-number">9</span>).tolist()
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure(figsize=(<span class="hljs-number">15</span>, <span class="hljs-number">6</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> i, idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(random_indices):
<span class="hljs-meta">... </span>    example = train_dataset[idx]
<span class="hljs-meta">... </span>    ax = plt.subplot(<span class="hljs-number">3</span>, <span class="hljs-number">3</span>, i + <span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    image_viz = merge_into_row(
<span class="hljs-meta">... </span>        example[<span class="hljs-string">&quot;image&quot;</span>], example[<span class="hljs-string">&quot;depth_map&quot;</span>]
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>    plt.imshow(image_viz.astype(<span class="hljs-string">&quot;uint8&quot;</span>))
<span class="hljs-meta">... </span>    plt.axis(<span class="hljs-string">&quot;off&quot;</span>)`}}),la=new x({props:{code:`import albumentations as A

crop_size = (448, 576)
transforms = [
    A.HorizontalFlip(p=0.5),
    A.RandomCrop(crop_size[0], crop_size[1]),
    A.RandomBrightnessContrast(),
    A.RandomGamma(),
    A.HueSaturationValue()
]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> albumentations <span class="hljs-keyword">as</span> A

<span class="hljs-meta">&gt;&gt;&gt; </span>crop_size = (<span class="hljs-number">448</span>, <span class="hljs-number">576</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>transforms = [
<span class="hljs-meta">... </span>    A.HorizontalFlip(p=<span class="hljs-number">0.5</span>),
<span class="hljs-meta">... </span>    A.RandomCrop(crop_size[<span class="hljs-number">0</span>], crop_size[<span class="hljs-number">1</span>]),
<span class="hljs-meta">... </span>    A.RandomBrightnessContrast(),
<span class="hljs-meta">... </span>    A.RandomGamma(),
<span class="hljs-meta">... </span>    A.HueSaturationValue()
<span class="hljs-meta">... </span>]`}}),pa=new x({props:{code:`additional_targets = {"depth": "mask"}
aug = A.Compose(transforms=transforms, additional_targets=additional_targets)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>additional_targets = {<span class="hljs-string">&quot;depth&quot;</span>: <span class="hljs-string">&quot;mask&quot;</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>aug = A.Compose(transforms=transforms, additional_targets=additional_targets)`}}),na=new x({props:{code:`def apply_transforms(examples):
    transformed_images, transformed_maps = [], []
    for image, depth_map in zip(examples["image"], examples["depth_map"]):
        image, depth_map = np.array(image), np.array(depth_map)
        transformed = aug(image=image, depth=depth_map)
        transformed_images.append(transformed["image"])
        transformed_maps.append(transformed["depth"])
    examples["pixel_values"] = transformed_images
    examples["labels"] = transformed_maps
    return examples`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">apply_transforms</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    transformed_images, transformed_maps = [], []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> image, depth_map <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(examples[<span class="hljs-string">&quot;image&quot;</span>], examples[<span class="hljs-string">&quot;depth_map&quot;</span>]):
<span class="hljs-meta">... </span>        image, depth_map = np.array(image), np.array(depth_map)
<span class="hljs-meta">... </span>        transformed = aug(image=image, depth=depth_map)
<span class="hljs-meta">... </span>        transformed_images.append(transformed[<span class="hljs-string">&quot;image&quot;</span>])
<span class="hljs-meta">... </span>        transformed_maps.append(transformed[<span class="hljs-string">&quot;depth&quot;</span>])
...
<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;pixel_values&quot;</span>] = transformed_images
<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;labels&quot;</span>] = transformed_maps
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> examples`}}),ia=new x({props:{code:"train_dataset.set_transform(apply_transforms)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>train_dataset.set_transform(apply_transforms)'}}),oa=new x({props:{code:`example = train_dataset[index]

plt.imshow(example["pixel_values"])
plt.axis("off")
plt.show()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = train_dataset[index]

<span class="hljs-meta">&gt;&gt;&gt; </span>plt.imshow(example[<span class="hljs-string">&quot;pixel_values&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.axis(<span class="hljs-string">&quot;off&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.show()`}}),ra=new x({props:{code:'show_depthmap(example["labels"])',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>show_depthmap(example[<span class="hljs-string">&quot;labels&quot;</span>])'}}),ha=new x({props:{code:`plt.figure(figsize=(15, 6))

for i, idx in enumerate(random_indices):
    ax = plt.subplot(3, 3, i + 1)
    example = train_dataset[idx]
    image_viz = merge_into_row(
        example["pixel_values"], example["labels"]
    )
    plt.imshow(image_viz.astype("uint8"))
    plt.axis("off")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure(figsize=(<span class="hljs-number">15</span>, <span class="hljs-number">6</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> i, idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(random_indices):
<span class="hljs-meta">... </span>    ax = plt.subplot(<span class="hljs-number">3</span>, <span class="hljs-number">3</span>, i + <span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    example = train_dataset[idx]
<span class="hljs-meta">... </span>    image_viz = merge_into_row(
<span class="hljs-meta">... </span>        example[<span class="hljs-string">&quot;pixel_values&quot;</span>], example[<span class="hljs-string">&quot;labels&quot;</span>]
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>    plt.imshow(image_viz.astype(<span class="hljs-string">&quot;uint8&quot;</span>))
<span class="hljs-meta">... </span>    plt.axis(<span class="hljs-string">&quot;off&quot;</span>)`}}),{c(){I=n("meta"),rs=r(),D=n("h1"),z=n("a"),ba=n("span"),_(F.$$.fragment),ie=r(),Ea=n("span"),oe=l("Depth estimation"),ds=r(),ua=n("p"),me=l(`Depth estimation datasets are used to train a model to approximate the relative distance of every pixel in an
image from the camera, also known as depth. The applications enabled by these datasets primarily lie in areas like visual machine
perception and perception in robotics. Example applications include mapping streets for self-driving cars. This guide will show you how to apply transformations
to a depth estimation dataset.`),hs=r(),C=n("p"),re=l("Before you start, make sure you have up-to-date versions of "),ka=n("code"),de=l("albumentations"),he=l(" installed:"),cs=r(),_(M.$$.fragment),fs=r(),U=n("p"),S=n("a"),ce=l("Albumentations"),fe=l(` is a Python library for performing data augmentation
for computer vision. It supports various computer vision tasks such as image classification, object
detection, segmentation, and keypoint estimation.`),us=r(),A=n("p"),ue=l("This guide uses the "),H=n("a"),_e=l("NYU Depth V2"),ge=l(` dataset which is
comprised of video sequences from various indoor scenes, recorded by RGB and depth cameras. The dataset consists of scenes from 3 cities and provides images along with
their depth maps as labels.`),_s=r(),G=n("p"),je=l("Load the "),qa=n("code"),ve=l("train"),ye=l(" split of the dataset and take a look at an example:"),gs=r(),_(J.$$.fragment),js=r(),_a=n("p"),we=l("The dataset has two fields:"),vs=r(),N=n("ul"),O=n("li"),Pa=n("code"),xe=l("image"),$e=l(": a PIL PNG image object with "),Ia=n("code"),be=l("uint8"),Ee=l(" data type."),ke=r(),R=n("li"),Da=n("code"),qe=l("depth_map"),Pe=l(": a PIL Tiff image object with "),za=n("code"),Ie=l("float32"),De=l(" data type which is the depth map of the image."),ys=r(),f=n("p"),ze=l("It is mention-worthy that JPEG/PNG format can only store "),Ca=n("code"),Ce=l("uint8"),Ae=l(" or "),Aa=n("code"),Ge=l("uint16"),Ne=l(" data. As the depth map is "),Ga=n("code"),Oe=l("float32"),Re=l(" data, it can\u2019t be stored using PNG/JPEG. However, we can save the depth map using TIFF format as it supports a wider range of data types, including "),Na=n("code"),Le=l("float32"),Te=l(" data."),ws=r(),ga=n("p"),Be=l("Next, check out an image with:"),xs=r(),_(W.$$.fragment),$s=r(),K=n("div"),Oa=n("img"),bs=r(),$=n("p"),Ve=l("Before we look at the depth map, we need to first convert its data type to "),Ra=n("code"),Ye=l("uint8"),Fe=l(" using "),La=n("code"),Me=l(".convert('RGB')"),Ue=l(" as PIL can\u2019t display "),Ta=n("code"),Se=l("float32"),He=l(" images. Now take a look at its corresponding depth map:"),Es=r(),_(Q.$$.fragment),ks=r(),X=n("div"),Ba=n("img"),qs=r(),b=n("p"),Je=l("It\u2019s all black! You\u2019ll need to add some color to the depth map to visualize it properly. To do that, either we can apply color automatically during display using "),Va=n("code"),We=l("plt.imshow()"),Ke=l(" or create a colored depth map using "),Ya=n("code"),Qe=l("plt.cm"),Xe=l(" and then display it. In this example, we have used the latter one, as we can save/write the colored depth map later. (the utility below is taken from the "),Z=n("a"),Ze=l("FastDepth repository"),at=l(")."),Ps=r(),_(aa.$$.fragment),Is=r(),sa=n("div"),Fa=n("img"),Ds=r(),ja=n("p"),st=l("You can also visualize several different images and their corresponding depth maps."),zs=r(),_(ea.$$.fragment),Cs=r(),ta=n("div"),Ma=n("img"),As=r(),L=n("p"),et=l("Now apply some augmentations with "),Ua=n("code"),tt=l("albumentations"),lt=l(". The augmentation transformations include:"),Gs=r(),u=n("ul"),Sa=n("li"),pt=l("Random horizontal flipping"),nt=r(),Ha=n("li"),it=l("Random cropping"),ot=r(),Ja=n("li"),mt=l("Random brightness and contrast"),rt=r(),Wa=n("li"),dt=l("Random gamma correction"),ht=r(),Ka=n("li"),ct=l("Random hue saturation"),Ns=r(),_(la.$$.fragment),Os=r(),va=n("p"),ft=l("Additionally, define a mapping to better reflect the target key name."),Rs=r(),_(pa.$$.fragment),Ls=r(),c=n("p"),ut=l("With "),Qa=n("code"),_t=l("additional_targets"),gt=l(" defined, you can pass the target depth maps to the "),Xa=n("code"),jt=l("depth"),vt=l(" argument of "),Za=n("code"),yt=l("aug"),wt=l(" instead of "),as=n("code"),xt=l("mask"),$t=l(`. You\u2019ll notice this change
in the `),ss=n("code"),bt=l("apply_transforms()"),Et=l(" function defined below."),Ts=r(),ya=n("p"),kt=l("Create a function to apply the transformation to the images as well as their depth maps:"),Bs=r(),_(na.$$.fragment),Vs=r(),T=n("p"),qt=l("Use the "),wa=n("a"),Pt=l("set_transform()"),It=l(" function to apply the transformation on-the-fly to batches of the dataset to consume less disk space:"),Ys=r(),_(ia.$$.fragment),Fs=r(),k=n("p"),Dt=l("You can verify the transformation worked by indexing into the "),es=n("code"),zt=l("pixel_values"),Ct=l(" and "),ts=n("code"),At=l("labels"),Gt=l(" of an example image:"),Ms=r(),_(oa.$$.fragment),Us=r(),ma=n("div"),ls=n("img"),Ss=r(),xa=n("p"),Nt=l("Visualize the same transformation on the image\u2019s corresponding depth map:"),Hs=r(),_(ra.$$.fragment),Js=r(),da=n("div"),ps=n("img"),Ws=r(),B=n("p"),Ot=l("You can also visualize multiple training samples reusing the previous "),ns=n("code"),Rt=l("random_indices"),Lt=l(":"),Ks=r(),_(ha.$$.fragment),Qs=r(),ca=n("div"),is=n("img"),this.h()},l(a){const t=Hl('[data-svelte="svelte-1phssyn"]',document.head);I=i(t,"META",{name:!0,content:!0}),t.forEach(s),rs=d(a),D=i(a,"H1",{class:!0});var Zs=m(D);z=i(Zs,"A",{id:!0,class:!0,href:!0});var Jt=m(z);ba=i(Jt,"SPAN",{});var Wt=m(ba);g(F.$$.fragment,Wt),Wt.forEach(s),Jt.forEach(s),ie=d(Zs),Ea=i(Zs,"SPAN",{});var Kt=m(Ea);oe=p(Kt,"Depth estimation"),Kt.forEach(s),Zs.forEach(s),ds=d(a),ua=i(a,"P",{});var Qt=m(ua);me=p(Qt,`Depth estimation datasets are used to train a model to approximate the relative distance of every pixel in an
image from the camera, also known as depth. The applications enabled by these datasets primarily lie in areas like visual machine
perception and perception in robotics. Example applications include mapping streets for self-driving cars. This guide will show you how to apply transformations
to a depth estimation dataset.`),Qt.forEach(s),hs=d(a),C=i(a,"P",{});var ae=m(C);re=p(ae,"Before you start, make sure you have up-to-date versions of "),ka=i(ae,"CODE",{});var Xt=m(ka);de=p(Xt,"albumentations"),Xt.forEach(s),he=p(ae," installed:"),ae.forEach(s),cs=d(a),g(M.$$.fragment,a),fs=d(a),U=i(a,"P",{});var Tt=m(U);S=i(Tt,"A",{href:!0,rel:!0});var Zt=m(S);ce=p(Zt,"Albumentations"),Zt.forEach(s),fe=p(Tt,` is a Python library for performing data augmentation
for computer vision. It supports various computer vision tasks such as image classification, object
detection, segmentation, and keypoint estimation.`),Tt.forEach(s),us=d(a),A=i(a,"P",{});var se=m(A);ue=p(se,"This guide uses the "),H=i(se,"A",{href:!0,rel:!0});var al=m(H);_e=p(al,"NYU Depth V2"),al.forEach(s),ge=p(se,` dataset which is
comprised of video sequences from various indoor scenes, recorded by RGB and depth cameras. The dataset consists of scenes from 3 cities and provides images along with
their depth maps as labels.`),se.forEach(s),_s=d(a),G=i(a,"P",{});var ee=m(G);je=p(ee,"Load the "),qa=i(ee,"CODE",{});var sl=m(qa);ve=p(sl,"train"),sl.forEach(s),ye=p(ee," split of the dataset and take a look at an example:"),ee.forEach(s),gs=d(a),g(J.$$.fragment,a),js=d(a),_a=i(a,"P",{});var el=m(_a);we=p(el,"The dataset has two fields:"),el.forEach(s),vs=d(a),N=i(a,"UL",{});var te=m(N);O=i(te,"LI",{});var os=m(O);Pa=i(os,"CODE",{});var tl=m(Pa);xe=p(tl,"image"),tl.forEach(s),$e=p(os,": a PIL PNG image object with "),Ia=i(os,"CODE",{});var ll=m(Ia);be=p(ll,"uint8"),ll.forEach(s),Ee=p(os," data type."),os.forEach(s),ke=d(te),R=i(te,"LI",{});var ms=m(R);Da=i(ms,"CODE",{});var pl=m(Da);qe=p(pl,"depth_map"),pl.forEach(s),Pe=p(ms,": a PIL Tiff image object with "),za=i(ms,"CODE",{});var nl=m(za);Ie=p(nl,"float32"),nl.forEach(s),De=p(ms," data type which is the depth map of the image."),ms.forEach(s),te.forEach(s),ys=d(a),f=i(a,"P",{});var q=m(f);ze=p(q,"It is mention-worthy that JPEG/PNG format can only store "),Ca=i(q,"CODE",{});var il=m(Ca);Ce=p(il,"uint8"),il.forEach(s),Ae=p(q," or "),Aa=i(q,"CODE",{});var ol=m(Aa);Ge=p(ol,"uint16"),ol.forEach(s),Ne=p(q," data. As the depth map is "),Ga=i(q,"CODE",{});var ml=m(Ga);Oe=p(ml,"float32"),ml.forEach(s),Re=p(q," data, it can\u2019t be stored using PNG/JPEG. However, we can save the depth map using TIFF format as it supports a wider range of data types, including "),Na=i(q,"CODE",{});var rl=m(Na);Le=p(rl,"float32"),rl.forEach(s),Te=p(q," data."),q.forEach(s),ws=d(a),ga=i(a,"P",{});var dl=m(ga);Be=p(dl,"Next, check out an image with:"),dl.forEach(s),xs=d(a),g(W.$$.fragment,a),$s=d(a),K=i(a,"DIV",{class:!0});var hl=m(K);Oa=i(hl,"IMG",{src:!0}),hl.forEach(s),bs=d(a),$=i(a,"P",{});var V=m($);Ve=p(V,"Before we look at the depth map, we need to first convert its data type to "),Ra=i(V,"CODE",{});var cl=m(Ra);Ye=p(cl,"uint8"),cl.forEach(s),Fe=p(V," using "),La=i(V,"CODE",{});var fl=m(La);Me=p(fl,".convert('RGB')"),fl.forEach(s),Ue=p(V," as PIL can\u2019t display "),Ta=i(V,"CODE",{});var ul=m(Ta);Se=p(ul,"float32"),ul.forEach(s),He=p(V," images. Now take a look at its corresponding depth map:"),V.forEach(s),Es=d(a),g(Q.$$.fragment,a),ks=d(a),X=i(a,"DIV",{class:!0});var _l=m(X);Ba=i(_l,"IMG",{src:!0}),_l.forEach(s),qs=d(a),b=i(a,"P",{});var Y=m(b);Je=p(Y,"It\u2019s all black! You\u2019ll need to add some color to the depth map to visualize it properly. To do that, either we can apply color automatically during display using "),Va=i(Y,"CODE",{});var gl=m(Va);We=p(gl,"plt.imshow()"),gl.forEach(s),Ke=p(Y," or create a colored depth map using "),Ya=i(Y,"CODE",{});var jl=m(Ya);Qe=p(jl,"plt.cm"),jl.forEach(s),Xe=p(Y," and then display it. In this example, we have used the latter one, as we can save/write the colored depth map later. (the utility below is taken from the "),Z=i(Y,"A",{href:!0,rel:!0});var vl=m(Z);Ze=p(vl,"FastDepth repository"),vl.forEach(s),at=p(Y,")."),Y.forEach(s),Ps=d(a),g(aa.$$.fragment,a),Is=d(a),sa=i(a,"DIV",{class:!0});var yl=m(sa);Fa=i(yl,"IMG",{src:!0}),yl.forEach(s),Ds=d(a),ja=i(a,"P",{});var wl=m(ja);st=p(wl,"You can also visualize several different images and their corresponding depth maps."),wl.forEach(s),zs=d(a),g(ea.$$.fragment,a),Cs=d(a),ta=i(a,"DIV",{class:!0});var xl=m(ta);Ma=i(xl,"IMG",{src:!0}),xl.forEach(s),As=d(a),L=i(a,"P",{});var le=m(L);et=p(le,"Now apply some augmentations with "),Ua=i(le,"CODE",{});var $l=m(Ua);tt=p($l,"albumentations"),$l.forEach(s),lt=p(le,". The augmentation transformations include:"),le.forEach(s),Gs=d(a),u=i(a,"UL",{});var P=m(u);Sa=i(P,"LI",{});var bl=m(Sa);pt=p(bl,"Random horizontal flipping"),bl.forEach(s),nt=d(P),Ha=i(P,"LI",{});var El=m(Ha);it=p(El,"Random cropping"),El.forEach(s),ot=d(P),Ja=i(P,"LI",{});var kl=m(Ja);mt=p(kl,"Random brightness and contrast"),kl.forEach(s),rt=d(P),Wa=i(P,"LI",{});var ql=m(Wa);dt=p(ql,"Random gamma correction"),ql.forEach(s),ht=d(P),Ka=i(P,"LI",{});var Pl=m(Ka);ct=p(Pl,"Random hue saturation"),Pl.forEach(s),P.forEach(s),Ns=d(a),g(la.$$.fragment,a),Os=d(a),va=i(a,"P",{});var Il=m(va);ft=p(Il,"Additionally, define a mapping to better reflect the target key name."),Il.forEach(s),Rs=d(a),g(pa.$$.fragment,a),Ls=d(a),c=i(a,"P",{});var E=m(c);ut=p(E,"With "),Qa=i(E,"CODE",{});var Dl=m(Qa);_t=p(Dl,"additional_targets"),Dl.forEach(s),gt=p(E," defined, you can pass the target depth maps to the "),Xa=i(E,"CODE",{});var zl=m(Xa);jt=p(zl,"depth"),zl.forEach(s),vt=p(E," argument of "),Za=i(E,"CODE",{});var Cl=m(Za);yt=p(Cl,"aug"),Cl.forEach(s),wt=p(E," instead of "),as=i(E,"CODE",{});var Al=m(as);xt=p(Al,"mask"),Al.forEach(s),$t=p(E,`. You\u2019ll notice this change
in the `),ss=i(E,"CODE",{});var Gl=m(ss);bt=p(Gl,"apply_transforms()"),Gl.forEach(s),Et=p(E," function defined below."),E.forEach(s),Ts=d(a),ya=i(a,"P",{});var Nl=m(ya);kt=p(Nl,"Create a function to apply the transformation to the images as well as their depth maps:"),Nl.forEach(s),Bs=d(a),g(na.$$.fragment,a),Vs=d(a),T=i(a,"P",{});var pe=m(T);qt=p(pe,"Use the "),wa=i(pe,"A",{href:!0});var Ol=m(wa);Pt=p(Ol,"set_transform()"),Ol.forEach(s),It=p(pe," function to apply the transformation on-the-fly to batches of the dataset to consume less disk space:"),pe.forEach(s),Ys=d(a),g(ia.$$.fragment,a),Fs=d(a),k=i(a,"P",{});var $a=m(k);Dt=p($a,"You can verify the transformation worked by indexing into the "),es=i($a,"CODE",{});var Rl=m(es);zt=p(Rl,"pixel_values"),Rl.forEach(s),Ct=p($a," and "),ts=i($a,"CODE",{});var Ll=m(ts);At=p(Ll,"labels"),Ll.forEach(s),Gt=p($a," of an example image:"),$a.forEach(s),Ms=d(a),g(oa.$$.fragment,a),Us=d(a),ma=i(a,"DIV",{class:!0});var Tl=m(ma);ls=i(Tl,"IMG",{src:!0}),Tl.forEach(s),Ss=d(a),xa=i(a,"P",{});var Bl=m(xa);Nt=p(Bl,"Visualize the same transformation on the image\u2019s corresponding depth map:"),Bl.forEach(s),Hs=d(a),g(ra.$$.fragment,a),Js=d(a),da=i(a,"DIV",{class:!0});var Vl=m(da);ps=i(Vl,"IMG",{src:!0}),Vl.forEach(s),Ws=d(a),B=i(a,"P",{});var ne=m(B);Ot=p(ne,"You can also visualize multiple training samples reusing the previous "),ns=i(ne,"CODE",{});var Yl=m(ns);Rt=p(Yl,"random_indices"),Yl.forEach(s),Lt=p(ne,":"),ne.forEach(s),Ks=d(a),g(ha.$$.fragment,a),Qs=d(a),ca=i(a,"DIV",{class:!0});var Fl=m(ca);is=i(Fl,"IMG",{src:!0}),Fl.forEach(s),this.h()},h(){h(I,"name","hf:doc:metadata"),h(I,"content",JSON.stringify(Xl)),h(z,"id","depth-estimation"),h(z,"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"),h(z,"href","#depth-estimation"),h(D,"class","relative group"),h(S,"href","https://albumentations.ai/"),h(S,"rel","nofollow"),h(H,"href","https://huggingface.co/datasets/sayakpaul/nyu_depth_v2"),h(H,"rel","nofollow"),fa(Oa.src,Vt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_sample.png")||h(Oa,"src",Vt),h(K,"class","flex justify-center"),fa(Ba.src,Yt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_target.png")||h(Ba,"src",Yt),h(X,"class","flex justify-center"),h(Z,"href","https://github.com/dwofk/fast-depth/blob/master/utils.py"),h(Z,"rel","nofollow"),fa(Fa.src,Ft="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_target_viz.png")||h(Fa,"src",Ft),h(sa,"class","flex justify-center"),fa(Ma.src,Mt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_collage.png")||h(Ma,"src",Mt),h(ta,"class","flex justify-center"),h(wa,"href","/docs/datasets/v2.11.0/en/package_reference/main_classes#datasets.Dataset.set_transform"),fa(ls.src,Ut="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_sample_aug.png")||h(ls,"src",Ut),h(ma,"class","flex justify-center"),fa(ps.src,St="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_target_aug.png")||h(ps,"src",St),h(da,"class","flex justify-center"),fa(is.src,Ht="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/datasets/depth_est_aug_collage.png")||h(is,"src",Ht),h(ca,"class","flex justify-center")},m(a,t){e(document.head,I),o(a,rs,t),o(a,D,t),e(D,z),e(z,ba),j(F,ba,null),e(D,ie),e(D,Ea),e(Ea,oe),o(a,ds,t),o(a,ua,t),e(ua,me),o(a,hs,t),o(a,C,t),e(C,re),e(C,ka),e(ka,de),e(C,he),o(a,cs,t),j(M,a,t),o(a,fs,t),o(a,U,t),e(U,S),e(S,ce),e(U,fe),o(a,us,t),o(a,A,t),e(A,ue),e(A,H),e(H,_e),e(A,ge),o(a,_s,t),o(a,G,t),e(G,je),e(G,qa),e(qa,ve),e(G,ye),o(a,gs,t),j(J,a,t),o(a,js,t),o(a,_a,t),e(_a,we),o(a,vs,t),o(a,N,t),e(N,O),e(O,Pa),e(Pa,xe),e(O,$e),e(O,Ia),e(Ia,be),e(O,Ee),e(N,ke),e(N,R),e(R,Da),e(Da,qe),e(R,Pe),e(R,za),e(za,Ie),e(R,De),o(a,ys,t),o(a,f,t),e(f,ze),e(f,Ca),e(Ca,Ce),e(f,Ae),e(f,Aa),e(Aa,Ge),e(f,Ne),e(f,Ga),e(Ga,Oe),e(f,Re),e(f,Na),e(Na,Le),e(f,Te),o(a,ws,t),o(a,ga,t),e(ga,Be),o(a,xs,t),j(W,a,t),o(a,$s,t),o(a,K,t),e(K,Oa),o(a,bs,t),o(a,$,t),e($,Ve),e($,Ra),e(Ra,Ye),e($,Fe),e($,La),e(La,Me),e($,Ue),e($,Ta),e(Ta,Se),e($,He),o(a,Es,t),j(Q,a,t),o(a,ks,t),o(a,X,t),e(X,Ba),o(a,qs,t),o(a,b,t),e(b,Je),e(b,Va),e(Va,We),e(b,Ke),e(b,Ya),e(Ya,Qe),e(b,Xe),e(b,Z),e(Z,Ze),e(b,at),o(a,Ps,t),j(aa,a,t),o(a,Is,t),o(a,sa,t),e(sa,Fa),o(a,Ds,t),o(a,ja,t),e(ja,st),o(a,zs,t),j(ea,a,t),o(a,Cs,t),o(a,ta,t),e(ta,Ma),o(a,As,t),o(a,L,t),e(L,et),e(L,Ua),e(Ua,tt),e(L,lt),o(a,Gs,t),o(a,u,t),e(u,Sa),e(Sa,pt),e(u,nt),e(u,Ha),e(Ha,it),e(u,ot),e(u,Ja),e(Ja,mt),e(u,rt),e(u,Wa),e(Wa,dt),e(u,ht),e(u,Ka),e(Ka,ct),o(a,Ns,t),j(la,a,t),o(a,Os,t),o(a,va,t),e(va,ft),o(a,Rs,t),j(pa,a,t),o(a,Ls,t),o(a,c,t),e(c,ut),e(c,Qa),e(Qa,_t),e(c,gt),e(c,Xa),e(Xa,jt),e(c,vt),e(c,Za),e(Za,yt),e(c,wt),e(c,as),e(as,xt),e(c,$t),e(c,ss),e(ss,bt),e(c,Et),o(a,Ts,t),o(a,ya,t),e(ya,kt),o(a,Bs,t),j(na,a,t),o(a,Vs,t),o(a,T,t),e(T,qt),e(T,wa),e(wa,Pt),e(T,It),o(a,Ys,t),j(ia,a,t),o(a,Fs,t),o(a,k,t),e(k,Dt),e(k,es),e(es,zt),e(k,Ct),e(k,ts),e(ts,At),e(k,Gt),o(a,Ms,t),j(oa,a,t),o(a,Us,t),o(a,ma,t),e(ma,ls),o(a,Ss,t),o(a,xa,t),e(xa,Nt),o(a,Hs,t),j(ra,a,t),o(a,Js,t),o(a,da,t),e(da,ps),o(a,Ws,t),o(a,B,t),e(B,Ot),e(B,ns),e(ns,Rt),e(B,Lt),o(a,Ks,t),j(ha,a,t),o(a,Qs,t),o(a,ca,t),e(ca,is),Xs=!0},p:Jl,i(a){Xs||(v(F.$$.fragment,a),v(M.$$.fragment,a),v(J.$$.fragment,a),v(W.$$.fragment,a),v(Q.$$.fragment,a),v(aa.$$.fragment,a),v(ea.$$.fragment,a),v(la.$$.fragment,a),v(pa.$$.fragment,a),v(na.$$.fragment,a),v(ia.$$.fragment,a),v(oa.$$.fragment,a),v(ra.$$.fragment,a),v(ha.$$.fragment,a),Xs=!0)},o(a){y(F.$$.fragment,a),y(M.$$.fragment,a),y(J.$$.fragment,a),y(W.$$.fragment,a),y(Q.$$.fragment,a),y(aa.$$.fragment,a),y(ea.$$.fragment,a),y(la.$$.fragment,a),y(pa.$$.fragment,a),y(na.$$.fragment,a),y(ia.$$.fragment,a),y(oa.$$.fragment,a),y(ra.$$.fragment,a),y(ha.$$.fragment,a),Xs=!1},d(a){s(I),a&&s(rs),a&&s(D),w(F),a&&s(ds),a&&s(ua),a&&s(hs),a&&s(C),a&&s(cs),w(M,a),a&&s(fs),a&&s(U),a&&s(us),a&&s(A),a&&s(_s),a&&s(G),a&&s(gs),w(J,a),a&&s(js),a&&s(_a),a&&s(vs),a&&s(N),a&&s(ys),a&&s(f),a&&s(ws),a&&s(ga),a&&s(xs),w(W,a),a&&s($s),a&&s(K),a&&s(bs),a&&s($),a&&s(Es),w(Q,a),a&&s(ks),a&&s(X),a&&s(qs),a&&s(b),a&&s(Ps),w(aa,a),a&&s(Is),a&&s(sa),a&&s(Ds),a&&s(ja),a&&s(zs),w(ea,a),a&&s(Cs),a&&s(ta),a&&s(As),a&&s(L),a&&s(Gs),a&&s(u),a&&s(Ns),w(la,a),a&&s(Os),a&&s(va),a&&s(Rs),w(pa,a),a&&s(Ls),a&&s(c),a&&s(Ts),a&&s(ya),a&&s(Bs),w(na,a),a&&s(Vs),a&&s(T),a&&s(Ys),w(ia,a),a&&s(Fs),a&&s(k),a&&s(Ms),w(oa,a),a&&s(Us),a&&s(ma),a&&s(Ss),a&&s(xa),a&&s(Hs),w(ra,a),a&&s(Js),a&&s(da),a&&s(Ws),a&&s(B),a&&s(Ks),w(ha,a),a&&s(Qs),a&&s(ca)}}}const Xl={local:"depth-estimation",title:"Depth estimation"};function Zl(Bt){return Wl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tp extends Ml{constructor(I){super();Ul(this,I,Zl,Ql,Sl,{})}}export{tp as default,Xl as metadata};
