Jacobellis Dan (dgj335) commited on
Commit
6a8d727
·
1 Parent(s): 051155c

entropy coding

Browse files
README.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
README.md CHANGED
@@ -1,7 +1,3 @@
1
- ---
2
- datasets:
3
- - danjacobellis/LSDIR_540
4
- ---
5
  ```python
6
  !pip install walloc PyWavelets pytorch-wavelets
7
  ```
@@ -13,8 +9,10 @@ datasets:
13
 
14
 
15
  ```python
 
16
  import torch
17
  import matplotlib.pyplot as plt
 
18
  from PIL import Image
19
  from IPython.display import display
20
  from torchvision.transforms import ToPILImage, PILToTensor
@@ -25,14 +23,14 @@ class Args: pass
25
 
26
  ```python
27
  device = "cpu"
28
- checkpoint = torch.load("v0.5.1.pth",map_location="cpu")
29
  args = checkpoint['args']
30
  codec = Walloc(
31
  channels = args.channels,
32
  J = args.J,
33
  N = args.N,
34
  latent_dim = args.latent_dim,
35
- latent_bits = 6
36
  )
37
  codec.load_state_dict(checkpoint['model_state_dict'])
38
  codec = codec.to(device)
@@ -84,7 +82,7 @@ with torch.no_grad():
84
  print(f"dimensionality reduction: {x.numel()/Y.numel()}x")
85
  ```
86
 
87
- dimensionality reduction: 16.0x
88
 
89
 
90
 
@@ -95,18 +93,15 @@ Y.unique()
95
 
96
 
97
 
98
- tensor([-31., -30., -29., -28., -27., -26., -25., -24., -23., -22., -21., -20.,
99
- -19., -18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8.,
100
- -7., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4.,
101
- 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16.,
102
- 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28.,
103
- 29., 30., 31.])
104
 
105
 
106
 
107
 
108
  ```python
109
- plt.hist(Y.flatten().numpy(),range=(-32,32),bins=65);
110
  ```
111
 
112
 
@@ -117,28 +112,33 @@ plt.hist(Y.flatten().numpy(),range=(-32,32),bins=65);
117
 
118
 
119
  ```python
120
- for latent in Y[0,:4,:,:]:
121
- display(ToPILImage()(0.5*latent/codec.latent_max + 0.5).resize((192,128),resample=Image.Resampling.NEAREST))
 
 
 
 
 
 
 
 
 
122
  ```
123
 
124
 
125
-
126
- ![png](README_files/README_9_0.png)
127
-
128
-
129
 
130
 
131
 
132
- ![png](README_files/README_9_1.png)
133
 
134
 
135
 
136
 
137
-
138
- ![png](README_files/README_9_2.png)
139
-
140
 
 
 
 
 
141
 
 
142
 
143
-
144
- ![png](README_files/README_9_3.png)
 
 
 
 
 
1
  ```python
2
  !pip install walloc PyWavelets pytorch-wavelets
3
  ```
 
9
 
10
 
11
  ```python
12
+ import os
13
  import torch
14
  import matplotlib.pyplot as plt
15
+ import numpy as np
16
  from PIL import Image
17
  from IPython.display import display
18
  from torchvision.transforms import ToPILImage, PILToTensor
 
23
 
24
  ```python
25
  device = "cpu"
26
+ checkpoint = torch.load("v0.6.1.pth",map_location="cpu")
27
  args = checkpoint['args']
28
  codec = Walloc(
29
  channels = args.channels,
30
  J = args.J,
31
  N = args.N,
32
  latent_dim = args.latent_dim,
33
+ latent_bits = 5
34
  )
35
  codec.load_state_dict(checkpoint['model_state_dict'])
36
  codec = codec.to(device)
 
82
  print(f"dimensionality reduction: {x.numel()/Y.numel()}x")
83
  ```
84
 
85
+ dimensionality reduction: 12.0x
86
 
87
 
88
 
 
93
 
94
 
95
 
96
+ tensor([-15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4.,
97
+ -3., -2., -1., 0., 1., 2., 3., 4., 5., 6., 7., 8.,
98
+ 9., 10., 11., 12., 13., 14., 15.])
 
 
 
99
 
100
 
101
 
102
 
103
  ```python
104
+ plt.hist(Y.flatten().numpy(),range=(-17.5,17.5),bins=35);
105
  ```
106
 
107
 
 
112
 
113
 
114
  ```python
115
+ grid_size = 4
116
+ n_channels, H, W = Y[0].shape
117
+ combined_image = Image.new('L', (W * grid_size, H * grid_size))
118
+ size_bytes = 0
119
+ for i, channel in enumerate(Y[0]):
120
+ channel = (channel+16).to(torch.uint8)
121
+ row = i // grid_size
122
+ col = i % grid_size
123
+ channel = ToPILImage()(channel)
124
+ combined_image.paste(channel, (col * W, row * H))
125
+ combined_image
126
  ```
127
 
128
 
 
 
 
 
129
 
130
 
131
 
132
+ ![png](README_files/README_9_0.png)
133
 
134
 
135
 
136
 
 
 
 
137
 
138
+ ```python
139
+ combined_image.save('tmp.png')
140
+ print("compression_ratio: ", x.numel()/os.path.getsize("tmp.png"))
141
+ ```
142
 
143
+ compression_ratio: 20.75383532723434
144
 
 
 
README_files/README_5_0.jpg CHANGED

Git LFS Details

  • SHA256: 3aec80fdd2f145ca0a4ded3366c14cb924db78164c03e72a9e0c428149841965
  • Pointer size: 130 Bytes
  • Size of remote file: 80.2 kB

Git LFS Details

  • SHA256: 2b46455c8bc7292b1abcade03f37969c71f12f5c35adca2f79147935c9220015
  • Pointer size: 130 Bytes
  • Size of remote file: 87.8 kB
README_files/README_5_0.png CHANGED

Git LFS Details

  • SHA256: 3e369ae447849364fb12f9876c678e86212efaf4a4bb3df5daa5124c73ba1972
  • Pointer size: 131 Bytes
  • Size of remote file: 709 kB

Git LFS Details

  • SHA256: c140f4a815c2ce36a8c01985b2e13ee48367dfb0e6bc1fe49413e3324dbe699a
  • Pointer size: 131 Bytes
  • Size of remote file: 769 kB
README_files/README_8_0.png CHANGED

Git LFS Details

  • SHA256: 47de82592423ffd1ac9b3eb111fe74ef688cacd03704330fb88b2d5954cf8b38
  • Pointer size: 130 Bytes
  • Size of remote file: 12.4 kB

Git LFS Details

  • SHA256: cb722ebdab9bf4ec5af4dc20a273ca50efcca97a5981e92f58196279277a7396
  • Pointer size: 130 Bytes
  • Size of remote file: 11.3 kB
README_files/README_9_0.jpg CHANGED

Git LFS Details

  • SHA256: 6f8d9f49891f70f8db7db670cfeceddd6cc134731257b245a0a7775e0915a60e
  • Pointer size: 129 Bytes
  • Size of remote file: 5.05 kB

Git LFS Details

  • SHA256: 4b303c0293677c27a12ea22f6f39ad2c60a9919e14fdc4b95f3aef78acecd5de
  • Pointer size: 129 Bytes
  • Size of remote file: 8.92 kB
README_files/README_9_0.png CHANGED

Git LFS Details

  • SHA256: cfdbfed35d4fb4ddd9842950e556aaec92f58b347b266a5c8818e26958acf1e6
  • Pointer size: 129 Bytes
  • Size of remote file: 2.56 kB

Git LFS Details

  • SHA256: abe2cb2b68637bc23efab8b138364d413038aca94e329fe27fd14dac2ab1296b
  • Pointer size: 130 Bytes
  • Size of remote file: 64.5 kB
walloc.ipynb DELETED
The diff for this file is too large to render. See raw diff