diffjpeg-jax

Official and maintained implementation of the paper "Differentiable JPEG: The Devil is in the Details" (WACV 2024)

https://github.com/necla-ml/diff-jpeg

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.8%) to scientific vocabulary

Keywords

differentiable-codec differentiable-jpeg image-codec image-compression jpeg pytorch ste surrogate wacv

Keywords from Contributors

medical-imaging
Last synced: 6 months ago · JSON representation ·

Repository

Official and maintained implementation of the paper "Differentiable JPEG: The Devil is in the Details" (WACV 2024)

Basic Info
Statistics
  • Stars: 97
  • Watchers: 6
  • Forks: 5
  • Open Issues: 2
  • Releases: 0
Topics
differentiable-codec differentiable-jpeg image-codec image-compression jpeg pytorch ste surrogate wacv
Created over 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

Differentiable JPEG: The Devil is in the Details

arXiv License Framework

Christoph Reich , Biplob Debnath , Deep Patel & Srimat Chakradhar

| Project Page | Paper | Poster | Talk |

1

This repository includes the official and maintained implementation of the differentiable JPEG approach proposed in the paper Differentiable JPEG: The Devil is in the Details.

Abstract

JPEG remains one of the most widespread lossy image coding methods. However, the non-differentiable nature of JPEG restricts the application in deep learning pipelines. Several differentiable approximations of JPEG have recently been proposed to address this issue. This paper conducts a comprehensive review of existing differentiable JPEG approaches and identifies critical details that have been missed by previous methods. To this end, we propose a novel differentiable JPEG approach, overcoming previous limitations. Our approach is differentiable w.r.t. the input image, the JPEG quality, the quantization tables, and the color conversion parameters. We evaluate the forward and backward performance of our differentiable JPEG approach against existing methods. Additionally, extensive ablations are performed to evaluate crucial design choices. Our proposed differentiable JPEG resembles the (non-differentiable) reference implementation best, significantly surpassing the recent-best differentiable approach by 3.47dB (PSNR) on average. For strong compression rates, we can even improve PSNR by 9.51dB. Strong adversarial attack results are yielded by our differentiable JPEG, demonstrating the effective gradient approximation.

If you use our differentiable JPEG or find this research useful in your work, please cite our paper:

bibtex @inproceedings{Reich2024, author={Reich, Christoph and Debnath, Biplob and Patel, Deep and Chakradhar, Srimat}, title={{Differentiable JPEG: The Devil is in the Details}}, booktitle={{WACV}}, year={2024} }

Installation

Our differentiable JPEG implementation can be installed as a Python package by running:

shell script pip install git+https://github.com/necla-ml/Diff-JPEG

All dependencies are listed in requirements.txt.

Usage

We offer both a functional and class (nn.Module) implementation of our differentiable JPEG approach. Note beyond the examples provided here we also have an example.py file.

The following example showcases the use of the functional implementation.

```python import torch import torchvision from torch import Tensor

from diffjpeg import diffjpeg_coding

Load test image and reshape to [B, 3, H, W]

image: Tensor = torchvision.io.readimage("testimages/test_image.png").float()[None]

Init JPEG quality

jpeg_quality: Tensor = torch.tensor([2.0])

Perform differentiable JPEG coding

imagecoded: Tensor = diffjpegcoding(imagergb=image, jpegquality=jpegquality) ```

In the following code example, the class (nn.Module) implementation is used.

```python import torch import torch.nn as nn import torchvision from torch import Tensor

from diff_jpeg import DiffJPEGCoding

Init module

diffjpegcoding_module: nn.Module = DiffJPEGCoding()

Load test image and reshape to [B, 3, H, W]

image: Tensor = torchvision.io.readimage("testimages/test_image.png").float()[None]

Init JPEG quality

jpeg_quality: Tensor = torch.tensor([19.04])

Perform differentiable JPEG coding

imagecoded: Tensor = diffjpegcodingmodule(imagergb=image, jpegquality=jpeg_quality) ```

STE Variant

To utilize the proposed straight-through estimator (STE) variant just set the ste: bool = True parameter.

```python

Perform differentiable JPEG coding

imagecoded: Tensor = diffjpegcoding(imagergb=image, jpegquality=jpegquality, ste=True) ```

```python

Init module

diffjpegcoding_module: nn.Module = DiffJPEGCoding(ste=True) ```

Custom Quantization Tables

Both the diff_jpeg_coding function and the forward function of DiffJPEGCoding offer the option to use custom quantization tables. Just use the quantization_table_y: Optional[Tensor] and quantization_table_c: Optional[Tensor] parameter. Both parameters are required to be a torch.Tensor of the shape [8, 8]. If no quantization table is given (or set to None), the respective standard JPEG quantization tables are utilized.

Here we provide two examples of using a custom quantization table.

```python import torch import torchvision from torch import Tensor

from diffjpeg import diffjpeg_coding

Load test image and reshape to [B, 3, H, W]

image: Tensor = torchvision.io.readimage("testimages/test_image.png").float()[None]

Init JPEG quality

jpeg_quality: Tensor = torch.tensor([2.0])

Perform differentiable JPEG coding

imagecoded: Tensor = diffjpegcoding( imagergb=image, jpegquality=jpegquality, quantizationtabley=torch.randint(low=1, high=256, size=(8, 8)), quantizationtablec=torch.randint(low=1, high=256, size=(8, 8)), ) ```

```python import torch import torch.nn as nn import torchvision from torch import Tensor

from diff_jpeg import DiffJPEGCoding

Init module

diffjpegcoding_module: nn.Module = DiffJPEGCoding()

Load test image and reshape to [B, 3, H, W]

image: Tensor = torchvision.io.readimage("testimages/test_image.png").float()[None]

Init JPEG quality

jpeg_quality: Tensor = torch.tensor([19.04])

Perform differentiable JPEG coding

imagecoded: Tensor = diffjpegcodingmodule( imagergb=image, jpegquality=jpegquality, quantizationtabley=torch.randint(low=1, high=256, size=(8, 8)), quantizationtable_c=torch.randint(low=1, high=256, size=(8, 8)), ) ```

Issues

If you encounter any issues with this implementation please open a GitHub issue!

Owner

  • Name: NECLA ML Group
  • Login: necla-ml
  • Kind: organization
  • Location: Princeton, NJ

NEC Labs America, Machine Learning Group

Citation (CITATION.cff)

cff-version: 1.2.0
message: "Code of the paper: Differentiable JPEG: The Devil is in the Details [WACV 2024]"
authors:
  - family-names: Reich
    given-names: Christoph
  - family-names: Debnath
    given-names: Biplob
  - family-names: Patel
    given-names: Deep
  - family-names: Chakradhar
    given-names: Srimat
title: "Differentiable JPEG: The Devil is in the Details [WACV 2024]"
version: 1.0.0
doi: 10.48550/arXiv.2309.06978
date-released: 2023-10-13

GitHub Events

Total
  • Watch event: 15
Last Year
  • Watch event: 15

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 20
  • Total Committers: 3
  • Avg Commits per committer: 6.667
  • Development Distribution Score (DDS): 0.1
Past Year
  • Commits: 9
  • Committers: 1
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Christoph Reich 3****6 18
ChristophReich1996 c****h@g****t 1
Ikko Eltociear Ashimine e****r@g****m 1
Committer Domains (Top 20 + Academic)
gmx.net: 1

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 5
  • Total pull requests: 1
  • Average time to close issues: about 6 hours
  • Average time to close pull requests: about 2 hours
  • Total issue authors: 5
  • Total pull request authors: 1
  • Average comments per issue: 1.8
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 0
  • Average time to close issues: about 2 hours
  • Average time to close pull requests: N/A
  • Issue authors: 3
  • Pull request authors: 0
  • Average comments per issue: 0.67
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • silencecmsj (1)
  • AlexCHENSiyu (1)
  • ZhangYuef (1)
  • alecjacobson (1)
  • hugga1 (1)
Pull Request Authors
  • eltociear (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 111 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
pypi.org: diffjpeg-jax

DiffJPEG implemented in JAX

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 111 Last month
Rankings
Dependent packages count: 10.0%
Average: 38.1%
Dependent repos count: 66.2%
Maintainers (1)
Last synced: about 1 year ago

Dependencies

requirements.txt pypi
  • Pillow >=9.2.0
  • kornia >=0.6.11
  • matplotlib >=3.5.2
  • opencv-python *
  • scipy >=1.0.0
  • torch >=1.0.0
  • torchvision >=0.14.0
setup.py pypi
  • torch >=1.0.0,