Skip to main content

Neural adaptive quantization tables for standards-compliant JPEG

Project description

X-JPEG

Neural, image-adaptive quantization tables for ordinary JPEG files.

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

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-bpp and --target-msssim search 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xjpeg-0.1.0.tar.gz (8.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

xjpeg-0.1.0-py3-none-win_amd64.whl (8.5 MB view details)

Uploaded Python 3Windows x86-64

xjpeg-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (8.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

xjpeg-0.1.0-py3-none-macosx_12_0_x86_64.whl (8.5 MB view details)

Uploaded Python 3macOS 12.0+ x86-64

xjpeg-0.1.0-py3-none-macosx_12_0_arm64.whl (8.5 MB view details)

Uploaded Python 3macOS 12.0+ ARM64

File details

Details for the file xjpeg-0.1.0.tar.gz.

File metadata

  • Download URL: xjpeg-0.1.0.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

Hashes for xjpeg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23dcbb1f24cfd99fe19c38e120062d99af5206a4f208ba3f10ebd58daadfbfe1
MD5 f873b45aa4ae145098a85428aec0298c
BLAKE2b-256 bd1f9b4e9edeb6c7842aebfef5d8daf07d850584e99687f51804e624f2d6d62f

See more details on using hashes here.

Provenance

The following attestation bundles were made for xjpeg-0.1.0.tar.gz:

Publisher: publish.yml on trinity-cloud/x-jpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xjpeg-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: xjpeg-0.1.0-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

Hashes for xjpeg-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6d76826534b209dad4f28fb3338c93a5f3b4f19204dd59836b987fe5380a16a0
MD5 df847df837798ba0ea3b41a89bd1f24e
BLAKE2b-256 a767c72b979fd573e5b7c89dda067aa9215e6ad436ea57119c1713b5e97e237b

See more details on using hashes here.

Provenance

The following attestation bundles were made for xjpeg-0.1.0-py3-none-win_amd64.whl:

Publisher: publish.yml on trinity-cloud/x-jpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xjpeg-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for xjpeg-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed754cd709f9414837f42afdad27891bc2f4fb74a5ddf7c6b88dbdb5436273d3
MD5 da535f1200ffdb2855d0d5d74aaa0e32
BLAKE2b-256 fb45f47882cb8b516a7bb2581b4524dfbd01f1c619ae3bc5ee9cbe2bf4ce658f

See more details on using hashes here.

Provenance

The following attestation bundles were made for xjpeg-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on trinity-cloud/x-jpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xjpeg-0.1.0-py3-none-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for xjpeg-0.1.0-py3-none-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 b7d68bc2a0f56cce8644655bef396d169beff789d363bc67e3fbf9c98a5074e8
MD5 7f13e7485593ffeb8669ba7556fcb73e
BLAKE2b-256 b8037303b0b19f93d17e20337af7696c5b64067144b1ba89dbfb5e8b734453b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for xjpeg-0.1.0-py3-none-macosx_12_0_x86_64.whl:

Publisher: publish.yml on trinity-cloud/x-jpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xjpeg-0.1.0-py3-none-macosx_12_0_arm64.whl.

File metadata

  • Download URL: xjpeg-0.1.0-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

Hashes for xjpeg-0.1.0-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 8dc938728a64ba43974d2f012b5336190369cc17a1dc8c1ea08c92ecc0f248a9
MD5 e7dd4fe79ba0258a81383050d3e56e49
BLAKE2b-256 2fd3afc30205edf350e04767a47dae81db9d5b6a4207fcfe20b7a3c8ca4e7079

See more details on using hashes here.

Provenance

The following attestation bundles were made for xjpeg-0.1.0-py3-none-macosx_12_0_arm64.whl:

Publisher: publish.yml on trinity-cloud/x-jpeg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page