> 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

Bilde mit Real-ESRGAN auf Clore.ai-GPUs hoch und verbessere sie

Bilder mithilfe von Real-ESRGAN auf der GPU hochskalieren und verbessern.

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

## Mieten auf CLORE.AI

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

### Greife auf deinen Server zu

* Verbindungsdetails finden in **Meine Bestellungen**
* Web-Oberflächen: Verwende die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Was ist Real-ESRGAN?

Real-ESRGAN ist ein praktisches Modell zur Bildwiederherstellung, das:

* Bilder um das 2- bis 4-Fache hochskaliert
* Rauschen und Artefakte entfernt
* Details verbessert
* Funktioniert mit Fotos, Anime und Kunst

## Modellvarianten

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

## Schnell bereitstellen

**Docker-Image:**

```
pytorch/pytorch:2.11.0-cuda12.8-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='Skalierung')],
    outputs=gr.Image(type='pil'),
    title='Real-ESRGAN-Hochskalierer'
)
demo.launch(server_name='0.0.0.0', server_port=7860)
"
```

## Auf deinen Dienst zugreifen

Nach der Bereitstellung findest du deine `http_pub` URL in **Meine Bestellungen**:

1. Gehe zu **Meine Bestellungen** Seite
2. Klicke auf deine Bestellung
3. Finde die `http_pub` URL (z. B. `abc123.clorecloud.net`)

Verwende `https://YOUR_HTTP_PUB_URL` anstelle von `localhost` in den folgenden Beispielen.

## CLI-Verwendung

### Installation

```bash
pip install realesrgan
```

### Grundlegende Hochskalierung

```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 \         # Gesichtsverbesserung 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
)

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

# 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, half=True)

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

# Alle Bilder verarbeiten
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
```

## Kachelverarbeitung (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,      # In 400px-Kacheln verarbeiten
    tile_pad=10,   # Überlappung zwischen Kacheln
    pre_pad=0,
    half=True
)
```

### Empfehlungen zur Kachelgröße

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

## Video-Hochskalierung

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

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

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

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

# Video wieder 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         | 4 GB+ | Fotos                  |
| x4plus\_anime\_6B | Am besten | Mittel          | 3 GB+ | Anime                  |
| x2plus            | Gut       | Schnell         | 2 GB+ | Schnelles 2x           |
| RealESRNet        | OK        | Am schnellsten  | 2 GB+ | Vorschauen             |

## Leistung

| Bildgröße | GPU      | 4x-Hochskalierungszeit |
| --------- | -------- | ---------------------- |
| 512x512   | RTX 3090 | \~0,5 s                |
| 1024x1024 | RTX 3090 | \~1,5 s                |
| 2048x2048 | RTX 3090 | \~5 s                  |
| 512x512   | RTX 4090 | \~0,3 s                |

## Fehlerbehebung

### CUDA-Speicher voll

```python

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

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

### Artefakte im Ausgabeergebnis

* Kleinere Kachelgröße mit mehr Überlappung verwenden
* Anderes Modell ausprobieren (Anime vs. Foto)
* Eingabebildqualität prüfen

### Langsame Verarbeitung

* FP16 aktivieren: `half=True`
* Kachelgröße erhöhen, wenn der VRAM es zulässt
* Schnelleres Modell verwenden: RealESRNet

## Ergebnisse herunterladen

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

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise (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           |

*Die Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

**Geld sparen:**

* Nutzen Sie den **Spot** Markt für unterbrechbare Arbeit — etwa ein Drittel der Server bietet Spot-Preise unter dem On-Demand-Preis (Median ca. 13 % Rabatt), der Rest ist gleichauf
* Bezahlen Sie mit **CLORE** Tokens
* Vergleichen Sie Preise zwischen verschiedenen Anbietern

## Nächste Schritte

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