All Projects → Justin-Tan → High Fidelity Generative Compression

Justin-Tan / High Fidelity Generative Compression

Licence: apache-2.0
Pytorch implementation of High-Fidelity Generative Image Compression + Routines for neural image compression

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to High Fidelity Generative Compression

Energy based generative models
PyTorch code accompanying our paper on Maximum Entropy Generators for Energy-Based Models
Stars: ✭ 114 (-33.33%)
Mutual labels:  generative-adversarial-networks
Generative adversarial networks 101
Keras implementations of Generative Adversarial Networks. GANs, DCGAN, CGAN, CCGAN, WGAN and LSGAN models with MNIST and CIFAR-10 datasets.
Stars: ✭ 138 (-19.3%)
Mutual labels:  generative-adversarial-networks
Flora
可能是Android平台上最快的图片压缩框架。
Stars: ✭ 160 (-6.43%)
Mutual labels:  image-compression
Pictureselector
Picture Selector Library for Android or 图片选择器
Stars: ✭ 11,095 (+6388.3%)
Mutual labels:  image-compression
Lerc
Limited Error Raster Compression
Stars: ✭ 126 (-26.32%)
Mutual labels:  image-compression
Waifu2x Extension
Image, GIF and Video enlarger/upscaler achieved with waifu2x and Anime4K. [NO LONGER UPDATED]
Stars: ✭ 149 (-12.87%)
Mutual labels:  image-compression
Ylg
[CVPR 2020] Official Implementation: "Your Local GAN: Designing Two Dimensional Local Attention Mechanisms for Generative Models".
Stars: ✭ 109 (-36.26%)
Mutual labels:  generative-adversarial-networks
Image Compressor
[Deprecated] No longer maintained, please use https://github.com/fengyuanchen/compressorjs
Stars: ✭ 167 (-2.34%)
Mutual labels:  image-compression
Pngcrush
It is a free, open source command-line utility for optimizing PNG image files ( batch script included ).
Stars: ✭ 136 (-20.47%)
Mutual labels:  image-compression
Gan Mri
Code repository for Frontiers article 'Generative Adversarial Networks for Image-to-Image Translation on Multi-Contrast MR Images - A Comparison of CycleGAN and UNIT'
Stars: ✭ 159 (-7.02%)
Mutual labels:  generative-adversarial-networks
Img2ktx
Converts common image formats (PNG, JPG, etc.) to GPU-native compressed (BCn, ETC, ASTC) in KTX containers.
Stars: ✭ 117 (-31.58%)
Mutual labels:  image-compression
Steganogan
SteganoGAN is a tool for creating steganographic images using adversarial training.
Stars: ✭ 124 (-27.49%)
Mutual labels:  generative-adversarial-networks
Caesium Clt
Caesium Command Line Tools - Lossy/lossless image compression tool using mozjpeg and zopflipng
Stars: ✭ 149 (-12.87%)
Mutual labels:  image-compression
Fuif
Free Universal Image Format
Stars: ✭ 115 (-32.75%)
Mutual labels:  image-compression
Repo 2018
Deep Learning Summer School + Tensorflow + OpenCV cascade training + YOLO + COCO + CycleGAN + AWS EC2 Setup + AWS IoT Project + AWS SageMaker + AWS API Gateway + Raspberry Pi3 Ubuntu Core
Stars: ✭ 163 (-4.68%)
Mutual labels:  generative-adversarial-networks
Imagine
🖼️ PNG/JPEG optimization app for macOS, Windows and Linux.
Stars: ✭ 1,859 (+987.13%)
Mutual labels:  image-compression
Optimize Images
A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.
Stars: ✭ 141 (-17.54%)
Mutual labels:  image-compression
Luban
Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法
Stars: ✭ 12,794 (+7381.87%)
Mutual labels:  image-compression
Essential Image Optimization
Essential Image Optimization - an eBook
Stars: ✭ 1,950 (+1040.35%)
Mutual labels:  image-compression
Zi2zi
Learning Chinese Character style with conditional GAN
Stars: ✭ 1,988 (+1062.57%)
Mutual labels:  generative-adversarial-networks

high-fidelity-generative-compression

Pytorch implementation of the paper "High-Fidelity Generative Image Compression" by Mentzer et. al.. This repo also provides general utilities for lossless compression that interface with Pytorch. For the official (TensorFlow) code release, see the TensorFlow compression repo.

About

This repository defines a model for learnable image compression based on the paper "High-Fidelity Generative Image Compression" (HIFIC) by Mentzer et. al.. The model is capable of compressing images of arbitrary spatial dimension and resolution up to two orders of magnitude in size, while maintaining perceptually similar reconstructions. Outputs tend to be more visually pleasing than standard image codecs operating at higher bitrates.

This repository also includes a partial port of the Tensorflow Compression library - which provides general tools for neural image compression in Pytorch.

Open In Colab

You can play with a demonstration of the model in Colab, where you can upload and compress your own images.

Example

Original HiFIC
guess guess
Original: (6.01 bpp - 2100 kB) | HiFIC: (0.160 bpp - 56 kB). Ratio: 37.5.

The image shown is an out-of-sample instance from the CLIC-2020 dataset. The HiFIC image is obtained by reconstruction via a learned model provided below.

Note that the learned model was not adapted in any way for evaluation on this image. More sample outputs from this model can be found at the end of the README and in EXAMPLES.md.

Note

The generator is trained to achieve realistic and not exact reconstruction. It may synthesize certain portions of a given image to remove artifacts associated with lossy compression. Therefore, in theory images which are compressed and decoded may be arbitrarily different from the input. This precludes usage for sensitive applications. An important caveat from the authors is reproduced here:

"Therefore, we emphasize that our method is not suitable for sensitive image contents, such as, e.g., storing medical images, or important documents."

Usage

  • Install Pytorch nightly and dependencies from https://pytorch.org/. Then install other requirements:
pip install -r requirements.txt
  • Clone this repository, cd in:
git clone https://github.com/Justin-Tan/high-fidelity-generative-compression.git
cd high-fidelity-generative-compression

To check if your setup is working, run python3 -m src.model in root. Usage instructions can be found in the user's guide.

Training

  • Download a large (> 100,000) dataset of diverse color images. We found that using 1-2 training divisions of the OpenImages dataset was able to produce satisfactory results on arbitrary images. Add the dataset path under the DatasetPaths class in default_config.py.

  • For best results, as described in the paper, train an initial base model using the rate-distortion loss only, together with the hyperprior model, e.g. to target low bitrates:

# Train initial autoencoding model
python3 train.py --model_type compression --regime low --n_steps 1e6
  • Then use the checkpoint of the trained base model to 'warmstart' the GAN architecture. Please see the user's guide for more detailed instructions.
# Train using full generator-discriminator loss
python3 train.py --model_type compression_gan --regime low --n_steps 1e6 --warmstart --ckpt path/to/base/checkpoint

Compression

  • compress.py will compress generic images using some specified model. This performs a forward pass through the model to yield the quantized latent representation, which is losslessly compressed using a vectorized ANS entropy coder and saved to disk in binary format. As the model architecture is fully convolutional, this will work with images of arbitrary size/resolution (subject to memory constraints).
python3 compress.py -i path/to/image/dir -ckpt path/to/trained/model --reconstruct

The compressed format can be transmitted and decoded using the routines in compress.py. The Colab demo illustrates the decoding process.

Pretrained Models

  • Pretrained model weights using the OpenImages dataset can be found below (~2 GB). The examples at the end of this readme were produced using the HIFIC-med model. The same models are also hosted in the following Zenodo repository: https://zenodo.org/record/4026003.
Target bitrate (bpp) Weights Training Instructions
0.14 HIFIC-low
python3 train.py --model_type compression_gan --regime low --warmstart -ckpt path/to/trained/model -nrb 9 -norm
0.30 HIFIC-med
python3 train.py --model_type compression_gan --regime med --warmstart -ckpt path/to/trained/model --likelihood_type logistic
0.45 HIFIC-high
python3 train.py --model_type compression_gan --regime high --warmstart -ckpt path/to/trained/model -nrb 9 -norm

Examples

The samples below are taken from the CLIC2020 dataset, external to the training set. The bitrate is reported in bits-per-pixel (bpp). The reconstructions are produced using the above HIFIC-med model (target bitrate 0.3 bpp). It's interesting to try to guess which image is the original (images are saved as PNG for viewing - best viewed widescreen). You can expand the spoiler tags below each image to reveal the answer.

For more examples see EXAMPLES.md. For even more examples see this shared folder (images within generated using the HIFIC-low model).

A B
guess guess
Image 1
Original: A (11.8 bpp) | HIFIC: B (0.269 bpp). Ratio: 43.8
A B
guess guess
Image 2
Original: A (14.6 bpp) | HIFIC: B (0.330 bpp). Ratio: 44.2
A B
guess guess
Image 3
Original: A (12.3 bpp) | HIFIC: B (0.209 bpp). Ratio: 58.9
A B
guess guess
Image 4
Original: B (19.9 bpp) | HIFIC: A (0.565 bpp). Ratio: 35.2

The last two show interesting failure modes: small figures in the distance are almost entirely removed (top of the central rock in the penultimate image), and the required model bitrate increases significantly when the image is dominated by high-frequency components.

Authors

  • Grace Han
  • Justin Tan

Acknowledgements

Contributing

All content in this repository is licensed under the Apache-2.0 license. Please open an issue if you encounter unexpected behaviour, or have corrections/suggestions to contribute.

Citation

This is a PyTorch port of the original implementation. Please cite the original paper if you use their work.

@article{mentzer2020high,
  title={High-Fidelity Generative Image Compression},
  author={Mentzer, Fabian and Toderici, George and Tschannen, Michael and Agustsson, Eirikur},
  journal={arXiv preprint arXiv:2006.09965},
  year={2020}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].