# InstantID

केवल एक संदर्भ फोटो का उपयोग करके किसी भी चेहरे की पहचान के साथ चित्र उत्पन्न करें।

{% 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)
   * यदि आवश्यक हो तो एनवायरनमेंट वेरिएबल जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**, या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट का इंतज़ार करें

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

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

## InstantID क्या है?

InstantID चेहरों की पहचान को संरक्षित करता है:

* किसी भी संदर्भ चेहरे का उपयोग करें
* शून्य-शॉट - किसी प्रशिक्षण की आवश्यकता नहीं
* किसी भी स्टाइल/प्रॉम्प्ट के साथ काम करता है
* LoRA प्रशिक्षण से बेहतर

## आवश्यकताएँ

| मोड           | VRAM  | अनुशंसित |
| ------------- | ----- | -------- |
| बेसिक         | 12GB  | RTX 4080 |
| उच्च गुणवत्ता | 16GB  | RTX 4090 |
| पोज़ के साथ   | 16GB+ | RTX 4090 |

## त्वरित तैनाती

**Docker इमेज:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-devel
```

**पोर्ट:**

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

**कमांड:**

```bash
pip install diffusers transformers accelerate opencv-python insightface onnxruntime-gpu && \
huggingface-cli download InstantX/InstantID --local-dir ./checkpoints && \
python instantid_app.py
```

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

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

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

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

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

```bash
pip install diffusers transformers accelerate
pip install opencv-python insightface onnxruntime-gpu
pip install huggingface_hub

# मॉडल डाउनलोड करें
huggingface-cli download InstantX/InstantID --local-dir ./checkpoints
```

## मूल उपयोग

```python
import torch
import cv2
import numpy as np
from PIL import Image
from diffusers import StableDiffusionXLPipeline, DDIMScheduler
from insightface.app import FaceAnalysis

# फ़ेस एनालाइज़र इनिशियलाइज़ करें
app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider'])
app.prepare(ctx_id=0, det_size=(640, 640))

# पाइपलाइन लोड करें
pipe = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16
).to("cuda")

# InstantID घटक लोड करें
from diffusers import ControlNetModel

controlnet = ControlNetModel.from_pretrained(
    "./checkpoints/ControlNetModel",
    torch_dtype=torch.float16
)

# चेहरे के लिए IP-Adapter लोड करें
pipe.load_ip_adapter(
    "./checkpoints",
    subfolder="",
    weight_name="ip-adapter.bin"
)

# संदर्भ चेहरे को प्रोसेस करें
face_image = cv2.imread("reference_face.jpg")
faces = app.get(face_image)
face_emb = faces[0].normed_embedding

# चेहरे की पहचान के साथ जेनरेट करें
image = pipe(
    prompt="portrait of a person as an astronaut, space background",
    negative_prompt="ugly, blurry, low quality",
    ip_adapter_image_embeds=[torch.tensor(face_emb).unsqueeze(0)],
    num_inference_steps=30,
    guidance_scale=7.5
).images[0]

image.save("output.png")
```

## Diffusers पाइपलाइन का उपयोग करना

```python
from diffusers import StableDiffusionXLInstantIDPipeline, DDIMScheduler
from insightface.app import FaceAnalysis
import torch
import cv2

# फेस एनालाइज़र लोड करें
app = FaceAnalysis(name='antelopev2', providers=['CUDAExecutionProvider'])
app.prepare(ctx_id=0)

# पाइपलाइन लोड करें
pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    controlnet="./checkpoints/ControlNetModel",
    torch_dtype=torch.float16
).to("cuda")

pipe.load_ip_adapter_instantid("./checkpoints/ip-adapter.bin")

# फेस एम्बेडिंग प्राप्त करें
face_image = cv2.imread("face.jpg")
face_info = app.get(face_image)[0]

face_emb = face_info.normed_embedding
face_kps = face_info.kps

# जनरेट करें
image = pipe(
    prompt="watercolor portrait painting, artistic",
    face_emb=face_emb,
    face_kps=face_kps,
    num_inference_steps=30
).images[0]

image.save("portrait.png")
```

## स्टाइल उदाहरण

### व्यावसायिक हेडशॉट

```python
prompt = "professional corporate headshot, studio lighting, gray background, business attire"
negative = "cartoon, anime, illustration, blurry"
```

### कलात्मक पोर्ट्रेट

```python
prompt = "oil painting portrait in the style of Rembrandt, dramatic lighting, museum quality"
negative = "photo, realistic, modern"
```

### फैंटेसी कैरेक्टर

```python
prompt = "fantasy elf character, pointed ears, magical forest background, ethereal lighting"
negative = "human ears, modern clothing, realistic"
```

### एनीमे स्टाइल

```python
prompt = "anime character portrait, studio ghibli style, detailed, beautiful"
negative = "realistic, photo, 3d render"
```

## पोज़ कंट्रोल के साथ

```python
from diffusers.utils import load_image

# पोज़ संदर्भ लोड करें
pose_image = load_image("pose_reference.jpg")

# चेहरा और पोज़ दोनों के साथ जेनरेट करें
image = pipe(
    prompt="person in action pose, dynamic, high quality",
    face_emb=face_emb,
    face_kps=face_kps,
    image=pose_image,  # पोज़ संदर्भ
    controlnet_conditioning_scale=0.8,
    num_inference_steps=30
).images[0]
```

## Gradio इंटरफ़ेस

```python
import gradio as gr
import torch
import cv2
import numpy as np
from diffusers import StableDiffusionXLInstantIDPipeline
from insightface.app import FaceAnalysis

app = FaceAnalysis(name='antelopev2', providers=['CUDAExecutionProvider'])
app.prepare(ctx_id=0)

pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    controlnet="./checkpoints/ControlNetModel",
    torch_dtype=torch.float16
).to("cuda")

pipe.load_ip_adapter_instantid("./checkpoints/ip-adapter.bin")

def generate(face_image, prompt, negative_prompt, strength, steps):
    # cv2 फॉर्मेट में कनवर्ट करें
    face_cv = cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR)

    # फेस सूचना प्राप्त करें
    faces = app.get(face_cv)
    if len(faces) == 0:
        return None, "No face detected!"

    face_info = faces[0]
    face_emb = face_info.normed_embedding
    face_kps = face_info.kps

    # जनरेट करें
    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        face_emb=face_emb,
        face_kps=face_kps,
        ip_adapter_scale=strength,
        num_inference_steps=steps
    ).images[0]

    return image, "Success!"

demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.Image(type="pil", label="Reference Face"),
        gr.Textbox(label="Prompt", value="professional portrait"),
        gr.Textbox(label="Negative Prompt", value="ugly, blurry"),
        gr.Slider(0.1, 1.0, value=0.8, label="Identity Strength"),
        gr.Slider(10, 50, value=30, step=1, label="Steps")
    ],
    outputs=[
        gr.Image(label="Generated Image"),
        gr.Textbox(label="Status")
    ],
    title="InstantID - Identity Preserving Generation"
)

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

## बैच फेस स्वैप

```python
import os
from pathlib import Path

def batch_generate(face_image_path, prompts, output_dir):
    # चेहरा लोड करें
    face_cv = cv2.imread(face_image_path)
    face_info = app.get(face_cv)[0]
    face_emb = face_info.normed_embedding
    face_kps = face_info.kps

    os.makedirs(output_dir, exist_ok=True)

    for i, prompt in enumerate(prompts):
        print(f"Generating {i+1}/{len(prompts)}: {prompt[:50]}...")

        image = pipe(
            prompt=prompt,
            negative_prompt="ugly, blurry, deformed",
            face_emb=face_emb,
            face_kps=face_kps,
            num_inference_steps=30
        ).images[0]

        image.save(f"{output_dir}/output_{i:03d}.png")

# उपयोग
prompts = [
    "astronaut in space suit, Earth background",
    "medieval knight in armor",
    "scientist in laboratory",
    "chef in restaurant kitchen",
    "athlete on sports field"
]

batch_generate("my_face.jpg", prompts, "./outputs")
```

## पहचान शक्ति नियंत्रण

```python

# कम शक्ति - अधिक स्टाइल, कम पहचान
image_stylized = pipe(
    prompt=prompt,
    face_emb=face_emb,
    ip_adapter_scale=0.4,  # Low
    num_inference_steps=30
).images[0]

# अधिक शक्ति - अधिक पहचान, कम स्टाइल
image_faithful = pipe(
    prompt=prompt,
    face_emb=face_emb,
    ip_adapter_scale=0.9,  # High
    num_inference_steps=30
).images[0]
```

## मेमोरी अनुकूलन

```python

# अनुकूलन सक्षम करें
pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing()

# या बहुत कम VRAM के लिए क्रमिक ऑफलोड का उपयोग करें
pipe.enable_sequential_cpu_offload()
```

## प्रदर्शन

| मोड         | GPU      | प्रति छवि समय |
| ----------- | -------- | ------------- |
| बेसिक       | RTX 4090 | \~8s          |
| पोज़ के साथ | RTX 4090 | \~12s         |
| बेसिक       | RTX 3090 | \~15s         |
| बेसिक       | A100     | \~5s          |

## समस्याओं का निवारण

### कोई चेहरा नहीं मिला

* सुनिश्चित करें कि चेहरा स्पष्ट रूप से दिखाई दे
* संदर्भ छवि में अच्छी रोशनी
* चेहरा सामने की ओर होना चाहिए

### पहचान संरक्षित नहीं हुई

* ip\_adapter\_scale बढ़ाएँ
* स्पष्ट संदर्भ फोटो का उपयोग करें
* अत्यधिक कोणों से बचें

### शैली लागू नहीं हुई

* ip\_adapter\_scale घटाएँ
* और अधिक वर्णनात्मक प्रॉम्प्ट
* guidance\_scale बढ़ाएँ

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

सामान्य 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) *वर्तमान दरों के लिए।*

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

* उपयोग करें **स्पॉट** लचीले वर्कलोड के लिए मार्केट (अक्सर 30-50% सस्ता)
* भुगतान करें **CLORE** टोकन के साथ
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले कदम

* [IP-Adapter](/guides/guides_v2-hi/face-and-identity/ip-adapter.md) - इमेज प्रॉम्प्टिंग
* Stable Diffusion WebUI - InstantID एक्सटेंशन
* [ControlNet](/guides/guides_v2-hi/image-processing/controlnet-advanced.md) - पोज़ कंट्रोल


---

# Agent Instructions: 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:

```
GET https://docs.clore.ai/guides/guides_v2-hi/face-and-identity/instantid.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
