> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-hi/image-processing/depth-anything.md).

# Depth Anything

Clore.ai पर Depth Anything के साथ मोनोक्युलर डेप्थ अनुमान

Depth Anything के साथ एकल छवियों से गहराई का अनुमान लगाएँ।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलाए जा सकते हैं, जिन्हें किराए पर लिया गया है [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## CLORE.AI पर किराए पर लेना

1. विज़िट करें [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace)
2. GPU प्रकार, VRAM और कीमत के अनुसार फ़िल्टर करें
3. चुनें **ऑन-डिमांड** (स्थिर दर) या **स्पॉट** (बोली मूल्य)
4. अपना ऑर्डर कॉन्फ़िगर करें:
   * Docker इमेज चुनें
   * पोर्ट सेट करें (SSH के लिए TCP, वेब UI के लिए HTTP)
   * यदि आवश्यक हो तो environment variables जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट की प्रतीक्षा करें

### अपने सर्वर तक पहुँचें

* कनेक्शन विवरण यहाँ खोजें **मेरे ऑर्डर**
* वेब इंटरफ़ेस: HTTP पोर्ट URL का उपयोग करें
* SSH: `ssh -p <port> root@<proxy-address>`

## Depth Anything क्या है?

Depth Anything प्रदान करता है:

* अत्याधुनिक गहराई अनुमान
* किसी भी छवि पर काम करता है
* स्टेरियो कैमरे की आवश्यकता नहीं
* तेज़ इन्फरेंस

## मॉडल वेरिएंट

| मॉडल                 | आकार    | VRAM  | गति                |
| -------------------- | ------- | ----- | ------------------ |
| Depth-Anything-Small | 25M     | 2GB   | सबसे तेज़          |
| Depth-Anything-Base  | 98M     | 4GB   | तेज़               |
| Depth-Anything-Large | 335M    | 8GB   | सर्वोत्तम गुणवत्ता |
| Depth-Anything-V2    | विभिन्न | 4-8GB | नवीनतम             |

## त्वरित डिप्लॉय

**Docker इमेज:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime
```

**पोर्ट:**

```
22/tcp
7860/http
```

**कमांड:**

```bash
pip install transformers torch gradio && \
python depth_anything_app.py
```

## अपनी सेवा तक पहुँचना

डिप्लॉयमेंट के बाद, अपना `http_pub` URL यहाँ **मेरे ऑर्डर**:

1. पर जाएँ **मेरे ऑर्डर** पेज
2. अपने ऑर्डर पर क्लिक करें
3. खोजें `http_pub` URL (उदा., `abc123.clorecloud.net`)

उपयोग करें `https://YOUR_HTTP_PUB_URL` की बजाय `localhost` नीचे दिए गए उदाहरणों में।

## इंस्टॉलेशन

```bash
pip install transformers torch
pip install opencv-python pillow
```

## मूल उपयोग

```python
from transformers import pipeline
from PIL import Image

# गहराई अनुमान पाइपलाइन लोड करें
pipe = pipeline(
    task="depth-estimation",
    model="LiheYoung/depth-anything-large-hf",
    device="cuda"
)

# गहराई का अनुमान लगाएँ
image = Image.open("photo.jpg")
depth = pipe(image)

# गहराई मानचित्र सहेजें
depth["depth"].save("depth_map.png")
```

## Depth Anything V2

```python
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
import torch
from PIL import Image
import numpy as np

# मॉडल लोड करें
processor = AutoImageProcessor.from_pretrained("depth-anything/Depth-Anything-V2-Large-hf")
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Large-hf")
model.to("cuda")

# छवि संसाधित करें
image = Image.open("photo.jpg")
inputs = processor(images=image, return_tensors="pt").to("cuda")

with torch.no_grad():
    outputs = model(**inputs)
    predicted_depth = outputs.predicted_depth

# मूल आकार में इंटरपोलेट करें
prediction = torch.nn.functional.interpolate(
    predicted_depth.unsqueeze(1),
    size=image.size[::-1],
    mode="bicubic",
    align_corners=False,
)

# numpy में बदलें
depth = prediction.squeeze().cpu().numpy()
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255
depth = depth.astype(np.uint8)

# सहेजें
Image.fromarray(depth).save("depth.png")
```

## रंगीन गहराई मानचित्र

```python
import cv2
import numpy as np
from PIL import Image

def colorize_depth(depth_array, colormap=cv2.COLORMAP_INFERNO):
    # 0-255 में सामान्यीकृत करें
    depth_normalized = cv2.normalize(depth_array, None, 0, 255, cv2.NORM_MINMAX)
    depth_uint8 = depth_normalized.astype(np.uint8)

    # कलरमैप लागू करें
    colored = cv2.applyColorMap(depth_uint8, colormap)

    return Image.fromarray(cv2.cvtColor(colored, cv2.COLOR_BGR2RGB))

# उपयोग
depth_colored = colorize_depth(depth)
depth_colored.save("depth_colored.png")
```

## बैच प्रोसेसिंग

```python
from transformers import pipeline
from PIL import Image
import os

pipe = pipeline(
    task="depth-estimation",
    model="LiheYoung/depth-anything-large-hf",
    device="cuda"
)

input_dir = "./images"
output_dir = "./depth_maps"
os.makedirs(output_dir, exist_ok=True)

for filename in os.listdir(input_dir):
    if filename.endswith(('.jpg', '.png', '.jpeg')):
        image_path = os.path.join(input_dir, filename)
        image = Image.open(image_path)

        # गहराई प्राप्त करें
        depth = pipe(image)

        # सहेजें
        output_path = os.path.join(output_dir, f"depth_{filename}")
        depth["depth"].save(output_path)
        print(f"Processed: {filename}")
```

## Gradio इंटरफ़ेस

```python
import gradio as gr
from transformers import pipeline
import cv2
import numpy as np

pipe = pipeline(
    task="depth-estimation",
    model="LiheYoung/depth-anything-large-hf",
    device="cuda"
)

def estimate_depth(image, colormap):
    # गहराई प्राप्त करें
    result = pipe(image)
    depth = np.array(result["depth"])

    # रंगीन करें
    depth_normalized = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)

    colormaps = {
        "Inferno": cv2.COLORMAP_INFERNO,
        "Viridis": cv2.COLORMAP_VIRIDIS,
        "Plasma": cv2.COLORMAP_PLASMA,
        "Magma": cv2.COLORMAP_MAGMA,
        "Jet": cv2.COLORMAP_JET
    }

    colored = cv2.applyColorMap(depth_normalized, colormaps[colormap])
    colored = cv2.cvtColor(colored, cv2.COLOR_BGR2RGB)

    return result["depth"], colored

demo = gr.Interface(
    fn=estimate_depth,
    inputs=[
        gr.Image(type="pil", label="Input Image"),
        gr.Dropdown(
            ["Inferno", "Viridis", "Plasma", "Magma", "Jet"],
            value="Inferno",
            label="कलरमैप"
        )
    ],
    outputs=[
        gr.Image(label="गहराई मानचित्र (धूसर-स्तर)"),
        gr.Image(label="गहराई मानचित्र (रंगीन)")
    ],
    title="Depth Anything - गहराई अनुमान"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## एपीआई सर्वर

```python
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import Response
from transformers import pipeline
from PIL import Image
import io
import numpy as np
import cv2

app = FastAPI()

pipe = pipeline(
    task="depth-estimation",
    model="LiheYoung/depth-anything-large-hf",
    device="cuda"
)

@app.post("/depth")
async def estimate_depth(image: UploadFile = File(...), colored: bool = True):
    # छवि लोड करें
    img = Image.open(io.BytesIO(await image.read()))

    # गहराई का अनुमान लगाएँ
    result = pipe(img)
    depth = np.array(result["depth"])

    if colored:
        depth_normalized = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)
        depth_img = cv2.applyColorMap(depth_normalized, cv2.COLORMAP_INFERNO)
        depth_img = cv2.cvtColor(depth_img, cv2.COLOR_BGR2RGB)
    else:
        depth_img = depth

    # बाइट्स में बदलें
    output = Image.fromarray(depth_img)
    buffer = io.BytesIO()
    output.save(buffer, format="PNG")

    return Response(content=buffer.getvalue(), media_type="image/png")

# चलाएँ: uvicorn server:app --host 0.0.0.0 --port 8000
```

## 3D पॉइंट क्लाउड जनरेशन

```python
import numpy as np
import open3d as o3d
from PIL import Image

def depth_to_pointcloud(rgb_image, depth_map, focal_length=500):
    """RGB छवि और गहराई मानचित्र को 3D पॉइंट क्लाउड में बदलें"""
    rgb = np.array(rgb_image)
    depth = np.array(depth_map)

    # छवि के आयाम प्राप्त करें
    height, width = depth.shape

    # मेश ग्रिड बनाएं
    u = np.arange(width)
    v = np.arange(height)
    u, v = np.meshgrid(u, v)

    # 3D निर्देशांकों में बदलें
    z = depth.astype(float)
    x = (u - width / 2) * z / focal_length
    y = (v - height / 2) * z / focal_length

    # निर्देशांकों को स्टैक करें
    points = np.stack([x, y, z], axis=-1).reshape(-1, 3)
    colors = rgb.reshape(-1, 3) / 255.0

    # पॉइंट क्लाउड बनाएं
    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(points)
    pcd.colors = o3d.utility.Vector3dVector(colors)

    return pcd

# उपयोग
rgb = Image.open("photo.jpg")
depth = pipe(rgb)["depth"]

pcd = depth_to_pointcloud(rgb, depth)
o3d.io.write_point_cloud("output.ply", pcd)
```

## उपयोग के मामले

### 3D फोटो प्रभाव

```python
def create_3d_photo(image, depth, shift=20):
    """3D फ़ोटो के लिए पैरालैक्स प्रभाव बनाएं"""
    import cv2
    import numpy as np

    img = np.array(image)
    depth_arr = np.array(depth)

    # गहराई को सामान्यीकृत करें
    depth_norm = (depth_arr - depth_arr.min()) / (depth_arr.max() - depth_arr.min())

    # शिफ्ट किया गया संस्करण बनाएं
    shifted = np.zeros_like(img)
    for y in range(img.shape[0]):
        for x in range(img.shape[1]):
            offset = int(shift * depth_norm[y, x])
            new_x = min(x + offset, img.shape[1] - 1)
            shifted[y, new_x] = img[y, x]

    return Image.fromarray(shifted)
```

### पृष्ठभूमि धुंधलापन (पोर्ट्रेट मोड)

```python
def portrait_mode(image, depth, blur_strength=25):
    import cv2
    import numpy as np

    img = np.array(image)
    depth_arr = np.array(depth)

    # गहराई को सामान्यीकृत करें
    depth_norm = (depth_arr - depth_arr.min()) / (depth_arr.max() - depth_arr.min())

    # धुंधला मास्क बनाएं (पृष्ठभूमि = अधिक गहराई = अधिक धुंधलापन)
    blur_mask = depth_norm

    # धुंधलापन लागू करें
    blurred = cv2.GaussianBlur(img, (blur_strength, blur_strength), 0)

    # गहराई के आधार पर मिश्रित करें
    mask_3d = np.stack([blur_mask] * 3, axis=-1)
    result = (img * (1 - mask_3d) + blurred * mask_3d).astype(np.uint8)

    return Image.fromarray(result)
```

## प्रदर्शन

| मॉडल     | GPU      | प्रति छवि समय |
| -------- | -------- | ------------- |
| छोटा     | RTX 3060 | \~50ms        |
| बेस      | RTX 3060 | \~100ms       |
| लार्ज    | RTX 3090 | \~150ms       |
| लार्ज    | RTX 4090 | \~80ms        |
| V2-Large | RTX 4090 | \~100ms       |

## समस्या निवारण

### खराब गहराई गुणवत्ता

* बड़े मॉडल संस्करण का उपयोग करें
* अच्छी छवि गुणवत्ता सुनिश्चित करें
* परावर्तक सतहों की जाँच करें

### मेमोरी संबंधी समस्याएँ

* छोटे मॉडल संस्करण का उपयोग करें
* छवि का रिज़ॉल्यूशन कम करें
* fp16 इन्फरेंस सक्षम करें

### धीमी प्रोसेसिंग

* छोटा मॉडल उपयोग करें
* यदि संभव हो तो बैच प्रोसेस करें
* GPU इन्फरेंस का उपयोग करें

## लागत का अनुमान

CLORE.AI मार्केटप्लेस की सामान्य दरें (2024 तक):

| GPU       | प्रति घंटा दर | प्रति दिन दर | 4-घंटे का सत्र |
| --------- | ------------- | ------------ | -------------- |
| RTX 3060  | \~$0.03       | \~$0.70      | \~$0.12        |
| RTX 3090  | \~$0.06       | \~$1.50      | \~$0.25        |
| RTX 4090  | \~$0.10       | \~$2.30      | \~$0.40        |
| A100 40GB | \~$0.17       | \~$4.00      | \~$0.70        |
| A100 80GB | \~$0.25       | \~$6.00      | \~$1.00        |

*मूल्य प्रदाता और मांग के अनुसार बदलते हैं। देखें* [*CLORE.AI मार्केटप्लेस*](https://clore.ai/marketplace) *वर्तमान दरों के लिए।*

**पैसे बचाएँ:**

* का उपयोग करें **स्पॉट** बाधित किए जा सकने वाले कार्य के लिए मार्केट — लगभग एक-तिहाई सर्वरों की स्पॉट कीमत ऑन-डिमांड से कम होती है (मध्य \~13% छूट), बाकी उससे मेल खाते हैं
* से भुगतान करें **CLORE** टोकन
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले चरण

* [ControlNet](/guides/guides_v2-hi/image-processing/controlnet-advanced.md) - नियंत्रण के लिए गहराई का उपयोग करें
* [Segment Anything](/guides/guides_v2-hi/image-processing/segment-anything.md) - वस्तु विभाजन
* [3D जनरेशन](/guides/guides_v2-hi/3d/triposr.md) - वीडियो गहराई


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-hi/image-processing/depth-anything.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
