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

How to control the model's bpp? #185

Closed hot-dog closed 1 year ago

hot-dog commented 1 year ago

First of all, thanks for your excellent work! I am new to image compression field and i have got a question. I want to train a model with bpp approximatly at 0.8, what should i do? Can i do this by setting the training hyper-parameters such as quality, lambda? Is there a formula between model's bpp and these training hyper-parameters?

YodaEmbedding commented 1 year ago

These lambda values should give you an approximate guideline. Compare the qualities with the RD plot below. No exact formula exists, though you can get a reasonable estimate by doing logarithmic interpolation of lambda between adjacent points on the RD curve.

For bpp=0.8, try somewhere around lmbda=0.03.

Experimental approach

Typically, most models trained from scratch quickly converge to their final bpp values (+/- 10%) within the first 1-10 epochs.

If you want to target a specific bpp with more precision than this, take a pretrained model, and then reduce its lambda value by a bit, and train for ~1 epoch. The resulting bpp value should be within +/- 5% of the final bpp. Repeat as desired.

fracape commented 1 year ago

Since you don't mention if you have a specific image / test set for which you need an encode at 0.8bpp, also note that the bitrate is very dependent on the content. The above is true if you keep Kodak as your reference test set for instance. You may want to check with your dataset if different. Even with Kodak, the figure below shows you how different the bpp and qualities can be using the same lambda among the images of Kodak (light blue). The orange dot is the average on Kodak for that particular lambda.

image
hot-dog commented 1 year ago

Thanks for your explanation, i get it :). Issue closed!