Skip to main content

A PyTorch library and evaluation platform for end-to-end compression research

Project description

License PyPI Downloads

CompressAI (compress-ay) is a PyTorch library and evaluation platform for end-to-end compression research.

CompressAI currently provides:

  • custom operations, layers and models for deep learning based data compression
  • a partial port of the official TensorFlow compression library
  • pre-trained end-to-end compression models for learned image compression
  • evaluation scripts to compare learned models against classical image/video compression codecs

PSNR performances plot on Kodak

Note: Multi-GPU support is now experimental.

Installation

CompressAI supports python 3.8+ and PyTorch 1.7+.

pip:

pip install compressai

Note: wheels are available for Linux and MacOS.

From source:

A C++17 compiler, a recent version of pip (19.0+), and common python packages are also required (see setup.py for the full list).

To get started locally and install the development version of CompressAI, run the following commands in a virtual environment:

git clone https://github.com/InterDigitalInc/CompressAI compressai
cd compressai
pip install -U pip && pip install -e .

For a custom installation, you can also run one of the following commands:

  • pip install -e '.[dev]': install the packages required for development (testing, linting, docs)
  • pip install -e '.[tutorials]': install the packages required for the tutorials (notebooks)

Note: Docker images will be released in the future. Conda environments are not officially supported.

Documentation

Usage

Examples

Script and notebook examples can be found in the examples/ directory.

To encode/decode images with the provided pre-trained models, run the codec.py example:

python3 examples/codec.py --help

An examplary training script with a rate-distortion loss is provided in examples/train.py. You can replace the model used in the training script with your own model implemented within CompressAI, and then run the script for a simple training pipeline:

python3 examples/train.py -d /path/to/my/image/dataset/ --epochs 300 -lr 1e-4 --batch-size 16 --cuda --save

Note: the training example uses a custom ImageFolder structure.

A jupyter notebook illustrating the usage of a pre-trained model for learned image compression is also provided in the examples directory:

pip install -U ipython jupyter ipywidgets matplotlib
jupyter notebook examples/

Evaluation

To evaluate a trained model on your own dataset, CompressAI provides an evaluation script:

python3 -m compressai.utils.eval_model checkpoint /path/to/images/folder/ -a $ARCH -p $MODEL_CHECKPOINT...

To evaluate provided pre-trained models:

python3 -m compressai.utils.eval_model pretrained /path/to/images/folder/ -a $ARCH -q $QUALITY_LEVELS...

To plot results from bench/eval_model simulations (requires matplotlib by default):

python3 -m compressai.utils.plot --help

To evaluate traditional codecs:

python3 -m compressai.utils.bench --help
python3 -m compressai.utils.bench bpg --help
python3 -m compressai.utils.bench vtm --help

For video, similar tests can be run, CompressAI only includes ssf2020 for now:

python3 -m compressai.utils.video.eval_model checkpoint /path/to/video/folder/ -a ssf2020 -p $MODEL_CHECKPOINT...
python3 -m compressai.utils.video.eval_model pretrained /path/to/video/folder/ -a ssf2020 -q $QUALITY_LEVELS...
python3 -m compressai.utils.video.bench x265 --help
python3 -m compressai.utils.video.bench VTM --help
python3 -m compressai.utils.video.plot --help

Tests

Run tests with pytest:

pytest -sx --cov=compressai --cov-append --cov-report term-missing tests

Slow tests can be skipped with the -m "not slow" option.

License

CompressAI is licensed under the BSD 3-Clause Clear License

Contributing

We welcome feedback and contributions. Please open a GitHub issue to report bugs, request enhancements or if you have any questions.

Before contributing, please read the CONTRIBUTING.md file.

Authors

  • Jean Bégaint, Fabien Racapé, Simon Feltman and Hyomin Choi, InterDigital AI Lab.

Citation

If you use this project, please cite the relevant original publications for the models and datasets, and cite this project as:

@article{begaint2020compressai,
	title={CompressAI: a PyTorch library and evaluation platform for end-to-end compression research},
	author={B{\'e}gaint, Jean and Racap{\'e}, Fabien and Feltman, Simon and Pushparaja, Akshay},
	year={2020},
	journal={arXiv preprint arXiv:2011.03029},
}

For any work related to the variable bitrate models, please cite

@article{kamisli2024dcc_vbrlic,
	title={Variable-Rate Learned Image Compression with Multi-Objective Optimization and Quantization-Reconstruction Offsets},
	author={Kamisli, Fatih and Racap{\'e}, Fabien and Choi, Hyomin},
	year={2024},
	booktitle={2024 Data Compression Conference (DCC)},
	eprint={2402.18930},
}

Related links

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

compressai-1.2.8.tar.gz (183.8 kB view details)

Uploaded Source

Built Distributions

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

compressai-1.2.8-cp312-cp312-manylinux_2_34_x86_64.whl (444.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

compressai-1.2.8-cp312-cp312-macosx_10_14_universal2.whl (540.9 kB view details)

Uploaded CPython 3.12macOS 10.14+ universal2 (ARM64, x86-64)

compressai-1.2.8-cp311-cp311-manylinux_2_34_x86_64.whl (445.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

compressai-1.2.8-cp311-cp311-macosx_10_14_universal2.whl (544.6 kB view details)

Uploaded CPython 3.11macOS 10.14+ universal2 (ARM64, x86-64)

compressai-1.2.8-cp310-cp310-manylinux_2_34_x86_64.whl (442.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

compressai-1.2.8-cp310-cp310-macosx_10_14_universal2.whl (538.6 kB view details)

Uploaded CPython 3.10macOS 10.14+ universal2 (ARM64, x86-64)

compressai-1.2.8-cp39-cp39-manylinux_2_34_x86_64.whl (442.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

compressai-1.2.8-cp39-cp39-macosx_10_14_universal2.whl (539.0 kB view details)

Uploaded CPython 3.9macOS 10.14+ universal2 (ARM64, x86-64)

compressai-1.2.8-cp38-cp38-manylinux_2_34_x86_64.whl (441.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

compressai-1.2.8-cp38-cp38-macosx_11_0_universal2.whl (538.1 kB view details)

Uploaded CPython 3.8macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file compressai-1.2.8.tar.gz.

File metadata

  • Download URL: compressai-1.2.8.tar.gz
  • Upload date:
  • Size: 183.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for compressai-1.2.8.tar.gz
Algorithm Hash digest
SHA256 d90a923694b4b66c3e39bd90316e7f177a620787190ca7550731fc16c1bc7d5e
MD5 0495d992e5db31442efb576b5cc7eac2
BLAKE2b-256 a365c6e387c10f159a15f9c0099b6656636d4e2ab4e2df1412b1755c8aee55f0

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 df389dd0503213a7d0856d03286d4532c048afa7421a1cf1ff1097ddc0b564a6
MD5 8354cdd4cdd60688232a0ee57f0b20c7
BLAKE2b-256 82bdc0a79dd7afe66e5d0efd49ec1aa199d8508c1bdd4e13de7b5cab21d5625c

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp312-cp312-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp312-cp312-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 2b0edf145f24d2eb2698b7e96c2332a8eac2cc8aea1416c13f3bf32a8fd5d33c
MD5 ff75099097bb8bfea7b10b32918fd770
BLAKE2b-256 d4d7fe36517c1f302647b3a7231b8ce233abd2b192e709a261cfb94e17bf13d7

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 65ad37fa12848bf11a597e37c4e527b993fc5ba736974a02137ab1026636c535
MD5 68bb103c1bbb104772a9439f4e6eab53
BLAKE2b-256 3424fa2fcf454447bbdcaeede1884c4e9757d3b90c6b1fa8b5e06a7162f1f4da

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp311-cp311-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp311-cp311-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 dae7c6dac90cdb45575c1b144512defb243ea93c316d78dbfe76658d35286903
MD5 c408b78fa0434cf3027c646aec487341
BLAKE2b-256 0ce399399a27a1b3f738bcfc790b259ede02aa1b41bf106e01cfdad06d7d6003

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7ba289e3f8188845f8c02b6852ab3364e26c6d27d699f9cbd4e9a1cec8c486ca
MD5 f3b0d863308de076eaac688be4a5650b
BLAKE2b-256 d5f7ce39375ab4cdfdfa704d8c24b781fccf932470ee9a2f8d5fe76427ff23e0

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp310-cp310-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp310-cp310-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 fad8b0cab994b2e5f3f9e99ccdc7054607fa785c99d21a61c6cfd6a904c57cac
MD5 fa014ae355fc48047eb4ebb693a72fef
BLAKE2b-256 7ac487698640ebf2dbd02a33de38e5c93ac58be3afff6b840e48d8707a0fd0d2

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c805044a3f538c815487a87f0828db23c3e811b56d53b3385d02074aaa31658c
MD5 4800369c0ee9e1e1ccf561972f9dab2e
BLAKE2b-256 4252db27ffef2affab1d66a63aa77383073f70a0c87579cd8bd7331d139d30f3

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp39-cp39-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp39-cp39-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 c208f3d970a806b9187c0632e734dbd1aea7f50f6b144e7dd331fbb932b4b4d7
MD5 cd498c01f2539491b2fa0191bd25d216
BLAKE2b-256 892b523a106e54db068482b126f399c54a8f5c79b2617aa321244be3852ff757

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4d54986623f6840b931497dba84b758f6aca2775fe4249632e8e5ae14ae1b41c
MD5 05ab9f5e71c3d2b51221f3734a977502
BLAKE2b-256 9fe5386f6fb0919fa02dc7a4daee1b9de139a3324e6c24998ad6491c2e785fee

See more details on using hashes here.

File details

Details for the file compressai-1.2.8-cp38-cp38-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for compressai-1.2.8-cp38-cp38-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 d3ed57ad80cca0c3a60e1d7fba9d7718a5c26a77ccaa180b5ebef902eaf1656a
MD5 e449c7faec7465a51c9703d876bff7f1
BLAKE2b-256 c7fb99f530505016bee6cba3b8a04f682272155680591f8395535b553542894d

See more details on using hashes here.

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