> 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

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

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

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

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

## ControlNet क्या है?

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

* **Canny** - किनारा पहचान
* **Depth** - 3D गहराई मानचित्र
* **Pose** - मानव मुद्राएँ
* **स्क्रिबल** - मोटे स्केच
* **विभाजन** - अर्थगत मास्क
* **लाइन आर्ट** - साफ़ रेखाएँ
* **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 ControlNet
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 ControlNet
wget https://huggingface.co/diffusers/controlnet-canny-sdxl-1.0/resolve/main/diffusion_pytorch_model.safetensors -O controlnet-canny-sdxl.safetensors
```

## Diffusers के साथ Python

### कैनी एज नियंत्रण

```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]
```

### स्क्रिबल/स्केच

```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]
```

## मल्टी-ControlNet

कई नियंत्रणों को संयोजित करें:

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

# कई ControlNet लोड करें
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
)

# कई ControlNet के साथ पाइपलाइन बनाएं
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 = 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 |
| स्क्रिबल  | स्केच, अवधारणाएँ       | 0.6-0.8 |
| लाइन आर्ट | चित्रण                 | 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     | \~5 सेकंड |
| एकल 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) *वर्तमान दरों के लिए।*

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

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

## अगले चरण

* स्टेबल डिफ्यूजन वेबयूआई
* 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.
