Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about _likelihood #23

Closed
Hanawh opened this issue Jan 17, 2021 · 3 comments
Closed

question about _likelihood #23

Hanawh opened this issue Jan 17, 2021 · 3 comments
Assignees

Comments

@Hanawh
Copy link

Hanawh commented Jan 17, 2021

I am a beginner in image compression. I don’t understand why lower, upper and sign are calculated for this step.

@jbegaint
Copy link
Contributor

Upper and lower are the estimated CDF bounds for the current input, from there the densities can be derived.

You can find more information in Ballé et al. papers: End-to-end Optimized Image Compression, Variational image compression with a scale hyperprior

The sign is used for floating point optimization, this had been directly ported from the tensorflow/compression project, you can find some explanations in the comments.

@jbegaint jbegaint self-assigned this Jan 21, 2021
@Hanawh
Copy link
Author

Hanawh commented Jan 26, 2021

Thanks for your reply!

@Freed-Wu
Copy link
Contributor

    @torch.jit.unused
    def _likelihood(self, inputs: Tensor) -> Tensor:
        half = float(0.5)
        v0 = inputs - half
        v1 = inputs + half
        lower = self._logits_cumulative(v0, stop_gradient=False)
        upper = self._logits_cumulative(v1, stop_gradient=False)
        sign = -torch.sign(lower + upper)
        sign = sign.detach()
        likelihood = torch.abs(
            torch.sigmoid(sign * upper) - torch.sigmoid(sign * lower)
        )
        return likelihood

Why not

    @torch.jit.unused
    def _likelihood(self, inputs: Tensor) -> Tensor:
        half = float(0.5)
        v0 = inputs - half
        v1 = inputs + half
        lower = self._logits_cumulative(v0, stop_gradient=False)
        upper = self._logits_cumulative(v1, stop_gradient=False)
        likelihood = torch.sigmoid(upper) - torch.sigmoid(lower)
        return likelihood

I debug found

> ll = torch.sigmoid(upper) - torch.sigmoid(lower)
> likelihood.isclose(ll).all()
True
> (likelihood == ll).all()
False

Why?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants