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

# Real-ESRGAN Upscaling

Bilder mit Real-ESRGAN auf der GPU hochskalieren und verbessern.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die über [CLORE.AI Marketplace](https://clore.ai/marketplace).
{% endhint %}

## Mieten auf CLORE.AI

1. Besuchen Sie [CLORE.AI Marketplace](https://clore.ai/marketplace)
2. Nach GPU-Typ, VRAM und Preis filtern
3. Wählen **On-Demand** (Festpreis) oder **Spot** (Gebotspreis)
4. Konfigurieren Sie Ihre Bestellung:
   * Docker-Image auswählen
   * Ports festlegen (TCP für SSH, HTTP für Web-UIs)
   * Umgebungsvariablen bei Bedarf hinzufügen
   * Startbefehl eingeben
5. Zahlung auswählen: **CLORE**, **BTC**, oder **USDT/USDC**
6. Bestellung erstellen und auf Bereitstellung warten

### Zugriff auf Ihren Server

* Verbindungsdetails finden Sie in **Meine Bestellungen**
* Webschnittstellen: Verwenden Sie die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Was ist Real-ESRGAN?

Real-ESRGAN ist ein praktisches Bildwiederherstellungsmodell, das:

* Bilder 2x–4x hochskaliert
* Rauschen und Artefakte entfernt
* Details verbessert
* An Fotos, Anime und Kunst arbeitet

## Modellvarianten

| Modell                        | Am besten geeignet für | Geschwindigkeit |
| ----------------------------- | ---------------------- | --------------- |
| RealESRGAN\_x4plus            | Allgemeine Fotos       | Mittel          |
| RealESRGAN\_x4plus\_anime\_6B | Anime/Zeichnungen      | Mittel          |
| RealESRGAN\_x2plus            | 2x Hochskalierung      | Schnell         |
| RealESRNet\_x4plus            | Schnelle Verarbeitung  | Am schnellsten  |

## Schnelle Bereitstellung

**Docker-Image:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
```

**Ports:**

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

**Befehl:**

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

# Modell laden
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)
"
```

## Zugriff auf Ihren Dienst

Nach der Bereitstellung finden Sie Ihre `http_pub` URL in **Meine Bestellungen**:

1. Gehen Sie zur **Meine Bestellungen** Seite
2. Klicken Sie auf Ihre Bestellung
3. Finden Sie die `http_pub` URL (z. B., `abc123.clorecloud.net`)

Verwenden Sie `https://IHRE_HTTP_PUB_URL` anstelle von `localhost` in den Beispielen unten.

## CLI-Verwendung

### Installation

```bash
pip install realesrgan
```

### Grundlegendes Hochskalieren

```bash

# Einzelnes Bild hochskalieren
python -m realesrgan -i input.jpg -o output.jpg -n RealESRGAN_x4plus -s 4

# Ordner hochskalieren
python -m realesrgan -i ./inputs -o ./outputs -n RealESRGAN_x4plus -s 4
```

### Optionen

```bash
python -m realesrgan \
    -i input.jpg \           # Eingabe
    -o output.jpg \          # Ausgabe
    -n RealESRGAN_x4plus \   # Modellname
    -s 4 \                   # Skalierungsfaktor
    --face_enhance \         # Gesichtsanpassung aktivieren
    --fp32 \                 # FP32 verwenden (mehr VRAM, bessere Qualität)
    --tile 400               # Kachelgröße für große Bilder
```

## Python-API

### Grundlegende Verwendung

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

# Modell einrichten
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 verwenden
)

# Hochskalieren
img = cv2.imread('input.jpg', cv2.IMREAD_UNCHANGED)
output, _ = upsampler.enhance(img, outscale=4)
cv2.imwrite('output.jpg', output)
```

### Mit Gesichtsverbesserung

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

# Real-ESRGAN Modell
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 für Gesichter
face_enhancer = GFPGANer(
    model_path='GFPGANv1.4.pth',
    upscale=4,
    arch='clean',
    channel_multiplier=2,
    bg_upsampler=upsampler
)

# Verarbeitung
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)
```

### Anime-Hochskalierung

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

# Anime-Modell
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)
```

## Batch-Verarbeitung

### Ordner verarbeiten

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

# Einrichtung
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)

# Verarbeite alle Bilder
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)
```

### Shell-Skript

```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 "Verarbeitet: $filename"
    fi
done
```

## Gekachelte Verarbeitung (große Bilder)

Für Bilder, die nicht in den VRAM passen:

```python
upsampler = RealESRGANer(
    scale=4,
    model_path='RealESRGAN_x4plus.pth',
    model=model,
    tile=400,      # Verarbeitung in 400px-Kacheln
    tile_pad=10,   # Überlappung zwischen Kacheln
    pre_pad=0,
    half=True
)
```

### Empfehlungen zur Kachelgröße

| VRAM | Maximale Kachelgröße |
| ---- | -------------------- |
| 4GB  | 200                  |
| 6GB  | 300                  |
| 8GB  | 400                  |
| 12GB | 600                  |
| 24GB | 0 (keine Kachelung)  |

## Video-Upscaling

### Verwendung von Real-ESRGAN

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

# Modell einrichten
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)

# Video öffnen
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))

# Ausgabe
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height))

# Frames verarbeiten
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-Pipeline

```bash

# Frames extrahieren
ffmpeg -i input.mp4 -qscale:v 1 frames/frame_%06d.png

# Frames hochskalieren
python -m realesrgan -i frames -o upscaled -n RealESRGAN_x4plus -s 4

# Video neu zusammensetzen
ffmpeg -framerate 30 -i upscaled/frame_%06d.png -c:v libx264 -pix_fmt yuv420p output.mp4

# Audio wieder hinzufügen
ffmpeg -i output.mp4 -i input.mp4 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 final.mp4
```

## API-Server

### FastAPI-Server

```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()

# Modell laden
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")

# Ausführen: uvicorn server:app --host 0.0.0.0 --port 8000
```

### Verwendung

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

## Modellvergleich

| Modell            | Qualität  | Geschwindigkeit | VRAM | Am besten geeignet für |
| ----------------- | --------- | --------------- | ---- | ---------------------- |
| x4plus            | Am besten | Langsam         | 4GB+ | Fotos                  |
| x4plus\_anime\_6B | Am besten | Mittel          | 3GB+ | Anime                  |
| x2plus            | Gut       | Schnell         | 2GB+ | Schnelles 2x           |
| RealESRNet        | OK        | Am schnellsten  | 2GB+ | Vorschauen             |

## Leistung

| Bildgröße | GPU      | 4x Hochskalierungszeit |
| --------- | -------- | ---------------------- |
| 512x512   | RTX 3090 | \~0.5s                 |
| 1024x1024 | RTX 3090 | \~1.5s                 |
| 2048x2048 | RTX 3090 | \~5s                   |
| 512x512   | RTX 4090 | \~0.3s                 |

## Fehlerbehebung

### CUDA: Kein Speicher

```python

# Kachelung verwenden
upsampler = RealESRGANer(..., tile=200, ...)

# Oder Skala reduzieren
output, _ = upsampler.enhance(img, outscale=2)  # Statt 4
```

### Artefakte im Ergebnis

* Verwende kleinere Kachelgröße mit mehr Überlappung
* Versuche ein anderes Modell (Anime vs. Foto)
* Überprüfe die Eingabebildqualität

### Langsame Verarbeitung

* FP16 aktivieren: `half=True`
* Erhöhe die Kachelgröße, wenn der VRAM es zulässt
* Verwende ein schnelleres Modell: RealESRNet

## Ergebnisse herunterladen

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

## Kostenabschätzung

Typische CLORE.AI-Marktplatztarife (Stand 2024):

| GPU       | Stundensatz | Tagessatz | 4-Stunden-Sitzung |
| --------- | ----------- | --------- | ----------------- |
| 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           |

*Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI Marketplace*](https://clore.ai/marketplace) *auf aktuelle Preise.*

**Geld sparen:**

* Verwenden Sie **Spot** Markt für flexible Workloads (oft 30–50% günstiger)
* Bezahlen mit **CLORE** Token
* Preise bei verschiedenen Anbietern vergleichen

## Nächste Schritte

* [GFPGAN-Gesichtsrestauration](/guides/guides_v2-de/bildverarbeitung/gfpgan-face-restore.md)
* [KI-Videogenerierung](/guides/guides_v2-de/video-generierung/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:

```
GET https://docs.clore.ai/guides/guides_v2-de/bildverarbeitung/real-esrgan-upscaling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
