Extending JPEG with neural networks (X-JPEG): Image-adaptive quantization with neural networks for JPEG
Project description
X-JPEG
Extending JPEG with neural networks (X-JPEG): Image-adaptive quantization with neural networks for JPEG
X-JPEG analyzes an image, predicts three 8×8 quantization tables for Y, Cb, and Cr, and passes them to a production JPEG encoder. The output is a normal JPEG: browsers, operating systems, and existing decoders need no plugin or neural network.
image ──► compact CNN + full-image DCT statistics ──► adaptive Y/Cb/Cr DQTs
│
▼
MozJPEG ──► .jpg
The current implementation and release weights were developed by Migel Tissera in 2026 and are released by Trinity Cloud under the MIT License.
Install
pip install xjpeg
Official platform wheels bundle MozJPEG. On an unsupported platform, X-JPEG
automatically uses a verified system MozJPEG (XJPEG_MOZJPEG=/path/to/cjpeg)
or falls back to Pillow/libjpeg.
Compress
# Complete-file bits per source pixel. This is conventional image-codec bpp.
xjpeg photo.png --target-bpp 0.5
# Search for the smallest file that reaches the requested RGB MS-SSIM.
xjpeg photo.png --target-msssim 0.98
# Directly control the learned tables (>1 means coarser/smaller).
xjpeg photo.png --scale 1.5
Progressive JPEG and a shared emitted chroma DQT are the release defaults.
The network still predicts independent Cb and Cr tables. Use --three-dqt
to emit all three tables or --sequential to disable progressive encoding.
from xjpeg import XJPEG
codec = XJPEG() # auto-selects bundled/system MozJPEG
result = codec.compress(
"photo.png",
output="photo.jpg",
target_bpp=0.5,
)
print(result.bpp, result.msssim, result.backend)
print(result.luma_table)
Low-rate results
Deterministic sample of 100 held-out native-resolution COCO val2017 images,
seed 20260721. Rates include the complete emitted file. Every JPEG row used
the same pinned MozJPEG build and settings; WebP used method 6. The release
model predicts three tables and the default deployment averages Cb/Cr only at
the encoding boundary.
| 0.50 bpp target | Actual bpp | RGB MS-SSIM ↑ | Y MS-SSIM ↑ | PSNR ↑ |
|---|---|---|---|---|
| X-JPEG, default 2-DQT emission | 0.49975 | 0.957182 | 0.967685 | 27.045 dB |
| X-JPEG, native 3-DQT emission | 0.49917 | 0.956934 | 0.967261 | 27.015 dB |
| Standard Annex-K tables + MozJPEG | 0.50097 | 0.953630 | 0.972323 | 26.958 dB |
| WebP method 6 | 0.50015 | 0.956685 | 0.972758 | 29.164 dB |
| 0.25 bpp target | Actual bpp | RGB MS-SSIM ↑ | Y MS-SSIM ↑ | PSNR ↑ |
|---|---|---|---|---|
| X-JPEG, default 2-DQT emission | 0.25111 | 0.917638 | 0.932246 | 24.899 dB |
| X-JPEG, native 3-DQT emission | 0.25002 | 0.916420 | 0.930914 | 24.853 dB |
| Standard Annex-K tables + MozJPEG | 0.25000 | 0.912369 | 0.938567 | 25.009 dB |
| WebP method 6 | 0.24996 | 0.922521 | 0.942144 | 26.609 dB |
The result is metric-specific. X-JPEG improves RGB MS-SSIM over the declared
standard-table JPEG control at these operating points; WebP retains a clear
advantage at 0.25 bpp and on luma MS-SSIM/PSNR. The 0.50-bpp X-JPEG/WebP mean
difference is too small to claim a general win. See
docs/BENCHMARKS.md for the protocol and limitations.
Train
pip install "xjpeg[train]"
python -m xjpeg.train \
--data /path/to/train2017 \
--val /path/to/kodak \
--out runs/experiment \
--architecture compact \
--num-tables 3 \
--dct-stats \
--gdn-reparam \
--native-crops \
--lambda-r 0.05 \
--lambda-luma 0.25
Training combines differentiable JPEG distortion, a learned coefficient-rate
proxy, soft table entropy, and an optional autoencoder reconstruction loss.
Release evaluation always uses real encoded files and complete-file byte
counts. The full objective and validation contract are documented in
docs/METHODOLOGY.md.
Model and releases
- Source and issues: https://github.com/trinity-cloud/x-jpeg
- Model weights: https://huggingface.co/migtissera/x-jpeg
- Python package: https://pypi.org/project/xjpeg/
- Model card:
MODEL_CARD.md
Limitations
- Trained and evaluated primarily on natural photographs.
- Not validated for medical, scientific, text-heavy, or adversarial imagery.
- Encoding is slower than libjpeg because it adds neural inference and MozJPEG trellis optimization; decoding speed is unchanged.
- EXIF/ICC metadata is not preserved in version 0.1.0.
--target-bppand--target-msssimsearch per image and therefore cost multiple real encodes.
License
X-JPEG code and weights are MIT licensed. Bundled MozJPEG is distributed
under its compatible upstream licenses; see
THIRD_PARTY_NOTICES.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xjpeg-0.1.1.tar.gz.
File metadata
- Download URL: xjpeg-0.1.1.tar.gz
- Upload date:
- Size: 8.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d6ed5329b0413f54937e77020fb683e1eac211a66a9c8b837a332d411c79662
|
|
| MD5 |
9e696ebb697dd52c7fcaae2967ddb1f0
|
|
| BLAKE2b-256 |
76eed43bd8d8e2d5ab34e5a1256c3b67920cd3b1e08b0f61b0f51eee909d40f0
|
Provenance
The following attestation bundles were made for xjpeg-0.1.1.tar.gz:
Publisher:
publish.yml on trinity-cloud/x-jpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xjpeg-0.1.1.tar.gz -
Subject digest:
3d6ed5329b0413f54937e77020fb683e1eac211a66a9c8b837a332d411c79662 - Sigstore transparency entry: 2340941043
- Sigstore integration time:
-
Permalink:
trinity-cloud/x-jpeg@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/trinity-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xjpeg-0.1.1-py3-none-win_amd64.whl.
File metadata
- Download URL: xjpeg-0.1.1-py3-none-win_amd64.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e14c4bbe7adeb916b6192c5dfc2a6b6cf0ee414de814f19bf69b07a94291b6fc
|
|
| MD5 |
f9ffd10a90d7f6c6dd4b12de41d7c93f
|
|
| BLAKE2b-256 |
f8756ba5c48dc2076a8c91275de6f9b2eb94283e76f0080d3653a1270c8025ed
|
Provenance
The following attestation bundles were made for xjpeg-0.1.1-py3-none-win_amd64.whl:
Publisher:
publish.yml on trinity-cloud/x-jpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xjpeg-0.1.1-py3-none-win_amd64.whl -
Subject digest:
e14c4bbe7adeb916b6192c5dfc2a6b6cf0ee414de814f19bf69b07a94291b6fc - Sigstore transparency entry: 2340941053
- Sigstore integration time:
-
Permalink:
trinity-cloud/x-jpeg@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/trinity-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xjpeg-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: xjpeg-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.6 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c8806db7a91f0a990d7e0f869c0ddc987388041b5d3beb543a11dbddb54fc7
|
|
| MD5 |
35ca9d33015a1fc4e0c16b4b2ce45f7b
|
|
| BLAKE2b-256 |
14ba5f6f66df6528d7b59fbd6c81d1f8863b4522bff55f7dd0dda24489bae531
|
Provenance
The following attestation bundles were made for xjpeg-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on trinity-cloud/x-jpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xjpeg-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
a6c8806db7a91f0a990d7e0f869c0ddc987388041b5d3beb543a11dbddb54fc7 - Sigstore transparency entry: 2340941066
- Sigstore integration time:
-
Permalink:
trinity-cloud/x-jpeg@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/trinity-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xjpeg-0.1.1-py3-none-macosx_12_0_x86_64.whl.
File metadata
- Download URL: xjpeg-0.1.1-py3-none-macosx_12_0_x86_64.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 3, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e182529d5ba1ec2e808fcc598f3425f28c8720812c4bd3e3d11a2798afdc47a
|
|
| MD5 |
ab2664a0ee823afea02f2ee4edf04de5
|
|
| BLAKE2b-256 |
6d56261b16ee7e58bab7d1cb99ef4919e711b34918c8affd30c6a1b2dc8bcb2a
|
Provenance
The following attestation bundles were made for xjpeg-0.1.1-py3-none-macosx_12_0_x86_64.whl:
Publisher:
publish.yml on trinity-cloud/x-jpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xjpeg-0.1.1-py3-none-macosx_12_0_x86_64.whl -
Subject digest:
8e182529d5ba1ec2e808fcc598f3425f28c8720812c4bd3e3d11a2798afdc47a - Sigstore transparency entry: 2340941075
- Sigstore integration time:
-
Permalink:
trinity-cloud/x-jpeg@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/trinity-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xjpeg-0.1.1-py3-none-macosx_12_0_arm64.whl.
File metadata
- Download URL: xjpeg-0.1.1-py3-none-macosx_12_0_arm64.whl
- Upload date:
- Size: 8.5 MB
- Tags: Python 3, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5e37b8154065c2ecd3925b2ebb3703ed822fd1c0e94221b6491d55a7c38b340
|
|
| MD5 |
7f4f1d09c21806975a7cb00cdc9f72d1
|
|
| BLAKE2b-256 |
9025c12eda7cb66de28f938fdd6e58061eae5b87a052566cbd000df56f28cee5
|
Provenance
The following attestation bundles were made for xjpeg-0.1.1-py3-none-macosx_12_0_arm64.whl:
Publisher:
publish.yml on trinity-cloud/x-jpeg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xjpeg-0.1.1-py3-none-macosx_12_0_arm64.whl -
Subject digest:
d5e37b8154065c2ecd3925b2ebb3703ed822fd1c0e94221b6491d55a7c38b340 - Sigstore transparency entry: 2340941085
- Sigstore integration time:
-
Permalink:
trinity-cloud/x-jpeg@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/trinity-cloud
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb6b9a0643accb9b0369c4cafddb23b0f8188808 -
Trigger Event:
push
-
Statement type: