InterDigitalInc / CompressAI

A PyTorch library and evaluation platform for end-to-end compression research
https://interdigitalinc.github.io/CompressAI/
BSD 3-Clause Clear License
1.15k stars 228 forks source link

Does CompressAI support direct compression of [y] instead of [y-mean]? #262

Open zhengxinChenee opened 9 months ago

zhengxinChenee commented 9 months ago

As stated, how can we use CompressAI to compress [y] instead of [y-mean]. Furthermore, how can we understand the advantages of compressing [y-mean]? Thank you very much for your answer!!!

YodaEmbedding commented 9 months ago

round(y-means) == round(y) if means = 0. (Or means == None works too.)

For example, just set means=None when using the desired entropy model:

        y_hat, y_likelihoods = self.gaussian_conditional(y, scales_hat, means=None)

In terms of advantages, that depends on the situation. If the source y has its most-likely-value occurring exactly at the mean, then [y - mean] will probably produce less reconstruction error since we can then reconstruct the most-likely-value with exact precision. On the other hand, if the actual values occur at locations other than the mean, then both methods will produce similar results. So... it depends.

See here for an example: https://github.com/InterDigitalInc/CompressAI/discussions/227#discussioncomment-5654273


Somewhat related concept: the deadzone quantizer used by JPEG allows near-zero DCT-transformed-and-rescaled coefficients to be rounded to zero, which helps reduce the rate since the most-likely-symbols are near zero, and reconstructing them as zero is worth the R-D tradeoff.

deadzone (Deadzone quantizer on the left. Lloyd-Max quantizer on the right.)

zhengxinChenee commented 9 months ago

Great answer! Thanks a lot! In general, compressing [y-mean] achieves better R-D tradeoff. However, in some cases, we have to compress [y] whose mean is not none. For example, in Checkerboard Context Model, we should compress [y] for one-pass encoding, and compressing [y-mean] leads to two-pass encoding. Can you make some suggestions for AE/AD of [y] using CompressAI?Thank you very much for your answer!!!

WenBingo commented 6 months ago

As stated, how can we use CompressAI to compress [y] instead of [y-mean]. Furthermore, how can we understand the advantages of compressing [y-mean]? Thank you very much for your answer!!!

Hello, I would like to ask you a question about the installation of compressai “Successfully installed compressai-1.2.4.dev0” . I successfully installed cmpressai, but I got the following error when importing:

import compressai Traceback (most recent call last): File "", line 1, in File "F:\compressai\compressai__init__.py", line 30, in from compressai import ( File "F:\compressai\compressai\latent_codecs__init__.py", line 38, in from .rasterscan import RasterScanLatentCodec File "F:\compressai\compressai\latent_codecs\rasterscan.py", line 38, in from compressai.ans import BufferedRansEncoder, RansDecoder ImportError: DLL load failed while importing ans: 找不到指定的程序。