Image upscaler for the Google Coral TPU.
Find a file
pcalau12i 697349bb24 Add CLI --version/--help, license, .gitignore, and a README example
CLI: both tools now support --version/-V, --help/-h, and print usage on bad
arguments or missing files; build version is defined at the top of the Makefile.

Docs: README gains a "Does it actually look sharper?" section — a zoomed
bicubic-vs-Coral-quality comparison on a test photo (example_2x.png) plus a
PSNR table computed from the test set.

Also adds The Unlicense (public domain) and a .gitignore for build products.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-27 01:40:45 -04:00
models Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
prebuilt Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
testcases Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
tools Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
.gitignore Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
build.sh Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
build_ffmpeg.sh Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
build_ffmpeg_static.sh Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
coral-sr.c Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
coral_sr.c Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
coral_sr.h Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
example_2x.png Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
install_deps.sh Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
LICENSE Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
Makefile Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
README.md Add CLI --version/--help, license, .gitignore, and a README example 2026-07-27 01:40:45 -04:00
setup_tflite.sh Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
stb_image.h Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
stb_image_write.h Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00
vf_coralsr.c Sat Jul 25 10:16:08 PM EDT 2026 2026-07-25 22:16:08 -04:00

coral-sr

Neural image & video upscaling that runs on a Google Coral Edge TPU — both as a standalone tool and as an ffmpeg filter.

It upscales 2× using a small neural network on the Coral, producing sharper, more detailed results than a plain resize. Two modes:

  • fast — faithful and quick; good for video and bulk jobs.
  • quality — invents plausible fine detail (sharpest); best for photos and hero frames, at the cost of speed.

For any target size other than a clean 2×, you pair it with ffmpeg's normal scale (e.g. 720p→1080p = 2× on the TPU, then scale down).


Does it actually look sharper?

Here's a 2× upscale of a test photo (turkey-tail fungus), zoomed in on the fine concentric bands of the cap — plain CPU bicubic vs. the Coral quality model vs. the true high-resolution original:

CPU bicubic vs Coral quality vs original

The neural upscale keeps the band edges crisp where bicubic smears them into a blur. Measured against the original with PSNR (higher = closer to the real image):

upscale (2×) this photo average over 8 test images
CPU bicubic 22.30 dB 29.86 dB
Coral quality 22.56 dB 30.75 dB (+0.89 dB)

Neural upscaling is slower than a plain resize — it's a quality tool, not a speed tool — but the Coral runs the network ~76× faster than the same model on the CPU (~31 ms per 2× tile), which is what makes it usable in practice.


Requirements

  • A Google Coral Edge TPU (USB accelerator or M.2/PCIe) and its runtime (libedgetpu).
  • Linux, x86_64.

Build & install

make deps        # one-time: installs build tools + the Coral runtime, and builds
                 # the TensorFlow Lite C library (~15 min, mostly the TFLite build)
make             # build the standalone CLI  ->  ./coral-sr
make ffmpeg      # optional: build a custom ffmpeg with the `coralsr` filter
sudo make install

make install puts coral-sr (and coral-ffmpeg, if you built it) in /usr/bin, and the model files in /usr/share/coral-sr/models/.

Can't build it? Prebuilt, self-contained binaries are in prebuilt/ — they only need libedgetpu installed (sudo apt install libedgetpu1-std).


Usage

Two model files are installed (fast and quality):

  • fast: /usr/share/coral-sr/models/fsrcnn_y2x_128_int8_edgetpu.tflite
  • quality: /usr/share/coral-sr/models/quality_F128C32_icnr_128_int8_edgetpu.tflite

Standalone tool

coral-sr --model <model.tflite> in.png out.png
# upscale a photo 2× with the quality model
coral-sr --model /usr/share/coral-sr/models/quality_F128C32_icnr_128_int8_edgetpu.tflite \
         photo.jpg photo_2x.jpg

ffmpeg filter

Works on both images and video (coralsr always upscales 2×):

# image
coral-ffmpeg -i in.png -vf "coralsr=model=<model>:device=tpu" out.png

# video
coral-ffmpeg -i in.mp4 -vf "coralsr=model=<model>:device=tpu" out.mp4

Arbitrary target resolution — chain ffmpeg's scale after it. Upscale 2× on the TPU, then resample to the exact size:

# 720p -> 1080p
coral-ffmpeg -i in.mp4 \
  -vf "coralsr=model=<model>:device=tpu,scale=1920:1080:flags=lanczos" out.mp4

Filter options: model=<path> (required), device=tpu (default) or cpu, threads=N (CPU only).


Notes

  • It's a quality tool, not a speed tool. Neural upscaling looks better than a plain resize, but it's slower — if you just want raw speed, ffmpeg's own scale is far faster. Reach for coral-sr when the extra detail is worth it (especially quality mode).
  • The network does a fixed 2×; use scale for any other factor, and skip coral-sr entirely when shrinking.
  • device=cpu is a fallback for machines without a Coral (much slower).

Repo layout

coral-sr.c            standalone CLI
coral_sr.c / .h       the upscaling engine (shared by CLI and the ffmpeg filter)
vf_coralsr.c          the ffmpeg video filter
models/               the trained networks (fast + quality)
prebuilt/             self-contained binaries you can run without building
tools/                training / evaluation scripts (how the models were made)
Makefile              build / install (see `make` targets above)

Build the shippable self-contained binaries yourself with make prebuilt.