> 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 Upscaling

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)
   * यदि आवश्यक हो तो एनवायरनमेंट वेरिएबल जोड़ें
   * स्टार्टअप कमांड दर्ज करें
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.5.1-cuda12.4-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='Scale')],
    outputs=gr.Image(type='pil'),
    title='Real-ESRGAN Upscaler'
)
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 "Processed: $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
```

## API सर्वर

### 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.5s         |
| 1024x1024 | RTX 3090 | \~1.5s         |
| 2048x2048 | RTX 3090 | \~5s           |
| 512x512   | RTX 4090 | \~0.3s         |

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

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

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

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

## अगले कदम

* [GFPGAN फेस रिस्टोरेशन](/guides/guides_v2-hi/image-processing/gfpgan-face-restore.md)
* [AI वीडियो जनरेशन](/guides/guides_v2-hi/video-generation/ai-video-generation.md)
* Stable Diffusion WebUI


---

# 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.
