compressors 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compressors-0.0.1/LICENSE +1 -0
- compressors-0.0.1/PKG-INFO +15 -0
- compressors-0.0.1/README.md +1 -0
- compressors-0.0.1/pyproject.toml +22 -0
- compressors-0.0.1/setup.cfg +4 -0
- compressors-0.0.1/src/compressors/evaluate.py +46 -0
- compressors-0.0.1/src/compressors.egg-info/PKG-INFO +15 -0
- compressors-0.0.1/src/compressors.egg-info/SOURCES.txt +9 -0
- compressors-0.0.1/src/compressors.egg-info/dependency_links.txt +1 -0
- compressors-0.0.1/src/compressors.egg-info/requires.txt +1 -0
- compressors-0.0.1/src/compressors.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Contact Dan Jacobellis
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: compressors
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: compresspors
|
|
5
|
+
Author-email: Dan Jacobellis <danjacobellis@utexas.edu>
|
|
6
|
+
License-Expression: LicenseRef-Proprietary
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.6
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: torch
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# codecs
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# codecs
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "compressors"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "compresspors"
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Dan Jacobellis", email = "danjacobellis@utexas.edu"}
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "LicenseRef-Proprietary"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent"
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"torch",
|
|
21
|
+
]
|
|
22
|
+
requires-python = ">=3.6"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import torch, io, datasets, PIL.Image, numpy as np
|
|
2
|
+
from piq import LPIPS, DISTS, SSIMLoss
|
|
3
|
+
from torchvision.transforms.v2.functional import pil_to_tensor, resize, to_pil_image
|
|
4
|
+
|
|
5
|
+
def kodak(encode_fn, decode_fn, resample_factor=1.0, img_format='torch', device='cuda:0'):
|
|
6
|
+
dataset = datasets.load_dataset("danjacobellis/kodak")['validation']
|
|
7
|
+
lpips_loss, dists_loss, ssim_loss = LPIPS().to(device), DISTS().to(device), SSIMLoss().to(device)
|
|
8
|
+
|
|
9
|
+
def evaluate_quality(sample):
|
|
10
|
+
img = sample['image']
|
|
11
|
+
orig_size = (img.height, img.width)
|
|
12
|
+
pixels = img.width * img.height
|
|
13
|
+
|
|
14
|
+
if resample_factor != 1.0:
|
|
15
|
+
new_size = (int(img.height * resample_factor), int(img.width * resample_factor))
|
|
16
|
+
img = img.resize((new_size[1], new_size[0]), PIL.Image.LANCZOS)
|
|
17
|
+
|
|
18
|
+
if img_format == 'torch':
|
|
19
|
+
x_in = pil_to_tensor(img).float() / 127.5 - 1.0
|
|
20
|
+
buff = encode_fn(x_in)
|
|
21
|
+
x_dec = decode_fn(buff)
|
|
22
|
+
if resample_factor != 1.0:
|
|
23
|
+
x_dec = resize(x_dec, orig_size)
|
|
24
|
+
x_hat_01 = (x_dec.to(device) / 2 + 0.5).unsqueeze(0)
|
|
25
|
+
else:
|
|
26
|
+
buff = encode_fn(img)
|
|
27
|
+
dec_img = decode_fn(buff)
|
|
28
|
+
if resample_factor != 1.0:
|
|
29
|
+
dec_img = dec_img.resize((orig_size[1], orig_size[0]), PIL.Image.LANCZOS)
|
|
30
|
+
x_hat_01 = (pil_to_tensor(dec_img).to(device).float() / 127.5 - 1.0).unsqueeze(0) / 2 + 0.5
|
|
31
|
+
|
|
32
|
+
x_orig_01 = (pil_to_tensor(sample['image']).to(device).float() / 127.5 - 1.0).unsqueeze(0) / 2 + 0.5
|
|
33
|
+
size_bytes = len(buff.getbuffer()) if hasattr(buff, 'getbuffer') else len(buff)
|
|
34
|
+
|
|
35
|
+
mse = torch.nn.functional.mse_loss(x_orig_01[0], x_hat_01[0])
|
|
36
|
+
return {
|
|
37
|
+
'pixels': pixels,
|
|
38
|
+
'bpp': 8 * size_bytes / pixels,
|
|
39
|
+
'PSNR': -10 * mse.log10().item(),
|
|
40
|
+
'LPIPS_dB': -10 * np.log10(lpips_loss(x_orig_01, x_hat_01).item()),
|
|
41
|
+
'DISTS_dB': -10 * np.log10(dists_loss(x_orig_01, x_hat_01).item()),
|
|
42
|
+
'SSIM': 1 - ssim_loss(x_orig_01, x_hat_01).item(),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
results = dataset.map(evaluate_quality)
|
|
46
|
+
return {m: float(np.mean(results[m])) for m in ['pixels', 'bpp', 'PSNR', 'LPIPS_dB', 'DISTS_dB', 'SSIM']}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: compressors
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: compresspors
|
|
5
|
+
Author-email: Dan Jacobellis <danjacobellis@utexas.edu>
|
|
6
|
+
License-Expression: LicenseRef-Proprietary
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.6
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: torch
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# codecs
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/compressors/evaluate.py
|
|
5
|
+
src/compressors.egg-info/PKG-INFO
|
|
6
|
+
src/compressors.egg-info/SOURCES.txt
|
|
7
|
+
src/compressors.egg-info/dependency_links.txt
|
|
8
|
+
src/compressors.egg-info/requires.txt
|
|
9
|
+
src/compressors.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
torch
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
compressors
|