Home

Awesome

Implicit Neural Representations for Image Compression

Paper

<img src='img/INRgraph.jpg'>

Requirements:

Repository Overview

The repository contains the following folders:

Environment Setup

To create a conda environment for image compression and install all requirements run inside the project directory:

<pre><code> conda env create --file environment.yml conda activate INRcompress export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/lib/aimet_common/x86_64-linux-gnu:$(pwd)/lib/aimet_common export PYTHONPATH=$PYTHONPATH:$(pwd)/lib/aimet_common/x86_64-linux-gnu:$(pwd)/lib/aimet_common:$(pwd)/lib:$(pwd) </code></pre>

If you wish to also install the dependencies to run the 3D shape compression code:

<pre><code> conda env create --file environment3D.yml conda activate INRcompress3D export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/lib/aimet_common/x86_64-linux-gnu:$(pwd)/lib/aimet_common export PYTHONPATH=$PYTHONPATH:$(pwd)/lib/aimet_common/x86_64-linux-gnu:$(pwd)/lib/aimet_common:$(pwd)/lib:$(pwd) </code></pre>

Implicit Neural Representations (INRs) 101

INRs are a way to represent coordinate based data as a function. For example, an image is nothing else but a function f(x,y) = (R,G,B), namely we assign a (R,G,B) color to the pixel at location (x,y). We can train a neural network to fit this function by optimization and what you get is an INR.

Datasets

We provide scripts for DIV2K and Kodak that automatically download the dataset in the data directory. For CelebA please follow these steps:

We provide an example 3D shape, that is already normalized, in data/armadillo. The other shapes are available from The Stanford 3D Scanning Repository.

Code Overview

To seperate dependencies, we split the code into two parts, namely 'image_compression' and 'shape_compression'. We briefly describe the role of the individual python files in the folder 'image_compression' here.

The shape compression code follows the same structure, the only difference is that the scripts for overfitting and named 'overfitINR3D.py' and 'quantize_and_test3D.py'.

Running Image Compression with INRs

Option 1: Basic Method: Overfitting from random initialization

Run

python overfitINR.py <general flags> <architecture flags> <overfitting flags>

to overfit an INR to single images. This function takes the following arguments as flags: <br>

<general flags>:

<architecture flags>:

<overfitting flags>:

Option 2: Meta-learned Method: Overfitting from MAML initialization

First train the MAML initialization:

python image_compression/trainMetaSiren.py <general flags> <architecture flags> <MAML flags>

This function takes a very similar set of parameters as listed above with a few additional ones that are MAML specific: <MAML flags>:

Once we have the MAML initialization we can overfit single images starting from that initialization. The MAML initialization are stored in a 'maml' subfolder in the exp_root By providing the same architecture flags and exp_root as in the MAML training step, the correct initialization will be automatically found when running:

python image_compression/overfitMetaSiren.py <general flags> <overfitting flags> <MAML flags>

You also need to pass the MAML flags from above to overfitMetaSiren.py. This differs from normal overfitting in that we first perform an inner loop optimization to leverage the learned learning rates. Then we continue with the overfitting as in Option A.

Quantization, AdaRound, QAT, Entropy Coding

The compression pipeline is run with the command:

python image_compression/quantize_and_test.py --exp_glob <my_experiments_regular_expression> <general flags> <quantization flags>

Please provide the experiment name(s) you want to run this for as the exp_glob as a regular expression. If exp_glob is set to '*' all experiments in the exp_root directory will get quantized. This script automatically detects models that were trained with a MAML initilization and uses it for quantization in this case. Note that the architecture of the model gets extracted from the training flags in FLAGS.yml stored in the experiment folder. Arguments you can modify through flags:

<quantization flags>:

Example Experiment Scripts

We provide example scripts in the folder 'experiment_scripts' that use our chosen hyperparameters to reproduce the main result (Fig.4) from the paper:

Run

chmod +x examples/run_basic_kodak.sh 
examples/run_basic_kodak.sh 

or similarly for the other scripts.

Running 3D Shape Compression with INRs

As an additional experiment, we showed in the paper that INRs are also effective for compression 3D shapes. At this point, we only support the overfitting functionality for shapes. The procedure is almost the same as for images, hence we will only point out the differences.

Normalizing the shapes

To learn the representaions we first need to normalize the '.obj' shapes to the unit cube. For this we run:

python shape_compression/normalize_shapes.py --shape_glob "<path_path_to_my_shape_dataset>/*.obj"

Note that the double quotes " " are needed here to prevent Linux from evaluating the regular expression. If the shapes are deeper inside a directory tree, modify the glob expression to: "<path_path_to_my_shape_dataset>/**/*.obj"

Overfitting a 3D shape

Run

python shape_compression/overfitINR3D.py <general flags> <architecture flags> <overfitting flags>

to overfit an INR to all individual shapes in the dataset.

The flags this function takes are the same as for overfitting an image, except:

Quantization, AdaRound, QAT, Entropy Coding for 3D shapes

The compression pipeline for 3D shapes is run with the command:

python shape_compression/quantize_and_test3D.py --exp_glob <my_experiment_regular_expression> <general flags> <quantization flags>

The overfitting flags for this function are the same as for image_compression. (The architecture flags, samples_per_shape and batch_size are extracted from the training flags stored in FLAGS.yml)

Acknowledgement

We make use of the code published in the following repositories:

Citation

@inproceedings{strumpler2022inrcompress,
  title={Implicit Neural Representations for Image Compression},
  author={Yannick Strümpler and Janis Postels and Ren Yang and Luc Van Gool and Federico Tombari},
  year={2022},
  booktitle={ECCV},
}