migtissera/x-jpeg
X-JPEG 0.1
Extending JPEG with neural networks (X-JPEG): Image-adaptive quantization with neural networks for JPEG
X-JPEG predicts image-adaptive JPEG quantization tables. The encoder produces three 8×8 tables for Y, Cb, and Cr; those tables are passed to MozJPEG or libjpeg to produce an ordinary, standards-compliant .jpg. No neural network or custom software is required to decode the output.
Developed by Migel Tissera / Trinity Cloud.
Artifact
The source PyTorch checkpoint was converted with weights_only=True and prediction parity was verified exactly on a deterministic non-square RGB input. This repository contains no pickle checkpoint or training optimizer state.
Use
The PyPI package already contains these weights:
pip install xjpeg
xjpeg photo.png --target-bpp 0.5To load this Hub snapshot explicitly:
from pathlib import Path
from huggingface_hub import snapshot_download
from xjpeg import XJPEG
snapshot = Path(snapshot_download(
"migtissera/x-jpeg",
allow_patterns=["model.safetensors", "config.json"],
))
codec = XJPEG(snapshot / "model.safetensors")
result = codec.compress("photo.png", output="photo.jpg", target_bpp=0.5)
print(result.bpp, result.msssim, result.backend)Source, training code, and methodology: <https://github.com/trinity-cloud/x-jpeg>
Model architecture
- 256×256 RGB thumbnail input.
- Four 5×5 stride-2 convolution + reparameterized GDN blocks.
- Final stride-2 head producing a
3×8×8table bottleneck. - Frequency-aligned
3×8×8conditioning from full-resolution DCT-band energy. - Integer tables mapped to
[1, 255]and stored in JPEG DQT segments. - Three predicted tables; the package defaults to averaging Cb/Cr only at emission time to reduce low-rate header overhead.
The model has 19 tensors in its encoder artifact. The training-only mirror decoder, table entropy model, coefficient rate model, and optimizer state are not included.
Training
The model was trained on COCO train2017. Its differentiable 4:2:0 JPEG objective combines RGB MS-SSIM, a 0.25-weight luma MS-SSIM guard, and a learned DCT-symbol rate proxy with rate weight 0.05. Release measurements use actual encoded files rather than the rate proxy.
Low-rate evaluation
100 deterministic held-out native-resolution COCO val2017 images, seed 20260721, complete-file conventional bpp, pinned MozJPEG pipeline:
These results support an RGB MS-SSIM improvement over the declared standard-table JPEG control. They do not establish general superiority over WebP; WebP is clearly ahead at 0.25 bpp and in luma/PSNR.
Intended use and limitations
Intended for lossy compression of natural photographs and research on adaptive JPEG quantization. It is not an archival or forensic-preservation codec.
- Other image domains, including medical and scientific imagery, are not established.
- Version 0.1.0 does not preserve EXIF or ICC metadata.
--target-bppperforms multiple real encodes per image.- Encoding is slower than libjpeg; decoding remains ordinary JPEG decoding.
- The 100-image low-rate evaluation should be expanded before making strong frontier claims.
License
The X-JPEG code and model weights are released under the MIT License. MozJPEG is not included in this model repository; platform wheels may bundle it under its upstream license notices.
