> 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/real-esrgan-upscaling.md).

# Real-ESRGAN अपस्केलिंग

Clore.ai GPUs पर Real-ESRGAN के साथ छवियों को अपस्केल और बेहतर बनाएँ

GPU पर Real-ESRGAN का उपयोग करके छवियों को अपस्केल और बेहतर बनाएं।

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

## Real-ESRGAN क्या है?

Real-ESRGAN एक व्यावहारिक इमेज रिस्टोरेशन मॉडल है जो:

* छवियों को 2x-4x तक अपस्केल करता है
* शोर और आर्टिफैक्ट्स हटाता है
* विवरणों को बेहतर बनाता है
* फोटो, एनीमे और कला पर काम करता है

## मॉडल वेरिएंट

| मॉडल                          | किसके लिए सर्वोत्तम | गति       |
| ----------------------------- | ------------------- | --------- |
| RealESRGAN\_x4plus            | सामान्य फोटो        | मध्यम     |
| RealESRGAN\_x4plus\_anime\_6B | एनीमे/चित्र         | मध्यम     |
| RealESRGAN\_x2plus            | 2x अपस्केल          | तेज़      |
| RealESRNet\_x4plus            | तेज़ प्रसंस्करण     | सबसे तेज़ |

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

**Docker इमेज:**

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

**पोर्ट:**

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

**कमांड:**

```bash
pip install realesrgan gradio && \\
python -c "
import gradio as gr
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import numpy as np
from PIL import Image
import torch

# मॉडल लोड करें
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(
    scale=4,
    model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth',
    model=model,
    tile=0,
    tile_pad=10,
    pre_pad=0,
    half=True
)

def upscale(image, scale):
    img = np.array(image)
    output, _ = upsampler.enhance(img, outscale=scale)
    return Image.fromarray(output)

demo = gr.Interface(
    fn=upscale,
    inputs=[gr.Image(type='pil'), gr.Slider(2, 4, value=4, step=1, label='स्केल')],
    outputs=gr.Image(type='pil'),
    title='Real-ESRGAN अपस्केलर'
)
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

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

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

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

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

## CLI उपयोग

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

```bash
pip install realesrgan
```

### मूल अपस्केलिंग

```bash

# एकल छवि को अपस्केल करें
python -m realesrgan -i input.jpg -o output.jpg -n RealESRGAN_x4plus -s 4

# फ़ोल्डर को अपस्केल करें
python -m realesrgan -i ./inputs -o ./outputs -n RealESRGAN_x4plus -s 4
```

### विकल्प

```bash
python -m realesrgan \\
    -i input.jpg \\           # इनपुट
    -o output.jpg \\          # आउटपुट
    -n RealESRGAN_x4plus \\   # मॉडल नाम
    -s 4 \\                   # स्केल गुणक
    --face_enhance \\         # चेहरे का सुधार सक्षम करें
    --fp32 \\                 # FP32 उपयोग करें (अधिक VRAM, बेहतर गुणवत्ता)
    --tile 400               # बड़ी छवियों के लिए टाइल आकार
```

## Python API

### मूल उपयोग

```python
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2

# मॉडल सेटअप
model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)

upsampler = RealESRGANer(
    scale=4,
    model_path='RealESRGAN_x4plus.pth',
    model=model,
    tile=0,
    tile_pad=10,
    pre_pad=0,
    half=True  # FP16 का उपयोग करें
)

# अपस्केल करें
img = cv2.imread('input.jpg', cv2.IMREAD_UNCHANGED)
output, _ = upsampler.enhance(img, outscale=4)
cv2.imwrite('output.jpg', output)
```

### चेहरे के संवर्धन के साथ

```python
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
from gfpgan import GFPGANer
import cv2

# Real-ESRGAN मॉडल
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(scale=4, model_path='RealESRGAN_x4plus.pth', model=model, half=True)

# चेहरों के लिए GFPGAN
face_enhancer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=4,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=upsampler
)

# प्रक्रिया
img = cv2.imread('portrait.jpg')
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
cv2.imwrite('output.jpg', output)
```

### एनीमे अपस्केलिंग

```python
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2

# एनीमे मॉडल
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)

upsampler = RealESRGANer(
    scale=4,
    model_path='RealESRGAN_x4plus_anime_6B.pth',
    model=model,
    half=True
)

img = cv2.imread('anime.png')
output, _ = upsampler.enhance(img, outscale=4)
cv2.imwrite('anime_upscaled.png', output)
```

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

### फ़ोल्डर संसाधित करें

```python
import os
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2
from tqdm import tqdm

# सेटअप
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(scale=4, model_path='RealESRGAN_x4plus.pth', model=model, half=True)

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

# सभी इमेज प्रोसेस करें
for filename in tqdm(os.listdir(input_dir)):
    if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
        img_path = os.path.join(input_dir, filename)
        img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)

        output, _ = upsampler.enhance(img, outscale=4)

        output_path = os.path.join(output_dir, f"upscaled_{filename}")
        cv2.imwrite(output_path, output)
```

### शेल स्क्रिप्ट

```bash
#!/bin/bash
INPUT_DIR=$1
OUTPUT_DIR=$2

mkdir -p $OUTPUT_DIR

for file in $INPUT_DIR/*.{jpg,png,jpeg}; do
    if [ -f "$file" ]; then
        filename=$(basename "$file")
        python -m realesrgan -i "$file" -o "$OUTPUT_DIR/upscaled_$filename" -n RealESRGAN_x4plus -s 4
        echo "संसाधित: $filename"
    fi
done
```

## टाइल्ड प्रसंस्करण (बड़ी छवियाँ)

उन छवियों के लिए जो VRAM में फिट नहीं होतीं:

```python
upsampler = RealESRGANer(
    scale=4,
    model_path='RealESRGAN_x4plus.pth',
    model=model,
    tile=400,      # 400px टाइलों में संसाधित करें
    tile_pad=10,   # टाइलों के बीच ओवरलैप
    pre_pad=0,
    half=True
)
```

### टाइल आकार अनुशंसाएँ

| VRAM | अधिकतम टाइल आकार     |
| ---- | -------------------- |
| 4GB  | 200                  |
| 6GB  | 300                  |
| 8GB  | 400                  |
| 12GB | 600                  |
| 24GB | 0 (कोई टाइलिंग नहीं) |

## वीडियो अपस्केलिंग

### Real-ESRGAN का उपयोग

```python
import cv2
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
from tqdm import tqdm

# मॉडल सेटअप
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(scale=4, model_path='RealESRGAN_x4plus.pth', model=model, tile=400, half=True)

# वीडियो खोलें
cap = cv2.VideoCapture('input.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) * 4
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) * 4
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

# आउटपुट
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height))

# फ्रेम संसाधित करें
for _ in tqdm(range(total_frames)):
    ret, frame = cap.read()
    if not ret:
        break

    output, _ = upsampler.enhance(frame, outscale=4)
    out.write(output)

cap.release()
out.release()
```

### FFmpeg पाइपलाइन

```bash

# फ्रेम निकालें
ffmpeg -i input.mp4 -qscale:v 1 frames/frame_%06d.png

# फ्रेम अपस्केल करें
python -m realesrgan -i frames -o upscaled -n RealESRGAN_x4plus -s 4

# वीडियो पुनः संयोजित करें
ffmpeg -framerate 30 -i upscaled/frame_%06d.png -c:v libx264 -pix_fmt yuv420p output.mp4

# ऑडियो वापस जोड़ें
ffmpeg -i output.mp4 -i input.mp4 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 final.mp4
```

## एपीआई सर्वर

### FastAPI सर्वर

```python
from fastapi import FastAPI, UploadFile
from fastapi.responses import Response
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
import cv2
import numpy as np
import io

app = FastAPI()

# मॉडल लोड करें
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(scale=4, model_path='RealESRGAN_x4plus.pth', model=model, tile=400, half=True)

@app.post("/upscale")
async def upscale(file: UploadFile, scale: int = 4):
    contents = await file.read()
    nparr = np.frombuffer(contents, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED)

    output, _ = upsampler.enhance(img, outscale=scale)

    _, encoded = cv2.imencode('.png', output)
    return Response(content=encoded.tobytes(), media_type="image/png")

# चलाएँ: uvicorn server:app --host 0.0.0.0 --port 8000
```

### उपयोग

```bash
curl -X POST "http://localhost:8000/upscale?scale=4" \\
    -F "file=@input.jpg" \\
    --output upscaled.png
```

## मॉडल तुलना

| मॉडल              | गुणवत्ता  | गति       | VRAM | किसके लिए सर्वोत्तम |
| ----------------- | --------- | --------- | ---- | ------------------- |
| x4plus            | सर्वोत्तम | धीमा      | 4GB+ | फोटो                |
| x4plus\_anime\_6B | सर्वोत्तम | मध्यम     | 3GB+ | ऐनिमे               |
| x2plus            | अच्छा     | तेज़      | 2GB+ | त्वरित 2x           |
| RealESRNet        | ठीक       | सबसे तेज़ | 2GB+ | पूर्वावलोकन         |

## प्रदर्शन

| छवि आकार  | GPU      | 4x अपस्केल समय |
| --------- | -------- | -------------- |
| 512x512   | RTX 3090 | \~0.5 सेकंड    |
| 1024x1024 | RTX 3090 | \~1.5 सेकंड    |
| 2048x2048 | RTX 3090 | \~5 सेकंड      |
| 512x512   | RTX 4090 | \~0.3 सेकंड    |

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

### CUDA मेमोरी समाप्त

```python

# टाइलिंग का उपयोग करें
upsampler = RealESRGANer(..., tile=200, ...)

# या स्केल कम करें
output, _ = upsampler.enhance(img, outscale=2)  # 4 के बजाय
```

### आउटपुट में आर्टिफैक्ट्स

* अधिक ओवरलैप के साथ छोटा टाइल आकार उपयोग करें
* अलग मॉडल आज़माएँ (एनीमे बनाम फोटो)
* इनपुट छवि गुणवत्ता जांचें

### धीमी प्रोसेसिंग

* FP16 सक्षम करें: `half=True`
* यदि VRAM अनुमति दे तो टाइल आकार बढ़ाएँ
* तेज़ मॉडल का उपयोग करें: RealESRNet

## परिणाम डाउनलोड करें

```bash
scp -P <port> -r root@<proxy>:/workspace/outputs/ ./upscaled_images/
```

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

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

## अगले चरण

* [GFPGAN चेहरे की पुनर्स्थापना](/guides/guides_v2-hi/image-processing/gfpgan-face-restore.md)
* [AI वीडियो जनरेशन](/guides/guides_v2-hi/video-generation/ai-video-generation.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/real-esrgan-upscaling.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.
