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.19k stars 232 forks source link

About lambda #27

Closed Hanawh closed 3 years ago

Hanawh commented 3 years ago

Sorry to bother you again. I have another question. I want to know what the value of lambda in loss function depends on. If the picture I use is 112x112, do I need to adjust the lambda in config, or do I need to search for the lambda value

jbegaint commented 3 years ago

Hi, no the lambda is used to balance the two terms in the rate distortion function: the estimated bit-rate and the distortion. The lower the lambda, the more the distortion is penalized over the rate term, which will result in a higher compression rate but a lower reconstruction quality. You may need to search different lambdas to achieve different bit-rates (for example on a logarithmic scale).

jbegaint commented 3 years ago

Closing this for now. Please let us know if you encounter any bug or issue.

kepengxu commented 3 years ago

hello , can you share the diffenent lambda value in quilty 1......8

jbegaint commented 3 years ago

https://interdigitalinc.github.io/CompressAI/zoo.html#training

Freed-Wu commented 1 year ago

Can the diffenent lambda values in quilty 1......8 be provided in compressai/losses/__init__.py? such as

from compressai.losses import q2lambda, RateDistortionLoss
loss_function = RateDistortionLoss(q2lambda(q))
Freed-Wu commented 1 year ago

And can users be allowed to define the output type of RateDistortionLoss? such as

from typing import Literal
class RateDistortionLoss(nn.Module):
    def __init__(self, lmbda: float=1e-2, return_type: Literal["bpp_loss", "mse_loss", "loss", "all"]="all"):
    def forward(self, output, target):
        if self.return_type == "all":
          return out
        else:
          return out[return_type]
Freed-Wu commented 1 year ago

And now RateDistortionLoss only support MSE. Can it support ms-ssim?

Freed-Wu commented 1 year ago

Now compressai model's output is a dict like {"x_hat": torch.Tensor, "likelihoods": XXX}. However many loss function expect only torch.Tensor (i.e, x_hat). Can it provide a decorator to wrap these functions?