> 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/training/dreambooth.md).

# DreamBooth

Clore.ai GPUs पर DreamBooth के साथ कस्टम इमेज मॉडल ट्रेन करें

विशिष्ट विषयों की छवियाँ生成 करने के लिए Stable Diffusion को प्रशिक्षित करें.

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

## DreamBooth क्या है?

DreamBooth आपके चित्रों पर SD को फाइन-ट्यून करता है:

* 5-20 छवियों पर प्रशिक्षण करें
* अपने विषय की नई छवियाँ生成 करें
* कोई भी शैली या संदर्भ
* SD 1.5 और SDXL के साथ काम करता है

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

| मॉडल          | VRAM | प्रशिक्षण समय |
| ------------- | ---- | ------------- |
| SD 1.5        | 12GB | 15-30 मिनट    |
| SDXL          | 24GB | 30-60 मिनट    |
| SD 1.5 + LoRA | 8GB  | 10-20 मिनट    |

## त्वरित डिप्लॉय

**Docker इमेज:**

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

**पोर्ट:**

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

**कमांड:**

```bash
pip install diffusers transformers accelerate bitsandbytes && \
pip install xformers peft && \
python dreambooth_train.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 bitsandbytes xformers peft
```

## प्रशिक्षण डेटा तैयार करें

1. अपने विषय की 5-20 छवियाँ एकत्र करें
2. चेहरे/विषय के अनुसार क्रॉप करें
3. 512x512 में आकार बदलें (या SDXL के लिए 1024x1024)
4. यदि आवश्यक हो तो पृष्ठभूमि हटाएँ

```python
from PIL import Image
import os

def prepare_images(input_dir, output_dir, size=512):
    os.makedirs(output_dir, exist_ok=True)

    for filename in os.listdir(input_dir):
        if filename.endswith(('.jpg', '.png', '.jpeg')):
            img = Image.open(os.path.join(input_dir, filename))
            img = img.convert('RGB')

            # केंद्र से वर्गाकार क्रॉप करें
            min_dim = min(img.size)
            left = (img.width - min_dim) // 2
            top = (img.height - min_dim) // 2
            img = img.crop((left, top, left + min_dim, top + min_dim))

            # आकार बदलें
            img = img.resize((size, size), Image.LANCZOS)
            img.save(os.path.join(output_dir, filename))

prepare_images("./raw_photos", "./training_data")
```

## LoRA के साथ DreamBooth (अनुशंसित)

स्मृति-कुशल प्रशिक्षण:

```python
from diffusers import StableDiffusionPipeline, DDPMScheduler
from diffusers.loaders import LoraLoaderMixin
import torch

# प्रशिक्षण स्क्रिप्ट
from accelerate import Accelerator
from diffusers import AutoencoderKL, UNet2DConditionModel
from transformers import CLIPTextModel, CLIPTokenizer
from peft import LoraConfig, get_peft_model

# मॉडल लोड करें
model_id = "runwayml/stable-diffusion-v1-5"
tokenizer = CLIPTokenizer.from_pretrained(model_id, subfolder="tokenizer")
text_encoder = CLIPTextModel.from_pretrained(model_id, subfolder="text_encoder")
vae = AutoencoderKL.from_pretrained(model_id, subfolder="vae")
unet = UNet2DConditionModel.from_pretrained(model_id, subfolder="unet")

# UNet में LoRA जोड़ें
lora_config = LoraConfig(
    r=8,
    lora_alpha=32,
    target_modules=["to_q", "to_k", "to_v", "to_out.0"],
    lora_dropout=0.1,
)

unet = get_peft_model(unet, lora_config)
```

## diffusers प्रशिक्षण स्क्रिप्ट का उपयोग

```bash

# प्रशिक्षण स्क्रिप्ट्स क्लोन करें
git clone https://github.com/huggingface/diffusers
cd diffusers/examples/dreambooth

# आवश्यकताएँ इंस्टॉल करें
pip install -r requirements.txt

# LoRA के साथ प्रशिक्षण करें
accelerate launch train_dreambooth_lora.py \
    --pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5" \
    --instance_data_dir="./training_data" \
    --instance_prompt="sks व्यक्ति की एक तस्वीर" \
    --output_dir="./dreambooth_model" \
    --resolution=512 \
    --train_batch_size=1 \
    --gradient_accumulation_steps=1 \
    --learning_rate=1e-4 \
    --lr_scheduler="constant" \
    --lr_warmup_steps=0 \
    --max_train_steps=500 \
    --seed=42
```

## ट्रेनिंग पैरामीटर

| पैरामीटर           | अनुशंसित                  | प्रभाव                      |
| ------------------ | ------------------------- | --------------------------- |
| learning\_rate     | 1e-4 से 5e-6              | अधिक = तेज़, कम = स्थिर     |
| max\_train\_steps  | 400-1000                  | अधिक = बेहतर फिट            |
| train\_batch\_size | 1-2                       | अधिक के लिए अधिक VRAM चाहिए |
| resolution         | 512 (SD1.5) / 1024 (SDXL) | प्रशिक्षण आकार              |

## इंस्टेंस प्रॉम्प्ट

एक अद्वितीय पहचानकर्ता चुनें:

```bash

# अच्छे प्रॉम्प्ट
"sks व्यक्ति की एक फोटो"      # sks = अद्वितीय टोकन
"xyz कुत्ते की एक फोटो"
"abc कार की एक फोटो"

# टोकन (sks, xyz, abc) दुर्लभ होना चाहिए
```

## क्लास संरक्षण के साथ

ओवरफिटिंग रोकें:

```bash
accelerate launch train_dreambooth_lora.py \
    --pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5" \
    --instance_data_dir="./my_dog_photos" \
    --instance_prompt="sks कुत्ते की एक फोटो" \
    --class_data_dir="./regular_dog_photos" \
    --class_prompt="कुत्ते की एक फोटो" \
    --with_prior_preservation \
    --prior_loss_weight=1.0 \
    --num_class_images=200 \
    --output_dir="./dreambooth_dog" \
    --max_train_steps=800
```

## SDXL DreamBooth

```bash
accelerate launch train_dreambooth_lora_sdxl.py \
    --pretrained_model_name_or_path="stabilityai/stable-diffusion-xl-base-1.0" \
    --instance_data_dir="./training_data" \
    --instance_prompt="sks व्यक्ति की एक तस्वीर" \
    --output_dir="./dreambooth_sdxl" \
    --resolution=1024 \
    --train_batch_size=1 \
    --gradient_accumulation_steps=4 \
    --learning_rate=1e-4 \
    --max_train_steps=500 \
    --mixed_precision="fp16"
```

## प्रशिक्षित मॉडल का उपयोग

### LoRA लोड करें

```python
from diffusers import StableDiffusionPipeline
import torch

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

# अपने प्रशिक्षित LoRA को लोड करें
pipe.load_lora_weights("./dreambooth_model")

# जनरेट करें
image = pipe(
    "मंगल ग्रह पर अंतरिक्ष यात्री के रूप में sks व्यक्ति की एक फोटो",
    num_inference_steps=30,
    guidance_scale=7.5
).images[0]

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

### पूर्ण फाइन-ट्यून

```python
pipe = StableDiffusionPipeline.from_pretrained(
    "./dreambooth_model",
    torch_dtype=torch.float16
).to("cuda")

image = pipe("सूट में sks व्यक्ति की एक फोटो").images[0]
```

## Gradio इंटरफ़ेस

```python
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch

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

pipe.load_lora_weights("./dreambooth_model")

def generate(prompt, negative_prompt, steps, guidance, seed):
    generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None

    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_inference_steps=steps,
        guidance_scale=guidance,
        generator=generator
    ).images[0]

    return image

demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label="प्रॉम्प्ट (अपने विषय के लिए 'sks' का उपयोग करें)"),
        gr.Textbox(label="नकारात्मक प्रॉम्प्ट", value="धुंधला, बदसूरत"),
        gr.Slider(20, 50, value=30, step=1, label="चरण"),
        gr.Slider(5, 15, value=7.5, step=0.5, label="गाइडेंस"),
        gr.Number(value=-1, label="सीड")
    ],
    outputs=gr.Image(label="जनरेट की गई छवि"),
    title="DreamBooth पोर्ट्रेट जनरेटर"
)

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

## ट्रेनिंग टिप्स

### लोगों के लिए

* विभिन्न कोणों का उपयोग करें (सामने, साइड, 3/4)
* विभिन्न प्रकाश स्थितियाँ
* विभिन्न अभिव्यक्तियाँ
* स्पष्ट, उच्च-रिज़ॉल्यूशन फ़ोटो

### वस्तुओं के लिए

* कई कोण
* विभिन्न पृष्ठभूमियाँ
* सुसंगत प्रकाश
* कोई अवरोध नहीं

### शैलियों के लिए

* 10-20 उदाहरण चित्र
* सुसंगत कलात्मक शैली
* उस शैली में विभिन्न विषय

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

### ओवरफिटिंग

* max\_train\_steps कम करें
* learning\_rate कम करें
* पूर्व संरक्षण का उपयोग करें
* अधिक प्रशिक्षण इमेजें

### अंडरफिटिंग

* max\_train\_steps बढ़ाएँ
* learning\_rate अधिक करें
* अधिक प्रशिक्षण इमेजें
* छवि की गुणवत्ता जाँचें

### शैली नहीं सीखी गई

* LoRA रैंक बढ़ाएँ (r=16 या 32)
* अधिक समय तक प्रशिक्षण करें
* अधिक उदाहरणों का उपयोग करें

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

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

## अगले चरण

* [Kohya प्रशिक्षण](/guides/guides_v2-hi/training/kohya-training.md) - उन्नत प्रशिक्षण
* Stable Diffusion WebUI - मॉडल्स का उपयोग करें
* [LoRA फाइन-ट्यूनिंग](/guides/guides_v2-hi/training/kohya-training.md) - LLM प्रशिक्षण


---

# 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/training/dreambooth.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.
