> 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/vision-models/groundingdino.md).

# GroundingDINO

GroundingDINO का उपयोग करके टेक्स्ट विवरणों से किसी भी वस्तु का पता लगाएँ

GroundingDINO के साथ टेक्स्ट विवरणों का उपयोग करके किसी भी वस्तु का पता लगाएँ।

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

{% hint style="info" %}
इस गाइड के सभी उदाहरण 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>`

## GroundingDINO क्या है?

IDEA-Research का GroundingDINO सक्षम करता है:

* टेक्स्ट प्रॉम्प्ट के साथ ज़ीरो-शॉट ऑब्जेक्ट डिटेक्शन
* बिना प्रशिक्षण के किसी भी वस्तु का पता लगाएँ
* उच्च-सटीकता बाउंडिंग बॉक्स स्थानीयकरण
* स्वचालित सेगमेंटेशन के लिए SAM के साथ संयोजन करें

## संसाधन

* **GitHub:** [IDEA-Research/GroundingDINO](https://github.com/IDEA-Research/GroundingDINO)
* **पेपर:** [GroundingDINO पेपर](https://arxiv.org/abs/2303.05499)
* **HuggingFace:** [IDEA-Research/grounding-dino](https://huggingface.co/IDEA-Research/grounding-dino-base)
* **डेमो:** [HuggingFace Space](https://huggingface.co/spaces/IDEA-Research/Grounding_DINO_Demo)

## अनुशंसित हार्डवेयर

| घटक     | न्यूनतम       | अनुशंसित      | इष्टतम        |
| ------- | ------------- | ------------- | ------------- |
| GPU     | RTX 3060 12GB | RTX 4080 16GB | RTX 4090 24GB |
| VRAM    | 6GB           | 12GB          | 16GB          |
| CPU     | 4 कोर         | 8 कोर         | 16 कोर        |
| RAM     | 16GB          | 32GB          | 64GB          |
| स्टोरेज | 20GB SSD      | 50GB NVMe     | 100GB NVMe    |
| इंटरनेट | 100 Mbps      | 500 Mbps      | 1 Gbps        |

## CLORE.AI पर त्वरित परिनियोजन

**Docker इमेज:**

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

**पोर्ट:**

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

**कमांड:**

```bash
cd /workspace && \
git clone https://github.com/IDEA-Research/GroundingDINO.git && \\
cd GroundingDINO && \\
pip install -e . && \\
python demo/gradio_demo.py
```

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

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

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

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

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

```bash
git clone https://github.com/IDEA-Research/GroundingDINO.git
cd GroundingDINO
pip install -e .

# वज़न डाउनलोड करें
mkdir weights
cd weights
wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
```

## आप क्या बना सकते हैं

### स्वचालित लेबलिंग

* ML प्रशिक्षण के लिए डेटासेट को स्वचालित रूप से एनोटेट करें
* वर्णनों से बाउंडिंग बॉक्स बनाएं
* डेटा लेबलिंग पाइपलाइनों को तेज़ करें

### दृश्य खोज

* छवि डेटाबेस में विशिष्ट वस्तुएँ खोजें
* सामग्री मॉडरेशन सिस्टम
* रिटेल में उत्पाद पहचान

### रोबोटिक्स और स्वचालन

* रोबोटिक आर्म्स के लिए वस्तु स्थानीयकरण
* इन्वेंट्री प्रबंधन सिस्टम
* गुणवत्ता नियंत्रण निरीक्षण

### रचनात्मक अनुप्रयोग

* फ़ोटो से विषयों को स्वचालित रूप से काटें
* SAM के साथ वस्तु मास्क बनाएं
* सामग्री-जागरूक छवि संपादन

### विश्लेषण

* छवियों में वस्तुओं की संख्या गिनें
* फ़ोटो से इन्वेंट्री ट्रैक करें
* वन्यजीव निगरानी

## मूल उपयोग

```python
from groundingdino.util.inference import load_model, load_image, predict, annotate
import cv2

# मॉडल लोड करें
model = load_model(
    "groundingdino/config/GroundingDINO_SwinT_OGC.py",
    "weights/groundingdino_swint_ogc.pth"
)

# छवि लोड करें
image_source, image = load_image("input.jpg")

# वस्तुओं का पता लगाएँ
TEXT_PROMPT = "बिल्ली . कुत्ता . व्यक्ति"
BOX_THRESHOLD = 0.35
TEXT_THRESHOLD = 0.25

boxes, logits, phrases = predict(
    model=model,
    image=image,
    caption=TEXT_PROMPT,
    box_threshold=BOX_THRESHOLD,
    text_threshold=TEXT_THRESHOLD
)

# छवि को एनोटेट करें
annotated_frame = annotate(
    image_source=image_source,
    boxes=boxes,
    logits=logits,
    phrases=phrases
)

cv2.imwrite("output.jpg", annotated_frame)
```

## GroundingDINO + SAM (Grounded-SAM)

डिटेक्शन को सेगमेंटेशन के साथ संयोजित करें:

```python
import torch
import numpy as np
from groundingdino.util.inference import load_model, load_image, predict
from segment_anything import sam_model_registry, SamPredictor

# GroundingDINO लोड करें
dino_model = load_model(
    "groundingdino/config/GroundingDINO_SwinT_OGC.py",
    "weights/groundingdino_swint_ogc.pth"
)

# SAM लोड करें
sam = sam_model_registry["vit_h"](checkpoint="sam_vit_h_4b8939.pth")
sam.to(device="cuda")
sam_predictor = SamPredictor(sam)

# छवि लोड करें
image_source, image = load_image("input.jpg")

# GroundingDINO के साथ पता लगाएँ
boxes, logits, phrases = predict(
    model=dino_model,
    image=image,
    caption="व्यक्ति . कार",
    box_threshold=0.35,
    text_threshold=0.25
)

# SAM के साथ सेगमेंट करें
sam_predictor.set_image(image_source)

# बॉक्स को SAM फ़ॉर्मेट में बदलें
H, W = image_source.shape[:2]
boxes_xyxy = boxes * torch.tensor([W, H, W, H])

masks = []
for box in boxes_xyxy:
    mask, _, _ = sam_predictor.predict(
        box=box.numpy(),
        multimask_output=False
    )
    masks.append(mask)
```

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

```python
import os
from groundingdino.util.inference import load_model, load_image, predict, annotate
import cv2

model = load_model(
    "groundingdino/config/GroundingDINO_SwinT_OGC.py",
    "weights/groundingdino_swint_ogc.pth"
)

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

TEXT_PROMPT = "उत्पाद . मूल्य टैग . बारकोड"

for filename in os.listdir(input_dir):
    if not filename.endswith(('.jpg', '.png')):
        continue

    image_path = os.path.join(input_dir, filename)
    image_source, image = load_image(image_path)

    boxes, logits, phrases = predict(
        model=model,
        image=image,
        caption=TEXT_PROMPT,
        box_threshold=0.3,
        text_threshold=0.25
    )

    annotated = annotate(image_source, boxes, logits, phrases)
    cv2.imwrite(os.path.join(output_dir, filename), annotated)

    print(f"{filename}: {len(boxes)} वस्तुएँ मिलीं")
```

## कस्टम डिटेक्शन पाइपलाइन

```python
from groundingdino.util.inference import load_model, load_image, predict
import json

model = load_model(
    "groundingdino/config/GroundingDINO_SwinT_OGC.py",
    "weights/groundingdino_swint_ogc.pth"
)

def detect_and_export(image_path, prompt, output_json):
    image_source, image = load_image(image_path)
    H, W = image_source.shape[:2]

    boxes, logits, phrases = predict(
        model=model,
        image=image,
        caption=prompt,
        box_threshold=0.35,
        text_threshold=0.25
    )

    # निरपेक्ष निर्देशांकों में बदलें
    detections = []
    for box, logit, phrase in zip(boxes, logits, phrases):
        x1, y1, x2, y2 = box * torch.tensor([W, H, W, H])
        detections.append({
            "label": phrase,
            "confidence": float(logit),
            "bbox": {
                "x1": int(x1),
                "y1": int(y1),
                "x2": int(x2),
                "y2": int(y2)
            }
        })

    with open(output_json, "w") as f:
        json.dump(detections, f, indent=2)

    return detections

# कार और लोगों का पता लगाएँ
results = detect_and_export(
    "street.jpg",
    "कार . व्यक्ति . साइकिल . ट्रैफिक लाइट",
    "detections.json"
)
```

## Gradio इंटरफ़ेस

```python
import gradio as gr
import cv2
from groundingdino.util.inference import load_model, load_image, predict, annotate
import tempfile
import numpy as np

model = load_model(
    "groundingdino/config/GroundingDINO_SwinT_OGC.py",
    "weights/groundingdino_swint_ogc.pth"
)

def detect_objects(image, text_prompt, box_threshold, text_threshold):
    # अस्थायी छवि सहेजें
    with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as f:
        cv2.imwrite(f.name, cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR))
        image_source, img = load_image(f.name)

    boxes, logits, phrases = predict(
        model=model,
        image=img,
        caption=text_prompt,
        box_threshold=box_threshold,
        text_threshold=text_threshold
    )

    annotated = annotate(image_source, boxes, logits, phrases)
    annotated_rgb = cv2.cvtColor(annotated, cv2.COLOR_BGR2RGB)

    return annotated_rgb, f"{len(boxes)} वस्तुएँ मिलीं: {', '.join(phrases)}"

demo = gr.Interface(
    fn=detect_objects,
    inputs=[
        gr.Image(type="pil", label="Input Image"),
        gr.Textbox(label="पता लगाने के लिए वस्तुएँ", value="व्यक्ति . कार . कुत्ता", placeholder="वस्तु1 . वस्तु2 . वस्तु3"),
        gr.Slider(0.1, 0.9, value=0.35, label="बॉक्स थ्रेशोल्ड"),
        gr.Slider(0.1, 0.9, value=0.25, label="टेक्स्ट थ्रेशोल्ड")
    ],
    outputs=[
        gr.Image(label="पता लगाने का परिणाम"),
        gr.Textbox(label="सारांश")
    ],
    title="GroundingDINO - ओपन-सेट ऑब्जेक्ट डिटेक्शन",
    description="इसे टेक्स्ट में वर्णित करके किसी भी वस्तु का पता लगाएँ। CLORE.AI GPU सर्वरों पर चल रहा है।"
)

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

## प्रदर्शन

| कार्य           | रिज़ॉल्यूशन | GPU      | गति   |
| --------------- | ----------- | -------- | ----- |
| एकल छवि         | 800x600     | RTX 3090 | 120ms |
| एकल छवि         | 800x600     | RTX 4090 | 80ms  |
| एकल छवि         | 1920x1080   | RTX 4090 | 150ms |
| बैच (10 छवियाँ) | 800x600     | RTX 4090 | 600ms |

## सामान्य समस्याएँ और समाधान

### कम पता लगाने की सटीकता

**समस्या:** वस्तुएँ पता नहीं चल रहीं

**समाधान:**

* कम करें `box_threshold` को 0.2-0.3 तक
* कम करें `text_threshold` को 0.15-0.2 तक
* अधिक विशिष्ट वस्तु विवरणों का उपयोग करें
* वस्तुओं को अल्पविरामों से नहीं, " . " से अलग करें

```python

# अच्छा प्रॉम्प्ट फ़ॉर्मैट
TEXT_PROMPT = "लाल कार . टोपी पहने व्यक्ति . लकड़ी की कुर्सी"

# खराब प्रॉम्प्ट फ़ॉर्मैट
TEXT_PROMPT = "लाल कार, टोपी पहने व्यक्ति, लकड़ी की कुर्सी"
```

### मेमोरी समाप्त

**समस्या:** बड़ी छवियों पर CUDA OOM

**समाधान:**

```python

# पता लगाने से पहले बड़ी छवियों का आकार बदलें
from PIL import Image

def resize_if_needed(image_path, max_size=1280):
    img = Image.open(image_path)
    if max(img.size) > max_size:
        ratio = max_size / max(img.size)
        new_size = (int(img.width * ratio), int(img.height * ratio))
        img = img.resize(new_size, Image.LANCZOS)
        img.save(image_path)
```

### धीमी inference

**समस्या:** पता लगाना बहुत लंबा समय ले रहा है

**समाधान:**

* छोटी इनपुट छवियों का उपयोग करें
* एक साथ कई छवियों को बैच में संसाधित करें
* FP16 इन्फरेंस का उपयोग करें
* तेज़ GPU किराए पर लें (RTX 4090, A100)

### गलत सकारात्मक परिणाम

**समस्या:** गलत वस्तुओं का पता लगना

**समाधान:**

* बढ़ाएँ `box_threshold` को 0.4-0.5 तक
* प्रॉम्प्ट में अधिक विशिष्ट हों
* नकारात्मक प्रॉम्प्ट का उपयोग करें (पता लगाने के बाद परिणामों को फ़िल्टर करें)

```python

# कम-विश्वास वाले डिटेक्शन फ़िल्टर करें
filtered = [(b, l, p) for b, l, p in zip(boxes, logits, phrases) if l > 0.5]
```

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

### ऑब्जेक्ट्स का पता नहीं चला

* अधिक विशिष्ट टेक्स्ट विवरणों का उपयोग करें
* विभिन्न वाक्यांश आज़माएँ
* विश्वास-सीमा कम करें

### बाउंडिंग बॉक्स गलत हैं

* टेक्स्ट प्रॉम्प्ट में अधिक विशिष्ट हों
* कई वस्तुओं को अलग करने के लिए "." का उपयोग करें
* छवि की गुणवत्ता जाँचें

{% hint style="danger" %}
**मेमोरी समाप्त**
{% endhint %}

* छवि का रिज़ॉल्यूशन कम करें
* छवियों को एक-एक करके संसाधित करें
* छोटे मॉडल संस्करण का उपयोग करें

### धीमी इनफ़रेंस

* गति बढ़ाने के लिए TensorRT का उपयोग करें
* समान आकार की छवियों को बैच में संसाधित करें
* FP16 इन्फरेंस सक्षम करें

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

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** टोकन
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले चरण

* [SAM2](/guides/guides_v2-hi/vision-models/sam2-video.md) - पता लगाए गए ऑब्जेक्ट्स को सेगमेंट करें
* [Florence-2](/guides/guides_v2-hi/vision-models/florence2.md) - अधिक विज़न कार्य
* [YOLO](/guides/guides_v2-hi/computer-vision/yolov8-detection.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/vision-models/groundingdino.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.
