> 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/controlnet-advanced.md).

# ControlNet

AI इमेज जनरेशन पर सटीक नियंत्रण के लिए ControlNet में महारत हासिल करें।

{% 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>`

## ControlNet क्या है?

ControlNet Stable Diffusion में सशर्त नियंत्रण जोड़ता है:

* **Canny** - एज डिटेक्शन
* **Depth** - 3D डेप्थ मैप
* **Pose** - मानव पोज़
* **Scribble** - मोटे स्केच
* **Segmentation** - सेमांटिक मास्क
* **Line Art** - साफ़ लाइनें
* **IP-Adapter** - स्टाइल ट्रांसफर

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

| कंट्रोल प्रकार   | न्यूनतम VRAM | अनुशंसित |
| ---------------- | ------------ | -------- |
| एकल ControlNet   | 8GB          | RTX 3070 |
| मल्टी ControlNet | 12GB         | RTX 3090 |
| SDXL ControlNet  | 16GB         | RTX 4090 |

## A1111 के साथ त्वरित डिप्लॉय

**कमांड:**

```bash
cd /workspace/stable-diffusion-webui && \
cd extensions && \
git clone https://github.com/Mikubill/sd-webui-controlnet && \
cd .. && \
python launch.py --listen --enable-insecure-extension-access
```

### मॉडल डाउनलोड करें

```bash
cd /workspace/stable-diffusion-webui/extensions/sd-webui-controlnet/models

# SD 1.5 ControlNets
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth
wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth

# SDXL ControlNets
wget https://huggingface.co/diffusers/controlnet-canny-sdxl-1.0/resolve/main/diffusion_pytorch_model.safetensors -O controlnet-canny-sdxl.safetensors
```

## Diffusers के साथ Python

### Canny एज कंट्रोल

```python
import torch
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from diffusers.utils import load_image
from controlnet_aux import CannyDetector
import cv2
import numpy as np

# ControlNet लोड करें
controlnet = ControlNetModel.from_pretrained(
    "lllyasviel/control_v11p_sd15_canny",
    torch_dtype=torch.float16
)

# पाइपलाइन लोड करें
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
)
pipe.to("cuda")
pipe.enable_model_cpu_offload()

# कंट्रोल इमेज तैयार करें
image = load_image("input.jpg")
canny = CannyDetector()
control_image = canny(image)

# जनरेट करें
output = pipe(
    prompt="एक खूबसूरत महिला बगीचे में, उच्च गुणवत्ता",
    negative_prompt="बदसूरत, धुंधला",
    image=control_image,
    num_inference_steps=30,
    controlnet_conditioning_scale=1.0
).images[0]

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

### डेप्थ कंट्रोल

```python
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from controlnet_aux import MidasDetector
import torch

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

pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

# डेप्थ मैप प्राप्त करें
depth_estimator = MidasDetector.from_pretrained("lllyasviel/Annotators")
depth_image = depth_estimator(image)

# डेप्थ के साथ जनरेट करें
output = pipe(
    prompt="एक भविष्यवादी शहर, साइंस-फिक्शन, विस्तृत",
    image=depth_image,
    num_inference_steps=30
).images[0]
```

### OpenPose (मानव पोज़)

```python
from controlnet_aux import OpenposeDetector

# पोज़ प्राप्त करें
pose_detector = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
pose_image = pose_detector(image)

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

pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

output = pipe(
    prompt="एक बैलेरीना नाचते हुए, सुरुचिपूर्ण, स्टूडियो लाइटिंग",
    image=pose_image,
    num_inference_steps=30
).images[0]
```

### Scribble/Sketch

```python
from controlnet_aux import HEDdetector

# स्क्रिबल के रूप में एजेस का पता लगाना
hed = HEDdetector.from_pretrained("lllyasviel/Annotators")
scribble_image = hed(image, scribble=True)

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

pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

output = pipe(
    prompt="एक विस्तृत लैंडस्केप पेंटिंग",
    image=scribble_image,
    num_inference_steps=30
).images[0]
```

## मल्टी-ContolNet

एकाधिक नियंत्रणों को संयोजित करें:

```python
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
import torch

# कई ControlNets लोड करें
controlnet_canny = ControlNetModel.from_pretrained(
    "lllyasviel/control_v11p_sd15_canny",
    torch_dtype=torch.float16
)

controlnet_depth = ControlNetModel.from_pretrained(
    "lllyasviel/control_v11f1p_sd15_depth",
    torch_dtype=torch.float16
)

# कई ControlNets के साथ पाइपलाइन बनाएं
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=[controlnet_canny, controlnet_depth],
    torch_dtype=torch.float16
).to("cuda")

# कई नियंत्रणों के साथ जनरेट करें
output = pipe(
    prompt="एक सुंदर पोर्ट्रेट",
    image=[canny_image, depth_image],
    controlnet_conditioning_scale=[1.0, 0.8],  # वज़न समायोजित करें
    num_inference_steps=30
).images[0]
```

## SDXL ControlNet

```python
from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel
from controlnet_aux import CannyDetector
import torch

# SDXL ControlNet लोड करें
controlnet = ControlNetModel.from_pretrained(
    "diffusers/controlnet-canny-sdxl-1.0",
    torch_dtype=torch.float16
)

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

# canny इमेज तैयार करें
canny = CannyDetector()
control_image = canny(image, low_threshold=100, high_threshold=200)

output = pipe(
    prompt="एक पेशेवर फ़ोटो, विस्तृत, 8k",
    image=control_image,
    controlnet_conditioning_scale=0.5,
    num_inference_steps=30
).images[0]
```

## IP-Adapter (स्टाइल ट्रांसफर)

```python
from diffusers import StableDiffusionPipeline
from transformers import CLIPVisionModelWithProjection
import torch

# IP-Adapter लोड करें
pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16
).to("cuda")

pipe.load_ip_adapter(
    "h94/IP-Adapter",
    subfolder="models",
    weight_name="ip-adapter_sd15.bin"
)

pipe.set_ip_adapter_scale(0.6)

# स्टाइल संदर्भ इमेज
style_image = load_image("style_reference.jpg")

output = pipe(
    prompt="एक कुर्सी पर बैठा बिल्ली",
    ip_adapter_image=style_image,
    num_inference_steps=30
).images[0]
```

## प्रीप्रोसेसर

सभी उपलब्ध प्रीप्रोसेसर:

```python
from controlnet_aux import (
    CannyDetector,           # एज डिटेक्शन
    HEDdetector,             # सॉफ्ट एज/स्क्रिबल
    MidasDetector,           # डेप्थ अनुमान
    OpenposeDetector,        # मानव पोज़
    MLSDdetector,            # लाइन डिटेक्शन
    LineartDetector,         # लाइन आर्ट
    LineartAnimeDetector,    # एनीमे लाइन आर्ट
    NormalBaeDetector,       # नॉर्मल मैप्स
    ContentShuffleDetector,  # कंटेंट शफल
    ZoeDetector,             # बेहतर डेप्थ
    MediapipeFaceDetector,   # फेस मैश
)

# उदाहरण उपयोग
canny = CannyDetector()
canny_image = canny(image, low_threshold=100, high_threshold=200)

depth = MidasDetector.from_pretrained("lllyasviel/Annotators")
depth_image = depth(image)

pose = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
pose_image = pose(image, hand_and_face=True)
```

## कंट्रोल वज़न

प्रत्येक ControlNet के प्रभाव को समायोजित करें:

```python

# पूर्ण नियंत्रण
output = pipe(..., controlnet_conditioning_scale=1.0)

# आंशिक नियंत्रण (अधिक रचनात्मक स्वतंत्रता)
output = pipe(..., controlnet_conditioning_scale=0.5)

# बहुत हल्का मार्गदर्शन
output = pipe(..., controlnet_conditioning_scale=0.3)
```

### प्रति-स्टेप कंट्रोल

```python

# केवल कुछ चरणों के दौरान नियंत्रण
output = pipe(
    prompt="...",
    image=control_image,
    controlnet_conditioning_scale=1.0,
    control_guidance_start=0.0,  # शुरुआत में शुरू करें
    control_guidance_end=0.5,    # चरणों के 50% पर रोकें
    num_inference_steps=30
).images[0]
```

## ControlNet के साथ इनपेंट

```python
from diffusers import StableDiffusionControlNetInpaintPipeline, ControlNetModel
import torch

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

pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

output = pipe(
    prompt="एक लाल स्पोर्ट्स कार",
    image=init_image,
    mask_image=mask,
    control_image=canny_image,
    num_inference_steps=30
).images[0]
```

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

```python
import os
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from controlnet_aux import CannyDetector
from PIL import Image
import torch

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

pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

canny = CannyDetector()

input_dir = "./inputs"
output_dir = "./outputs"
os.makedirs(output_dir, exist_ok=True)

prompt = "खूबसूरत लैंडस्केप पेंटिंग, विस्तृत, आर्टिस्टिक"

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

        output = pipe(
            prompt=prompt,
            image=control_image,
            num_inference_steps=30
        ).images[0]

        output.save(os.path.join(output_dir, f"cn_{filename}"))
```

## कंट्रोल प्रकार मार्गदर्शिका

| कंट्रोल  | उत्तम हेतु               | मजबूती  |
| -------- | ------------------------ | ------- |
| Canny    | आर्किटेक्चर, वस्तुएं     | 0.8-1.0 |
| Depth    | 3D दृश्यों, परिप्रेक्ष्य | 0.6-0.8 |
| Pose     | लोग, पात्र               | 0.8-1.0 |
| Scribble | स्केच, अवधारणाएँ         | 0.6-0.8 |
| Line Art | चित्रण                   | 0.7-0.9 |
| Softedge | सामान्य मार्गदर्शन       | 0.5-0.7 |
| Seg      | सीन संरचना               | 0.6-0.8 |

## प्रदर्शन

| सेटअप          | GPU      | रिज़ॉल्यूशन | समय  |
| -------------- | -------- | ----------- | ---- |
| सिंगल CN SD1.5 | RTX 3090 | 512x512     | \~3s |
| मल्टी CN SD1.5 | RTX 3090 | 512x512     | \~5s |
| सिंगल CN SDXL  | RTX 4090 | 1024x1024   | \~8s |

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

```python

# मेमोरी-इफिशिएंट अटेंशन सक्षम करें
pipe.enable_xformers_memory_efficient_attention()

# CPU ऑफलोड
pipe.enable_model_cpu_offload()

# अटेंशन स्लाइसिंग
pipe.enable_attention_slicing()
```

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

### कमज़ोर कंट्रोल प्रभाव

* बढ़ाएँ `controlnet_conditioning_scale`
* प्रीप्रोसेसर आउटपुट की गुणवत्ता जाँचें
* उच्च रेज़ोल्यूशन कंट्रोल इमेज का उपयोग करें

### आर्टिफैक्ट्स

* कंट्रोल स्केल घटाएँ
* सॉफ्ट प्रीप्रोसेसर का उपयोग करें (softedge बनाम canny)
* आर्टिफैक्ट्स के लिए नेगेटिव प्रॉम्प्ट जोड़ें

### VRAM समस्याएँ

* CPU ऑफलोड का उपयोग करें
* रिज़ॉल्यूशन घटाएँ
* एक समय में एक ControlNet का उपयोग करें

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

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

## अगले कदम

* Stable Diffusion WebUI
* ComfyUI वर्कफ़्लो
* [Kohya प्रशिक्षण](/guides/guides_v2-hi/training/kohya-training.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/controlnet-advanced.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.
