GithubHelp home page GithubHelp logo

necla-ml / diff-jpeg Goto Github PK

View Code? Open in Web Editor NEW
80.0 6.0 5.0 24.64 MB

Official and maintained implementation of the paper "Differentiable JPEG: The Devil is in the Details" [WACV 2024].

Home Page: https://christophreich1996.github.io/differentiable_jpeg/

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
differentiable-codec image-codec image-compression jpeg pytorch wacv differentiable-jpeg ste surrogate

diff-jpeg's People

Contributors

christophreich1996 avatar eltociear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

diff-jpeg's Issues

Is this logic judgement reversed?

In Diff-JPEG-main/diff_jpeg/clipping.py line 56:

grad: Tensor = torch.where(torch.logical_or(input >= ctx.min, input >= ctx.max), 1.0, ctx.scale) * grad_output

should this be:

grad: Tensor = torch.where(torch.logical_or(input <= ctx.min, input >= ctx.max), 1.0, ctx.scale) * grad_output

Expected size of input image?

I'm trying to run the example on a 2160x1080 .png file but I'm getting this error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[4], line 12
     10 jpeg_quality: Tensor = torch.tensor([2.0])
     11 # Perform differentiable JPEG coding
---> 12 image_coded: Tensor = diff_jpeg_coding(image_rgb=image, jpeg_quality=jpeg_quality)

File ~/miniconda3/lib/python3.9/site-packages/diff_jpeg/jpeg.py:49, in diff_jpeg_coding(image_rgb, jpeg_quality, quantization_table_y, quantization_table_c, ste)
     47 _, _, H, W = image_rgb.shape  # type: int, int, int, int
     48 # Perform encoding
---> 49 y_encoded, cb_encoded, cr_encoded = jpeg_encode(
     50     image_rgb=image_rgb,
     51     jpeg_quality=jpeg_quality,
     52     quantization_table_c=quantization_table_c,
     53     quantization_table_y=quantization_table_y,
     54     rounding_function=rounding_function,
     55     floor_function=floor_function,
     56     clipping_function=clipping_function,
     57 )  # type: Tensor, Tensor, Tensor
     58 image_rgb_jpeg: Tensor = jpeg_decode(
     59     input_y=y_encoded,
     60     input_cb=cb_encoded,
   (...)
     68     clipping_function=clipping_function,
     69 )
     70 # Clip coded image

File ~/miniconda3/lib/python3.9/site-packages/diff_jpeg/encode.py:142, in jpeg_encode(image_rgb, jpeg_quality, rounding_function, floor_function, clipping_function, quantization_table_y, quantization_table_c)
    140 input_y, input_cb, input_cr = chroma_subsampling(image_ycbcr)  # type: Tensor, Tensor, Tensor
    141 # Patchify, DCT, and rounding
--> 142 input_y, input_cb, input_cr = patchify_8x8(input_y), patchify_8x8(input_cb), patchify_8x8(input_cr)
    143 dct_y, dct_cb, dct_cr = dct_8x8(input_y), dct_8x8(input_cb), dct_8x8(input_cr)  # type: Tensor, Tensor, Tensor
    144 y_encoded: Tensor = quantize(
    145     dct_y,
    146     jpeg_quality,
   (...)
    150     clipping_function=clipping_function,
    151 )

File ~/miniconda3/lib/python3.9/site-packages/diff_jpeg/encode.py:22, in patchify_8x8(input)
     20 B, H, W = input.shape  # type: int, int, int
     21 # Patchify to shape [B, N, H // 8, W // 8]
---> 22 output: Tensor = input.view(B, H // 8, 8, W // 8, 8).permute(0, 1, 3, 2, 4).reshape(B, -1, 8, 8)
     23 return output

RuntimeError: shape '[1, 67, 8, 135, 8]' is invalid for input of size 583200

Is there an expectation on the size of the input image?

About batch size

When I set batch_size to 2, the output of the encoder is abnormal, as shown below:

Snipaste_2024-07-28_21-28-20

This will lead to problems in the final result, how to solve it?

B, N, _, _ = input.shape  # type: int, int, int, int

ValueError: too many values to unpack (expected 4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.