> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/models/hi/supported-models/sam3.md).

# SAM3

हम Meta के [सेगमेंट एनीथिंग मॉडल 3](https://github.com/facebookresearch/sam3) हमारे माध्यम से इन्फरेंसिंग [सर्वरलेस होस्टेड API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api). हम दो अलग-अलग SAM3 एंडपॉइंट प्रदान करते हैं:

{% hint style="info" %}
Roboflow पर SAM3 मॉडल को प्रशिक्षित करना सशुल्क [योजनाओं](https://docs.roboflow.com/platform/billing-and-plans/plans) जिनमें शामिल है [उपयोग-आधारित बिलिंग](https://docs.roboflow.com/platform/billing-and-plans/credits). वहाँ से, आप सुविधा का उपयोग करने के लिए SAM3 आर्किटेक्चर पर "Request Feature" बटन से पहुँच का अनुरोध कर सकते हैं [प्रशिक्षण प्रवाह](/models/hi/readme.md).
{% endhint %}

* [प्रॉम्प्ट-आधारित कॉन्सेप्ट सेगमेंटेशन](#concept-segmentation-pcs) (**PCS**), जो छवि में किसी कॉन्सेप्ट के हर उदाहरण को सेगमेंट करता है। कॉन्सेप्ट का वर्णन टेक्स्ट प्रॉम्प्ट, उदाहरण बॉक्स, या दोनों से किया जाता है।
* [प्रॉम्प्ट-आधारित विज़ुअल सेगमेंटेशन](#visual-segmentation-pvs) (**PVS**), जो SAM2 की शैली में, बिंदुओं या एक बॉक्स से प्रति अनुरोध एक ऑब्जेक्ट को इंटरैक्टिव रूप से सेगमेंट करता है।

एंडपॉइंट चुनने के लिए इस तालिका का उपयोग करें:

<table data-search="false"><thead><tr><th>आपके पास है</th><th>आप चाहते हैं</th><th>उपयोग करें</th></tr></thead><tbody><tr><td>एक टेक्स्ट विवरण (उदा: "व्यक्ति")</td><td>हर मेल खाने वाले उदाहरण के लिए मास्क</td><td><code>/sam3/concept_segment</code></td></tr><tr><td>एक उदाहरण ऑब्जेक्ट के चारों ओर एक बॉक्स</td><td>हर समान उदाहरण के लिए मास्क</td><td><code>/sam3/concept_segment</code></td></tr><tr><td>ऑब्जेक्ट शामिल या बाहर करने के लिए टेक्स्ट और उदाहरण बॉक्स</td><td>हर मेल खाने वाले उदाहरण के लिए मास्क</td><td><code>/sam3/concept_segment</code></td></tr><tr><td>एक विशिष्ट ऑब्जेक्ट पर एक क्लिक या बॉक्स</td><td>केवल उस ऑब्जेक्ट के लिए एक मास्क</td><td><code>/sam3/visual_segment</code></td></tr></tbody></table>

अपनी [API कुंजी](https://app.roboflow.com/settings/api) के रूप में `api_key` प्रत्येक अनुरोध पर क्वेरी पैरामीटर.

## कॉन्सेप्ट सेगमेंटेशन (PCS)

`POST https://serverless.roboflow.com/sam3/concept_segment`

में प्रत्येक प्रविष्टि `प्रॉम्प्ट्स` एक कॉन्सेप्ट का वर्णन करती है। प्रतिक्रिया में एक `prompt_results` प्रत्येक प्रॉम्प्ट के लिए एक प्रविष्टि होती है, और प्रत्येक में पाए गए सभी उदाहरण होते हैं। अनुरोध अधिकतम 16 प्रॉम्प्ट स्वीकार करते हैं।

### टेक्स्ट प्रॉम्प्ट

```python
import os
import requests

payload = {
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/people-walking.jpg"},
    "prompts": [
        {"type": "text", "text": "व्यक्ति"},
        {"type": "text", "text": "बैगपैक"},
    ],
    "output_prob_thresh": 0.5,
    "format": "polygon",  # या "rle"
}

response = requests.post(
    "https://serverless.roboflow.com/sam3/concept_segment",
    params={"api_key": os.environ["ROBOFLOW_API_KEY"]},
    json=payload,
)
for prompt_result in response.json()["prompt_results"]:
    print(prompt_result["echo"], len(prompt_result["predictions"]), "उदाहरण")
```

छवियाँ इनलाइन भी इस रूप में भेजी जा सकती हैं `{"type": "base64", "value": "<BASE64_IMAGE>"}`.

### उदाहरण बॉक्स प्रॉम्प्ट

टेक्स्ट की बजाय, आप एक उदाहरण के साथ प्रॉम्प्ट कर सकते हैं: एक उदाहरण ऑब्जेक्ट के चारों ओर एक बॉक्स। मॉडल उदाहरण से मेल खाने वाले हर उदाहरण को ढूँढता है, केवल बॉक्स किए गए ऑब्जेक्ट को नहीं।

```python
payload = {
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/people-walking.jpg"},
    "prompts": [
        {
            "type": "visual",
            "boxes": [{"x": 1409, "y": 705, "width": 112, "height": 183}],
            "box_labels": [1],
        }
    ],
    "output_prob_thresh": 0.5,
    "format": "polygon",
}
```

बॉक्स पूर्ण पिक्सेल निर्देशांक का उपयोग करते हैं। दो प्रारूप स्वीकार किए जाते हैं:

* `{"x": ..., "y": ..., "width": ..., "height": ...}` जहाँ `x`, `y` ऊपरी-बाएँ कोना है
* `{"x0": ..., "y0": ..., "x1": ..., "y1": ...}` स्पष्ट कोनों के लिए

`box_labels` आवश्यक है जब `boxes` सेट किया गया हो और प्रत्येक बॉक्स के लिए एक प्रविष्टि होनी चाहिए: `1` एक सकारात्मक उदाहरण दर्शाता है (ऐसे ऑब्जेक्ट ढूँढें), `0` एक नकारात्मक उदाहरण दर्शाता है (ऐसे ऑब्जेक्ट बाहर करें)।

### संयुक्त टेक्स्ट और उदाहरण प्रॉम्प्ट

एक ही प्रॉम्प्ट में टेक्स्ट और उदाहरण बॉक्स दोनों हो सकते हैं। यह किसी टेक्स्ट कॉन्सेप्ट को दृश्य उदाहरणों से सीमित करने, या नकारात्मक उदाहरणों के साथ मिलते-जुलते ऑब्जेक्ट बाहर करने के लिए उपयोगी है:

```python
payload = {
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/people-walking.jpg"},
    "prompts": [
        {
            "type": "visual",
            "text": "व्यक्ति",
            "boxes": [
                {"x": 1409, "y": 705, "width": 112, "height": 183},
                {"x": 1216, "y": 496, "width": 124, "height": 184},
            ],
            "box_labels": [1, 0],
        }
    ],
    "output_prob_thresh": 0.5,
    "format": "polygon",
}
```

यहाँ मॉडल पहले (सकारात्मक) उदाहरण से मेल खाने वाले लोगों को सेगमेंट करता है, जबकि दूसरे (नकारात्मक) उदाहरण जैसे दिखने वाले उदाहरणों को दबाता है।

## विज़ुअल सेगमेंटेशन (PVS)

`POST https://serverless.roboflow.com/sam3/visual_segment`

PVS क्लिक या बॉक्स से इंगित एक विशिष्ट ऑब्जेक्ट को सेगमेंट करता है। इसे इंटरैक्टिव, human-in-the-loop मास्क परिष्कार के लिए उपयोग करें; जब आप किसी कॉन्सेप्ट के हर उदाहरण चाहते हों, तो PCS का उपयोग करें।

```python
import os
import requests

payload = {
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/people-walking.jpg"},
    "prompts": {
        "prompts": [
            {
                "points": [{"x": 1465, "y": 796, "positive": True}],
                "box": {"x": 1465, "y": 796, "width": 112, "height": 183},
            }
        ]
    },
    "multimask_output": False,
    "format": "json",
}

response = requests.post(
    "https://serverless.roboflow.com/sam3/visual_segment",
    params={"api_key": os.environ["ROBOFLOW_API_KEY"]},
    json=payload,
)
prediction = response.json()["predictions"][0]
print(prediction["confidence"], len(prediction["masks"]), "बहुभुज")
```

एक प्रॉम्प्ट में शामिल हो सकता है `बिंदु`, एक `बॉक्स`, या दोनों:

* `बिंदु` पूर्ण पिक्सेल निर्देशांक हैं। `"positive": true` क्लिक किए गए क्षेत्र को शामिल करता है, `false` इसे बाहर करता है। मास्क को और परिष्कृत करने के लिए अधिक बिंदु जोड़ें।
* `बॉक्स` केंद्र-आधारित निर्देशांक का उपयोग करता है: `x`, `y` बॉक्स का केंद्र है, PCS बॉक्स के विपरीत जो ऊपरी-बाएँ पर आधारित होते हैं।

प्रतिक्रिया में प्रॉम्प्ट के लिए केवल सबसे अधिक विश्वसनीयता वाला मास्क होता है। `multimask_output` यह नियंत्रित करता है कि मॉडल कितने आंतरिक मास्क प्रस्ताव उत्पन्न करता है (true होने पर तीन), लेकिन प्रतिक्रिया के लिए हमेशा सर्वोत्तम प्रस्ताव चुना जाता है।

{% hint style="warning" %}
प्रति अनुरोध एक प्रॉम्प्ट भेजें। एक PVS अनुरोध में कई प्रॉम्प्ट वर्तमान में केवल एक भविष्यवाणी लौटाते हैं।
{% endhint %}

OpenCV का उपयोग करने वाले इंटरैक्टिव डेमो के लिए, यह देखें [GitHub Gist](https://gist.github.com/Erol444/4cbc33c6ac52d83c63f6f9d86ca8a7a4), जिसका उपयोग इस वीडियो में किया गया था:

{% embed url="<https://www.youtube.com/watch?v=01xrBzqHZ6c>" %}

## इन्फरेंस गति

लेटेंसी मापी गई [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1x NVIDIA L4 पर, बैच साइज़ 1, वार्मअप के बाद औसत।

<table data-search="false"><thead><tr><th>मॉडल</th><th>लेटेंसी (मि.से.)</th></tr></thead><tbody><tr><td><code>sam3</code></td><td>251.4</td></tr></tbody></table>

एकल टेक्स्ट प्रॉम्प्ट से कॉन्सेप्ट सेगमेंटेशन के साथ मापा गया।

## एंडपॉइंट

## SAM3 PCS (promptable concept segmentation)

> \*\*Concept Segmentation (Text Prompts)\*\*\
> \
> Allows you to segment objects using text prompts.\
> \
> \*\*Image Input\*\*: The \`image\` field accepts either:\
> \- \`{"type": "url", "value": "\<IMAGE\_URL>"}\` - A publicly accessible image URL\
> \- \`{"type": "base64", "value": "\<BASE64\_DATA>"}\` - Base64 encoded image data\
> \
> &#x20;\*\*Prompts\*\*: Each prompt in the \`prompts\` array should have \`type: "text"\` and a \`text\` field with the object description.

```json
{"openapi":"3.1.0","info":{"title":"Roboflow SAM3 API","version":"0.64.4"},"servers":[{"url":"https://serverless.roboflow.com"}],"paths":{"/sam3/concept_segment":{"post":{"summary":"SAM3 PCS (promptable concept segmentation)","description":"**Concept Segmentation (Text Prompts)**\n\nAllows you to segment objects using text prompts.\n\n**Image Input**: The `image` field accepts either:\n- `{\"type\": \"url\", \"value\": \"<IMAGE_URL>\"}` - A publicly accessible image URL\n- `{\"type\": \"base64\", \"value\": \"<BASE64_DATA>\"}` - Base64 encoded image data\n\n **Prompts**: Each prompt in the `prompts` array should have `type: \"text\"` and a `text` field with the object description.","operationId":"sam3_segment_image_sam3_concept_segment_post","parameters":[{"name":"api_key","in":"query","required":true,"schema":{"type":"string","title":"API Key"},"description":"Your Roboflow API Key. Get one at https://app.roboflow.com/settings/api"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Sam3SegmentationRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Sam3SegmentationResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"Sam3SegmentationRequest":{"properties":{"image":{"$ref":"#/components/schemas/InferenceRequestImage","description":"The image to be segmented."},"prompts":{"items":{"$ref":"#/components/schemas/Sam3Prompt"},"type":"array","minItems":1,"title":"Prompts","description":"List of prompts (text and/or visual)"},"format":{"type":"string","title":"Format","description":"One of 'polygon', 'rle'","default":"polygon"},"image_id":{"type":"string","title":"Image Id","description":"Optional ID for caching embeddings."},"output_prob_thresh":{"type":"number","title":"Output Prob Thresh","description":"Score threshold for outputs.","default":0.5},"model_id":{"type":"string","title":"Model Id","description":"The model ID of SAM3. Use 'sam3/sam3_final' to target the generic base model.","default":"sam3/sam3_final"},"nms_iou_threshold":{"type":"number","title":"Nms Iou Threshold","description":"IoU threshold for cross-prompt NMS. If not set, NMS is disabled. Must be in [0.0, 1.0] when set."}},"type":"object","required":["image","prompts"],"title":"Sam3SegmentationRequest"},"InferenceRequestImage":{"properties":{"type":{"type":"string","title":"Type","description":"The type of image data provided, one of `url`, `base64`"},"value":{"type":"string","title":"Value","description":"Image data corresponding to the image type, if type = 'url' then value is a string containing the url of an image, else if type = 'base64' then value is a string containing base64 encoded image data."}},"type":"object","required":["type"],"title":"InferenceRequestImage","description":"Image data for inference request.\n\nAttributes:\n    type (str): The type of image data provided, one of 'url', 'base64', or 'numpy'.\n    value (Optional[Any]): Image data corresponding to the image type."},"Sam3Prompt":{"properties":{"type":{"type":"string","title":"Type","description":"Hint: `text` or `visual`"},"text":{"type":"string","title":"Text","description":"Text prompt describing the object to segment"},"output_prob_thresh":{"type":"number","title":"Output Prob Thresh","description":"Score threshold for this prompt's outputs. Overrides request-level threshold if set."},"boxes":{"items":{"anyOf":[{"$ref":"#/components/schemas/Box"},{"$ref":"#/components/schemas/BoxXYXY"}]},"type":"array","title":"Boxes","description":"Absolute pixel boxes as either XYWH or XYXY entries"},"box_labels":{"items":{"anyOf":[{"type":"integer"},{"type":"boolean"}]},"type":"array","title":"Box Labels","description":"List of 0/1 or booleans for boxes"}},"type":"object","required":["type"],"title":"Sam3Prompt","description":"Unified prompt that can contain text and/or geometry. Absolute pixel coordinates are used for boxes."},"Sam3SegmentationResponse":{"properties":{"prompt_results":{"items":{"$ref":"#/components/schemas/Sam3PromptResult"},"type":"array","title":"Prompt Results","description":"Results for each prompt in the request"},"time":{"type":"number","title":"Time","description":"The time in seconds it took to produce the segmentation including preprocessing"}},"type":"object","required":["prompt_results","time"],"title":"Sam3SegmentationResponse"},"Sam3PromptResult":{"properties":{"prompt_index":{"type":"integer","title":"Prompt Index","description":"Index of the prompt this result corresponds to"},"echo":{"$ref":"#/components/schemas/Sam3PromptEcho","description":"Echo of the original prompt for reference"},"predictions":{"items":{"$ref":"#/components/schemas/Sam3SegmentationPrediction"},"type":"array","title":"Predictions","description":"Segmentation predictions for this prompt"}},"type":"object","required":["prompt_index","predictions"],"title":"Sam3PromptResult"},"Sam3PromptEcho":{"properties":{"prompt_index":{"type":"integer","title":"Prompt Index"},"type":{"type":"string","title":"Type","description":"The prompt type (`text` or `visual`)"},"text":{"type":"string","title":"Text","description":"The text prompt if type is `text`"},"num_boxes":{"type":"integer","title":"Num Boxes","description":"Number of bounding boxes in the prompt"}},"type":"object","title":"Sam3PromptEcho"},"Sam3SegmentationPrediction":{"properties":{"format":{"type":"string","title":"Format","description":"The format of the mask data, either `polygon` or `rle`"},"confidence":{"type":"number","title":"Confidence","description":"Confidence score for this prediction"},"masks":{"items":{"items":{"items":{"type":"number"},"type":"array","minItems":2,"maxItems":2},"type":"array"},"type":"array","title":"Masks","description":"Array of polygons, each polygon is an array of [x, y] coordinate points"}},"type":"object","required":["format","confidence","masks"],"title":"Sam3SegmentationPrediction"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}}}
```

## SAM3 PVS (promptable visual segmentation)

> \*\*Interactive Segmentation (SAM 2 Style)\*\*\
> \
> SAM 3 also supports interactive segmentation using points and boxes.\
> \
> \*\*Image Input\*\*: The \`image\` field accepts either:\
> \- \`{"type": "url", "value": "\<IMAGE\_URL>"}\` - A publicly accessible image URL\
> \- \`{"type": "base64", "value": "\<BASE64\_DATA>"}\` - Base64 encoded image data\
> \
> \> \*\*Note\*\*: NumPy arrays are NOT supported on the serverless API. Use URL or base64 encoding only.\
> \
> \*\*Prompts\*\*: Support point-based prompts with positive/negative clicks for interactive segmentation.

```json
{"openapi":"3.1.0","info":{"title":"Roboflow SAM3 API","version":"0.64.4"},"servers":[{"url":"https://serverless.roboflow.com"}],"paths":{"/sam3/visual_segment":{"post":{"summary":"SAM3 PVS (promptable visual segmentation)","description":"**Interactive Segmentation (SAM 2 Style)**\n\nSAM 3 also supports interactive segmentation using points and boxes.\n\n**Image Input**: The `image` field accepts either:\n- `{\"type\": \"url\", \"value\": \"<IMAGE_URL>\"}` - A publicly accessible image URL\n- `{\"type\": \"base64\", \"value\": \"<BASE64_DATA>\"}` - Base64 encoded image data\n\n> **Note**: NumPy arrays are NOT supported on the serverless API. Use URL or base64 encoding only.\n\n**Prompts**: Support point-based prompts with positive/negative clicks for interactive segmentation.","operationId":"sam3_visual_segment_sam3_visual_segment_post","parameters":[{"name":"api_key","in":"query","required":true,"schema":{"type":"string","title":"API Key"},"description":"Your Roboflow API Key. Get one at https://app.roboflow.com/settings/api"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Sam2SegmentationRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Sam2SegmentationResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"Sam2SegmentationRequest":{"properties":{"image":{"$ref":"#/components/schemas/InferenceRequestImage","description":"The image to be segmented."},"image_id":{"type":"string","title":"Image Id","description":"The ID of the image to be segmented used to retrieve cached embeddings. If an embedding is cached, it will be used instead of generating a new embedding. If no embedding is cached, a new embedding will be generated and cached."},"prompts":{"$ref":"#/components/schemas/Sam2PromptSet","description":"A list of prompts for masks to predict. Each prompt can include a bounding box and / or a set of postive or negative points."},"format":{"type":"string","title":"Format","description":"The format of the response. Must be one of 'json', 'rle', or 'binary'. If binary, masks are returned as binary numpy arrays. If json, masks are converted to polygons. If rle, masks are converted to RLE format.","default":"json"},"sam2_version_id":{"type":"string","title":"Sam2 Version Id","description":"The version ID of SAM to be used for this request. Must be one of hiera_tiny, hiera_small, hiera_large, hiera_b_plus","default":"hiera_large"},"multimask_output":{"type":"boolean","title":"Multimask Output","description":"If true, the model will return three masks. For ambiguous input prompts (such as a single click), this will often produce better masks than a single prediction.","default":true},"save_logits_to_cache":{"type":"boolean","title":"Save Logits To Cache","description":"If True, saves the low-resolution logits to the cache for potential future use.","default":false},"load_logits_from_cache":{"type":"boolean","title":"Load Logits From Cache","description":"If True, attempts to load previously cached low-resolution logits for the given image and prompt set.","default":false}},"type":"object","required":["image"],"title":"Sam2SegmentationRequest","description":"SAM2 visual segmentation request."},"InferenceRequestImage":{"properties":{"type":{"type":"string","title":"Type","description":"The type of image data provided, one of `url`, `base64`"},"value":{"type":"string","title":"Value","description":"Image data corresponding to the image type, if type = 'url' then value is a string containing the url of an image, else if type = 'base64' then value is a string containing base64 encoded image data."}},"type":"object","required":["type"],"title":"InferenceRequestImage","description":"Image data for inference request.\n\nAttributes:\n    type (str): The type of image data provided, one of 'url', 'base64', or 'numpy'.\n    value (Optional[Any]): Image data corresponding to the image type."},"Sam2SegmentationResponse":{"properties":{"prompt_results":{"items":{"$ref":"#/components/schemas/Sam2PromptResult"},"type":"array","title":"Prompt Results","description":"Results for each prompt in the request"},"time":{"type":"number","title":"Time","description":"The time in seconds it took to produce the segmentation including preprocessing"}},"type":"object","required":["prompt_results","time"],"title":"Sam2SegmentationResponse"},"Sam2PromptResult":{"properties":{"prompt_index":{"type":"integer","title":"Prompt Index","description":"Index of the prompt this result corresponds to"},"predictions":{"items":{"$ref":"#/components/schemas/Sam2SegmentationPrediction"},"type":"array","title":"Predictions","description":"Segmentation predictions for this prompt"}},"type":"object","required":["prompt_index","predictions"],"title":"Sam2PromptResult"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}}}
```

## Inference (स्व-होस्टेड) के साथ उपयोग करें

SAM3 आपके अपने हार्डवेयर पर भी चल सकता है, या तो इसे निम्न के साथ इन-प्रोसेस लोड करके [`inference`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) पैकेज, या GPU कंटेनर से सर्व किया जा सकता है।

### Docker में चलाएँ

```bash
docker run -it --rm -p 9001:9001 --gpus=all roboflow/inference-server:latest
```

सर्वर वही `/sam3/concept_segment` और `/sam3/visual_segment` ऊपर दस्तावेज़ित एंडपॉइंट्स यहाँ `http://localhost:9001`.

### Python में मॉडल लोड करें

```bash
pip install "inference-gpu[sam3]"
```

```python
import os

os.environ["API_KEY"] = "YOUR_API_KEY"

from inference.core.entities.requests.sam3 import Sam3Prompt
from inference.models.sam3 import SegmentAnything3

model = SegmentAnything3(model_id="sam3/sam3_final")

prompts = [
    # किसी कॉन्सेप्ट के हर उदाहरण को सेगमेंट करें
    Sam3Prompt(type="text", text="व्यक्ति"),
    # एक उदाहरण ऑब्जेक्ट पर बॉक्स बनाएं और हर समान उदाहरण को सेगमेंट करें.
    # box_labels: 1 = सकारात्मक उदाहरण, 0 = नकारात्मक उदाहरण.
    Sam3Prompt(
        type="visual",
        boxes=[Sam3Prompt.Box(x=1409, y=705, width=112, height=183)],
        box_labels=[1],
    ),
]

response = model.segment_image(
    image="path/to/your/image.jpg",
    prompts=prompts,
    output_prob_thresh=0.5,
    format="polygon",  # या "rle", "json"
)

for prompt_result in response.prompt_results:
    print(prompt_result.echo.text, len(prompt_result.predictions), "उदाहरण")
```

वज़न पहली बार उपयोग पर स्वतः डाउनलोड हो जाते हैं।

### Python में इंटरैक्टिव सेगमेंटेशन

`Sam3ForInteractiveImageSegmentation` मानव-इन-द-लूप मास्क परिष्कार के लिए SAM2-शैली के बिंदु और बॉक्स इंटरफ़ेस को लागू करता है:

```python
from inference.models.sam3 import Sam3ForInteractiveImageSegmentation

model = Sam3ForInteractiveImageSegmentation(model_id="sam3/sam3_final")

embedding, img_shape, image_id = model.embed_image(image="path/to/image.jpg")

masks, scores, logits = model.segment_image(
    image_id=image_id,
    prompts={"points": [{"x": 500, "y": 400, "positive": True}]},
)
```

## वर्कफ़्लोज़ में उपयोग करें

में दो SAM3 छवि ब्लॉक उपलब्ध हैं [वर्कफ़्लोज़](https://docs.roboflow.com/workflows):

* **SAM 3** कॉन्सेप्ट सेगमेंटेशन चलाता है। जिन कक्षाओं को आप चाहते हैं उन्हें यहाँ दर्ज करें `class_names` (उदाहरण के लिए `["व्यक्ति", "वाहन"]`) और यह ब्लॉक इंस्टेंस सेगमेंटेशन भविष्यवाणियाँ आउटपुट करता है, जिन्हें अन्य चरण उपयोग कर सकते हैं।
* **SAM 3 इंटरैक्टिव** प्रॉम्प्ट-आधारित विज़ुअल सेगमेंटेशन चलाता है। लेबल किए गए बिंदु प्रदान करें (प्रकार `labeled_points`), उदाहरण के लिए `[{"x": 320, "y": 240, "positive": true}]`, और वैकल्पिक रूप से किसी अन्य मॉडल की detections को `boxes` फ़ील्ड से जोड़ें। प्रत्येक बॉक्स एक अलग प्रॉम्प्ट बन जाता है, और उसका class name पूर्वानुमानित मास्क को भेजा जाता है।

### वीडियो ट्रैकिंग

यह **SAM3 वीडियो ट्रैकर** ब्लॉक (`roboflow_core/sam3_video@v1`) SAM3 के स्ट्रीमिंग कॉन्सेप्ट ट्रैकर को फ्रेम दर फ्रेम चलाता है। आप कॉन्सेप्ट को टेक्स्ट के रूप में यहाँ प्रदान करते हैं `class_names`में, और मॉडल हर फ्रेम पर संयुक्त डिटेक्शन और ट्रैकिंग चलाता है। किसी कॉन्सेप्ट से मेल खाने वाले ऑब्जेक्ट एक स्थिर `tracker_id`रखते हैं, और, detector-seeded tracking के विपरीत, जो ऑब्जेक्ट बीच में दृश्य में आते हैं उन्हें बिना दोबारा प्रॉम्प्ट किए और बिना किसी upstream detection model के स्वतः पकड़ लिया जाता है। प्रत्येक मास्क अपने मेल खाते कॉन्सेप्ट को class name के रूप में और मॉडल के detection score को confidence के रूप में रखता है (फ़िल्टर करें `थ्रेशहोल्ड`, डिफ़ॉल्ट `0.5`).

* **स्टेटफुल और केवल लोकल।** प्रति एक ट्रैकिंग सत्र रखा जाता है `video_metadata.video_identifier`. ब्लॉक को चाहिए `WORKFLOWS_STEP_EXECUTION_MODE=local`, एक GPU, और एक स्थायी WebRTC सत्र।
* **कोई प्रॉम्प्ट शेड्यूलिंग नहीं।** कॉन्सेप्ट प्रॉम्प्ट प्रति सत्र एक बार पंजीकृत किए जाते हैं; सत्र केवल तब पुनः-seed किया जाता है जब स्ट्रीम पुनः आरंभ होती है या `class_names` बदलती है। detector-driven (box-prompted) वीडियो ट्रैकिंग के लिए, SAM2 Video Tracker ब्लॉक का उपयोग यहाँ करें [SAM2 पेज](/models/hi/supported-models/sam2.md), जो यह भी स्वीकार करता है `sam3trackervideo` के रूप में `model_id`.
* **मॉडल।** `model_id` डिफ़ॉल्ट रूप से `sam3video`, HuggingFace transformers का SAM3 वीडियो पोर्ट, जो फ्रेम-दर-फ्रेम स्ट्रीमिंग इंटरफ़ेस प्रदान करता है। मूल `sam3` पैकेज का वीडियो प्रेडिक्टर पूरा वीडियो पहले से मांगता है और लाइव स्ट्रीम के लिए उपयोग नहीं किया जा सकता।

```python
from inference_sdk import InferenceHTTPClient
from inference_sdk.webrtc import StreamConfig, VideoFileSource

WORKFLOW = {
    "version": "1.0",
    "inputs": [{"type": "InferenceImage", "name": "image"}],
    "steps": [
        {
            "type": "roboflow_core/sam3_video@v1",
            "name": "tracker",
            "images": "$inputs.image",
            "class_names": ["व्यक्ति", "forklift"],
            "threshold": 0.5,
        },
    ],
    "outputs": [
        {
            "type": "JsonField",
            "name": "predictions",
            "selector": "$steps.tracker.predictions",
        }
    ],
}

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="YOUR_API_KEY",
)

session = client.webrtc.stream(
    source=VideoFileSource("path/to/video.mp4"),
    workflow=WORKFLOW,
    config=StreamConfig(data_output=["predictions"]),
)

@session.on_data("predictions")
def handle_predictions(predictions, metadata):
    print(predictions)

session.run()
```

## SAM3-3D (बीटा)

SAM3-3D 2D छवि और मास्क को 3D एसेट्स में बदलता है: मेश और Gaussian splats।

{% hint style="warning" %}
SAM3-3D बीटा में है। यह केवल तब उपलब्ध है जब `SAM3_3D_OBJECTS_ENABLED` फ़्लैग सेट हो, 32 GB या अधिक VRAM वाले GPU की आवश्यकता हो, और यह यहाँ से चलता हो `inference` पैकेज या एक स्थानीय Inference सर्वर (यह Serverless Hosted API पर नहीं है)।
{% endhint %}

निर्भरताएँ इंस्टॉल करें (Python 3.10 अनुशंसित):

```bash
pip install --no-cache-dir --no-build-isolation -r requirements/requirements.sam3_3d.txt
```

या 3D-सक्षम GPU कंटेनर को बनाकर चलाएँ:

```bash
docker build -t roboflow/roboflow-inference-server-gpu:dev -f docker/dockerfiles/Dockerfile.onnx.gpu.3d .
docker run --gpus all -p 9001:9001 roboflow/roboflow-inference-server-gpu:dev
```

**इनपुट।** एक RGB छवि और `mask_input`, जो ऑब्जेक्ट क्षेत्रों को परिभाषित करता है। मास्क बाइनरी ऐरे के रूप में स्वीकार किए जाते हैं (`(H, W)` या `(N, H, W)`), COCO फ्लैट बहुभुज, बिंदु-युग्म बहुभुज, RLE डिक्ट, या एक `sv.Detections` SAM2 या किसी अन्य सेगमेंटेशन मॉडल से object.

**आउटपुट।** `mesh_glb` (संयुक्त दृश्य मेश, GLB), `gaussian_ply` (संयुक्त Gaussian splat, PLY), `ऑब्जेक्ट्स` (प्रति-ऑब्जेक्ट `mesh_glb`, `gaussian_ply`, और `मेटाडेटा` जिसमें घूर्णन, स्थानांतरण और स्केल शामिल है), और `समय`.

```python
import os

os.environ["SAM3_3D_OBJECTS_ENABLED"] = "true"
os.environ["SPARSE_ATTN_BACKEND"] = "flash_attn"
os.environ["ATTN_BACKEND"] = "flash_attn"

from inference import get_model
from inference.core.entities.requests.sam3_3d import Sam3_3D_Objects_InferenceRequest

model = get_model("sam3-3d-objects", api_key="YOUR_API_KEY")

request = Sam3_3D_Objects_InferenceRequest(
    image={"type": "file", "value": "image.jpg"},
    mask_input=mask_polygons,  # बहुभुज, बाइनरी मास्क, या RLE
)

response = model.infer_from_request(request)

if response.mesh_glb is not None:
    with open("out_mesh.glb", "wb") as f:
        f.write(response.mesh_glb)

for index, obj in enumerate(response.objects):
    if obj.gaussian_ply is not None:
        with open(f"out_object_{index}.ply", "wb") as f:
            f.write(obj.gaussian_ply)
```

सेट करना `SPARSE_ATTN_BACKEND` और `ATTN_BACKEND` को `flash_attn` पाइपलाइन को तेज़ करता है। Workflows में, SAM3-3D स्थानीय निष्पादन और यहाँ के माध्यम से दूरस्थ निष्पादन का समर्थन करता है `sam3_3d_infer()` क्लाइंट मेथड, या `/sam3_3d/infer` एंडपॉइंट।

## यह भी देखें

* [SAM2](/models/hi/supported-models/sam2.md) - बिंदु और बॉक्स द्वारा प्रेरित विभाजन, साथ ही डिटेक्टर-सीडेड वीडियो ट्रैकिंग।
* [सेगमेंट एनीथिंग (SAM)](/models/hi/supported-models/sam.md) - मूल एकल-वस्तु मॉडल।
