Jacobellis Dan (dgj335)
commited on
Commit
·
c5a3e9a
1
Parent(s):
c518ce5
allow 1, 3, or 4 channels for entropy coding
Browse files- README.ipynb +0 -0
- README.md +44 -14
- README_files/README_12_0.png +0 -0
- README_files/README_14_0.jpg +0 -0
- README_files/README_16_0.jpg +0 -0
- README_files/README_16_0.png +0 -0
- README_files/README_18_0.jpg +0 -0
- README_files/README_8_0.jpg +0 -0
- README_files/README_8_0.png +2 -2
README.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
README.md
CHANGED
@@ -34,6 +34,7 @@ from PIL import Image
|
|
34 |
from IPython.display import display
|
35 |
from torchvision.transforms import ToPILImage, PILToTensor
|
36 |
from walloc import walloc
|
|
|
37 |
class Args: pass
|
38 |
```
|
39 |
|
@@ -127,7 +128,7 @@ Y.unique()
|
|
127 |
|
128 |
|
129 |
tensor([-15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4.,
|
130 |
-
-3., -2., -1.,
|
131 |
9., 10., 11., 12., 13., 14., 15.])
|
132 |
|
133 |
|
@@ -151,43 +152,72 @@ plt.xticks(range(-15,16,5));
|
|
151 |
|
152 |
|
153 |
|
154 |
-
# Lossless compression of latents
|
|
|
|
|
155 |
|
156 |
|
157 |
```python
|
158 |
-
Y_pil =
|
159 |
-
Y_pil[0]
|
|
|
|
|
|
|
|
|
|
|
160 |
```
|
161 |
|
162 |
|
163 |
-
|
164 |
-
|
165 |
|
166 |
-
![
|
167 |
|
168 |
|
169 |
|
|
|
|
|
|
|
|
|
170 |
|
171 |
|
172 |
```python
|
|
|
|
|
173 |
Y_pil[0].save('latent.webp',lossless=True)
|
174 |
-
|
|
|
|
|
|
|
175 |
```
|
176 |
|
177 |
-
compression_ratio: 26.13425495148212
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
|
181 |
```python
|
182 |
-
|
183 |
-
(
|
|
|
|
|
|
|
|
|
|
|
184 |
```
|
185 |
|
186 |
|
|
|
|
|
|
|
187 |
|
188 |
|
189 |
-
|
190 |
-
|
191 |
|
192 |
|
193 |
|
@@ -198,7 +228,7 @@ Y2 = walloc.pil_to_latent(Y_pil, 16, 5)
|
|
198 |
[NbConvertApp] Converting notebook README.ipynb to markdown
|
199 |
[NbConvertApp] Support files will be in README_files/
|
200 |
[NbConvertApp] Making directory README_files
|
201 |
-
[NbConvertApp] Writing
|
202 |
|
203 |
|
204 |
|
|
|
34 |
from IPython.display import display
|
35 |
from torchvision.transforms import ToPILImage, PILToTensor
|
36 |
from walloc import walloc
|
37 |
+
from walloc.walloc import latent_to_pil, pil_to_latent
|
38 |
class Args: pass
|
39 |
```
|
40 |
|
|
|
128 |
|
129 |
|
130 |
tensor([-15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4.,
|
131 |
+
-3., -2., -1., -0., 1., 2., 3., 4., 5., 6., 7., 8.,
|
132 |
9., 10., 11., 12., 13., 14., 15.])
|
133 |
|
134 |
|
|
|
152 |
|
153 |
|
154 |
|
155 |
+
# Lossless compression of latents
|
156 |
+
|
157 |
+
### Single channel PNG (L)
|
158 |
|
159 |
|
160 |
```python
|
161 |
+
Y_pil = latent_to_pil(Y,5,1)
|
162 |
+
display(Y_pil[0])
|
163 |
+
Y_pil[0].save('latent.png')
|
164 |
+
png = [Image.open("latent.png")]
|
165 |
+
Y_rec = pil_to_latent(png,16,5,1)
|
166 |
+
assert(Y_rec.equal(Y))
|
167 |
+
print("compression_ratio: ", x.numel()/os.path.getsize("latent.png"))
|
168 |
```
|
169 |
|
170 |
|
|
|
|
|
171 |
|
172 |
+
![png](README_files/README_14_0.png)
|
173 |
|
174 |
|
175 |
|
176 |
+
compression_ratio: 20.307596963280485
|
177 |
+
|
178 |
+
|
179 |
+
### Three channel WebP (RGB)
|
180 |
|
181 |
|
182 |
```python
|
183 |
+
Y_pil = latent_to_pil(Y[:,:12],5,3)
|
184 |
+
display(Y_pil[0])
|
185 |
Y_pil[0].save('latent.webp',lossless=True)
|
186 |
+
webp = [Image.open("latent.webp")]
|
187 |
+
Y_rec = pil_to_latent(webp,16,5,3)
|
188 |
+
assert(Y_rec.equal(Y[:,:12]))
|
189 |
+
print("compression_ratio: ", (12/16)*x.numel()/os.path.getsize("latent.webp"))
|
190 |
```
|
191 |
|
|
|
192 |
|
193 |
+
|
194 |
+
![png](README_files/README_16_0.png)
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
compression_ratio: 21.436712541190154
|
199 |
+
|
200 |
+
|
201 |
+
### Four channel TIF (CMYK)
|
202 |
|
203 |
|
204 |
```python
|
205 |
+
Y_pil = latent_to_pil(Y,5,4)
|
206 |
+
display(Y_pil[0])
|
207 |
+
Y_pil[0].save('latent.tif',compression="tiff_adobe_deflate")
|
208 |
+
tif = [Image.open("latent.tif")]
|
209 |
+
Y_rec = pil_to_latent(tif,16,5,4)
|
210 |
+
assert(Y_rec.equal(Y))
|
211 |
+
print("compression_ratio: ", x.numel()/os.path.getsize("latent.png"))
|
212 |
```
|
213 |
|
214 |
|
215 |
+
|
216 |
+
![jpeg](README_files/README_18_0.jpg)
|
217 |
+
|
218 |
|
219 |
|
220 |
+
compression_ratio: 20.307596963280485
|
|
|
221 |
|
222 |
|
223 |
|
|
|
228 |
[NbConvertApp] Converting notebook README.ipynb to markdown
|
229 |
[NbConvertApp] Support files will be in README_files/
|
230 |
[NbConvertApp] Making directory README_files
|
231 |
+
[NbConvertApp] Writing 5002 bytes to README.md
|
232 |
|
233 |
|
234 |
|
README_files/README_12_0.png
CHANGED
README_files/README_14_0.jpg
CHANGED
README_files/README_16_0.jpg
ADDED
README_files/README_16_0.png
ADDED
README_files/README_18_0.jpg
ADDED
README_files/README_8_0.jpg
CHANGED
README_files/README_8_0.png
CHANGED
Git LFS Details
|
Git LFS Details
|