AI Image Upscaler using Real-ESRGAN.
pip install scaleioOr install from source:
pip install -e .realesrgan- Real-ESRGAN inferencePillow- Image handlingnumpy- Array operationsopencv-python-headless- Computer visiontorch- Deep learning backendbasicsr- Basic Super Resolution librarytqdm- Progress bars
from scaleio import Upscaler
upscaler = Upscaler(scale=4, model="general")
# From file
result = upscaler.upscale("input.jpg", "output.png")
# From PIL Image
from PIL import Image
img = Image.open("input.jpg")
result = upscaler.upscale(img)
# Batch processing
output_paths = upscaler.upscale_batch(
["img1.jpg", "img2.jpg", "img3.jpg"],
output_dir="upscaled/"
)# Single image
scaleio input.jpg --scale 4 --model general --output output.png
# Batch processing
scaleio ./images/ --batch --output-dir ./upscaled/
# With custom settings
scaleio input.jpg --scale 2 --model anime --tile 512| Option | Description | Default |
|---|---|---|
--scale |
Upscaling factor (2, 4, 8) | 4 |
--model |
Model type | general |
--tile |
Tile size for large images | 0 (disabled) |
--device |
Device (auto, cuda, mps, cpu) | auto |
--output |
Output file (single mode) | auto-generated |
--output-dir |
Output directory (batch mode) | required for batch |
--batch |
Enable batch mode | false |
--suffix |
Output suffix for batch | _upscaled |
general- General purpose upscaling (RealESRGAN_x4plus)anime- Optimized for anime/illustrations (RealESRGAN_x4plus_anime_6B)general-denoise- General with denoisinganime-denoise- Anime with denoising
Upscaler(
scale: int = 4, # 2, 4, or 8
model: str = "general", # model name
tile: int = 0, # tile size (0 = disabled)
tile_pad: int = 10, # tile padding
device: str = "auto" # auto, cuda, mps, cpu
)-
upscale(input, output=None)- Upscale single imageinput: str, Path, PIL.Image, or np.ndarrayoutput: Optional output path- Returns: PIL.Image
-
upscale_batch(inputs, output_dir, suffix="_upscaled")- Batch processinputs: List of file pathsoutput_dir: Output directorysuffix: Suffix for output filenames
from scaleio import (
Upscaler,
ModelNotFoundError,
UnsupportedScaleError,
ImageLoadError
)
try:
upscaler = Upscaler(model="invalid")
except ModelNotFoundError as e:
print(f"Invalid model: {e}")
try:
upscaler = Upscaler(scale=3)
except UnsupportedScaleError as e:
print(f"Invalid scale: {e}")# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black scaleio/
ruff check scaleio/MIT