Skip to content

Real-ESRGAN image upscaling#172

Open
lucasliet wants to merge 4 commits into
mansuf:mainfrom
lucasliet:pr-upstream
Open

Real-ESRGAN image upscaling#172
lucasliet wants to merge 4 commits into
mansuf:mainfrom
lucasliet:pr-upstream

Conversation

@lucasliet

Copy link
Copy Markdown

Summary

  • Adds an optional Real-ESRGAN upscaling pipeline (--upscale, --upscale-scale {2,4}) that works on macOS via
    Core ML and on Linux/Windows via PyTorch.
  • Keeps the default download experience unchanged; upscaling is opt-in and only available when the new
    upscale extra is installed.
  • Create temporary .upscaled markers in raw downloads, and reuses SHA-based
    checks to skip already processed images. remove them after finish vol/chapter upscaling

Implementation Notes

  • New modules:
    • mangadex_downloader/upscale.py: PyTorch backend wrapping Real-ESRGAN (models RealESRGAN_x2plus.pth,
      RealESRGAN_x4plus_anime_6B.pth).
    • mangadex_downloader/upscale_coreml.py: Core ML backend (models RealESRGAN_x2plus.mlpackage,
      RealESRGAN_x4plus_anime_6B.mlpackage). (conversion made with Aidoku upscale script https://github.com/Aidoku/upscale?tab=readme-ov-file)
  • Lazy model download:
    • First use triggers download into mangadex_downloader/models/, with SHA256 verification
    • Subsequent runs reuse the files; marker hashes in .upscaled files prevent redundant processing.
  • CLI/config updates accept new flags and validations; upscaler shutdown is registered with the global
    cleanup queue.
  • requirements-upscale.txt and the upscale extra isolate heavyweight deps (torch, coremltools, basicsr,
    etc.) and restrict them to Python 3.10–3.12 (not compatible with 3.13 at moment, therefore I decided to made a exclusive scope for them named "upscale"), keeping the core package compatible with 3.10+.

Known Caveat

  • Model storage happens inside the package directory. For system-wide pip install on read-only site-packages
    or for PyInstaller builds produced by CI, write permissions may be limited. If that becomes an issue we
    may need to redirect the cache to a writable user directory (e.g. ~/.cache/mangadex-downloader).

Testing

  1. pipx install "mangadex-downloader[optional,upscale]" (Python 3.11/3.12).
  2. mangadex-dl "" --upscale --upscale-scale 4
  3. Re-run the download to confirm markers skip re-upscaling and .upscaled files are cleaned in raw outputs.

Screenshots

Download and upscale ![2025-10-07 00 05 25](https://github.com/user-attachments/assets/7210eedd-eacb-4f27-83ad-ee8b9e84c742)

Resume upscale and download
telegram-cloud-photo-size-1-5127880945439542091-y

Default run without upscale with warning because of flag usage
telegram-cloud-photo-size-1-5127880945439542104-y

Default run without flag, and no warnings
image

there are some errors connecting to "https://api.mangadex.network/report" but that happens to me on main version too

Upscale Result

Before: image

After:
image


Sources: https://github.com/xinntao/Real-ESRGAN https://github.com/Aidoku/Aidoku

lucasliet and others added 4 commits October 4, 2025 01:20
Major Feature: AI-powered image upscaling with Real-ESRGAN
- Core ML backend for macOS with Neural Engine acceleration (2x/4x)
- PyTorch backend for Linux/Windows with CUDA/CPU support (2x/4x)
- NCNN backend for macOS (legacy Vulkan support)

Security Enhancements:
- SHA256 validation for all model downloads (Core ML, PyTorch, NCNN)
- Automatic integrity checks before model loading/extraction
- Fallback URL system for reliable Core ML model downloads
- Protection against corrupted or malicious downloads

Infrastructure:
- Refactored GitHub Actions workflows for macOS arm64 builds
- Added Claude Code integration workflow
- Updated CI/CD pipeline with proper artifact handling

Documentation:
- Comprehensive CLAUDE.md for development guidance
- Updated README with upscaling features and requirements
- Detailed changelog with version history

Technical Details:
- Tile-based processing for large images (256x256 tiles)
- Weighted blending with feathering for seamless upscaling
- SHA256-based marker system to skip already upscaled images
- Graceful shutdown handling with threading events

Files Changed: 22 files (+1963/-282 lines)
- New: upscale.py, upscale_coreml.py, upscale_ncnn.py, CLAUDE.md
- Modified: CI workflows, README, requirements, format handlers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Standardizes the 4x upscaling model across all backends to `RealESRGAN_x4plus_anime_6B` and sets 4x as the new default scaling factor. This improves quality and consistency.

- **Standardized 4x Upscaling Model**: Switched PyTorch backend from `realesr-general-x4v3.pth` to `RealESRGAN_x4plus_anime_6B.pth` for consistency with Core ML and NCNN backends.
- **4x as Default**: Changed the default upscale factor from 2x to 4x for higher quality out-of-the-box.
- **Enhanced Validation**: Added strict validation to only allow `2` or `4` as scale factors at the configuration level.
- **Code Cleanup**: Removed legacy code paths for 3x upscaling and clarified model selection logic.

- **Default upscale scale changed from 2x to 4x**: Users who relied on the 2x default will need to explicitly use `--upscale-scale 2`.
- The old `realesr-general-x4v3.pth` model is no longer used and will be replaced by the new anime-specific model on first run.

- Updated `README.md` and `CLAUDE.md` with the new default scale, model names, and usage examples.
- Added a new entry to `docs/changelog.md` for version `v3.2.1-upscale`.
- Updated default upscale factor from 2x to 4x across all backends.
- Removed legacy 3x support and added strict validation for upscale scale (2 or 4).
- Introduced cleanup method for upscale markers after successful processing.
- Updated documentation and changelog to reflect changes in upscaling features.
- Refactored requirements to separate upscale-specific dependencies.
- Removed NCNN backend implementation as it was no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant