|
1 | 1 | {
|
2 |
| - "nbformat": 4, |
3 |
| - "nbformat_minor": 0, |
4 |
| - "metadata": { |
5 |
| - "colab": { |
6 |
| - "name": "HiFiC_Interactive_Colab.ipynb", |
7 |
| - "provenance": [], |
8 |
| - "collapsed_sections": [], |
9 |
| - "toc_visible": true |
10 |
| - }, |
11 |
| - "kernelspec": { |
12 |
| - "display_name": "Python 3", |
13 |
| - "name": "python3" |
14 |
| - }, |
15 |
| - "accelerator": "GPU" |
16 |
| - }, |
17 | 2 | "cells": [
|
18 | 3 | {
|
19 | 4 | "cell_type": "markdown",
|
|
40 | 25 | },
|
41 | 26 | {
|
42 | 27 | "cell_type": "code",
|
| 28 | + "execution_count": null, |
43 | 29 | "metadata": {
|
44 | 30 | "id": "LO_MNEQ7Bhbw"
|
45 | 31 | },
|
| 32 | + "outputs": [], |
46 | 33 | "source": [
|
47 |
| - "%tensorflow_version 1.x\n", |
48 |
| - "!pip install tensorflow-compression\\<2.0\n", |
| 34 | + "!pip install tensorflow-compression\n", |
49 | 35 | "![[ -e /tfc ]] || git clone https://github.com/tensorflow/compression /tfc\n",
|
50 | 36 | "%cd /tfc/models\n",
|
51 |
| - "import tfci # Check if tfci.py is available.\n" |
52 |
| - ], |
53 |
| - "execution_count": null, |
54 |
| - "outputs": [] |
| 37 | + "import tfci # Check if tfci.py is available." |
| 38 | + ] |
55 | 39 | },
|
56 | 40 | {
|
57 | 41 | "cell_type": "markdown",
|
|
68 | 52 | },
|
69 | 53 | {
|
70 | 54 | "cell_type": "code",
|
| 55 | + "execution_count": null, |
71 | 56 | "metadata": {
|
72 | 57 | "id": "x-yLUG_tmo3M"
|
73 | 58 | },
|
| 59 | + "outputs": [], |
74 | 60 | "source": [
|
75 | 61 | "import tensorflow as tf\n",
|
76 | 62 | "\n",
|
77 |
| - "if not tf.test.is_gpu_available():\n", |
| 63 | + "if not tf.config.list_physical_devices('GPU'):\n", |
78 | 64 | " print('WARNING: No GPU found. Might be slow!')\n",
|
79 | 65 | "else:\n",
|
80 | 66 | " print('Found GPU.')"
|
81 |
| - ], |
82 |
| - "execution_count": null, |
83 |
| - "outputs": [] |
| 67 | + ] |
84 | 68 | },
|
85 | 69 | {
|
86 | 70 | "cell_type": "markdown",
|
|
93 | 77 | },
|
94 | 78 | {
|
95 | 79 | "cell_type": "code",
|
| 80 | + "execution_count": null, |
96 | 81 | "metadata": {
|
97 | 82 | "id": "vtd1l70Pf95V"
|
98 | 83 | },
|
| 84 | + "outputs": [], |
99 | 85 | "source": [
|
100 | 86 | "import os\n",
|
101 | 87 | "import zipfile\n",
|
|
121 | 107 | "File = collections.namedtuple('File', ['full_path', 'num_bytes', 'bpp'])\n",
|
122 | 108 | "\n",
|
123 | 109 | "def print_html(html):\n",
|
124 |
| - " display(HTML(html + '<br/>'))\n", |
| 110 | + " display(HTML(html + '\u003cbr/\u003e'))\n", |
125 | 111 | "\n",
|
126 | 112 | "def make_cell_large():\n",
|
127 | 113 | " display(Javascript(\n",
|
128 | 114 | " '''google.colab.output.setIframeHeight(0, true, {maxHeight: 5000})'''))\n",
|
129 | 115 | "\n",
|
130 | 116 | "def get_default_image(output_dir):\n",
|
131 | 117 | " output_path = os.path.join(output_dir, os.path.basename(DEFAULT_IMAGE_URL))\n",
|
132 |
| - " print('Downloading', DEFAULT_IMAGE_URL, '\\n->', output_path)\n", |
| 118 | + " print('Downloading', DEFAULT_IMAGE_URL, '\\n-\u003e', output_path)\n", |
133 | 119 | " urllib.request.urlretrieve(DEFAULT_IMAGE_URL, output_path)\n",
|
134 | 120 | "\n"
|
135 |
| - ], |
136 |
| - "execution_count": null, |
137 |
| - "outputs": [] |
| 121 | + ] |
138 | 122 | },
|
139 | 123 | {
|
140 | 124 | "cell_type": "markdown",
|
|
147 | 131 | },
|
148 | 132 | {
|
149 | 133 | "cell_type": "code",
|
| 134 | + "execution_count": null, |
150 | 135 | "metadata": {
|
151 | 136 | "id": "NgtIlL2ADCI2"
|
152 | 137 | },
|
| 138 | + "outputs": [], |
153 | 139 | "source": [
|
154 | 140 | "#@title Setup { vertical-output: false, run: \"auto\", display-mode: \"form\" }\n",
|
155 | 141 | "#@markdown #### Custom Images\n",
|
|
173 | 159 | "\n",
|
174 | 160 | "model = 'hific-lo' #@param [\"hific-lo\", \"hific-mi\", \"hific-hi\"]\n",
|
175 | 161 | "\n"
|
176 |
| - ], |
177 |
| - "execution_count": null, |
178 |
| - "outputs": [] |
| 162 | + ] |
179 | 163 | },
|
180 | 164 | {
|
181 | 165 | "cell_type": "code",
|
| 166 | + "execution_count": null, |
182 | 167 | "metadata": {
|
183 | 168 | "id": "GYcbc2HupTRD"
|
184 | 169 | },
|
| 170 | + "outputs": [], |
185 | 171 | "source": [
|
186 | 172 | "if 'upload_custom_images' not in locals():\n",
|
187 | 173 | " print('ERROR: Please run the previous cell!')\n",
|
188 | 174 | " # Setting defaults anyway.\n",
|
189 | 175 | " upload_custom_images = False\n",
|
190 | 176 | " model = 'hific-lo'"
|
191 |
| - ], |
192 |
| - "execution_count": null, |
193 |
| - "outputs": [] |
| 177 | + ] |
194 | 178 | },
|
195 | 179 | {
|
196 | 180 | "cell_type": "code",
|
| 181 | + "execution_count": null, |
197 | 182 | "metadata": {
|
198 | 183 | "id": "e0C4vMqZsnqA"
|
199 | 184 | },
|
| 185 | + "outputs": [], |
200 | 186 | "source": [
|
201 | 187 | "all_files = os.listdir(FILES_DIR)\n",
|
202 | 188 | "if not upload_custom_images or not all_files:\n",
|
|
213 | 199 | " img = img.resize((w // 15, h // 15))\n",
|
214 | 200 | " print('- ' + file_name + ':')\n",
|
215 | 201 | " display(img)"
|
216 |
| - ], |
217 |
| - "execution_count": null, |
218 |
| - "outputs": [] |
219 |
| - }, |
220 |
| - { |
221 |
| - "cell_type": "code", |
222 |
| - "metadata": { |
223 |
| - "id": "46eq2rCRpXzC" |
224 |
| - }, |
225 |
| - "source": [ |
226 |
| - "print(f'Caching model \"{model}\"...')\n", |
227 |
| - "tfci.import_metagraph(model)\n", |
228 |
| - "print('Done')" |
229 |
| - ], |
230 |
| - "execution_count": null, |
231 |
| - "outputs": [] |
| 202 | + ] |
232 | 203 | },
|
233 | 204 | {
|
234 | 205 | "cell_type": "markdown",
|
|
241 | 212 | },
|
242 | 213 | {
|
243 | 214 | "cell_type": "code",
|
| 215 | + "execution_count": null, |
244 | 216 | "metadata": {
|
245 | 217 | "id": "kd02HOhLBj6e"
|
246 | 218 | },
|
| 219 | + "outputs": [], |
247 | 220 | "source": [
|
248 | 221 | "SUPPORTED_EXT = {'.png', '.jpg'}\n",
|
249 | 222 | "\n",
|
|
296 | 269 | " get_bpp(Image.open(full_path).size, num_bytes)))\n",
|
297 | 270 | "\n",
|
298 | 271 | "print('All done!')"
|
299 |
| - ], |
300 |
| - "execution_count": null, |
301 |
| - "outputs": [] |
| 272 | + ] |
302 | 273 | },
|
303 | 274 | {
|
304 | 275 | "cell_type": "markdown",
|
|
311 | 282 | },
|
312 | 283 | {
|
313 | 284 | "cell_type": "code",
|
| 285 | + "execution_count": null, |
314 | 286 | "metadata": {
|
315 | 287 | "id": "3nVCPeDnskD8"
|
316 | 288 | },
|
| 289 | + "outputs": [], |
317 | 290 | "source": [
|
318 | 291 | "make_cell_large() # Larger output window.\n",
|
319 | 292 | "\n",
|
320 | 293 | "for file in all_outputs:\n",
|
321 |
| - " print_html('<hr/>')\n", |
| 294 | + " print_html('\u003chr/\u003e')\n", |
322 | 295 | " print(f'Showing {file.full_path} | {file.num_bytes//1000}kB | {file.bpp:.4f}bpp')\n",
|
323 | 296 | " display(Image.open(file.full_path))\n",
|
324 |
| - " print_html('<hr/>')" |
325 |
| - ], |
326 |
| - "execution_count": null, |
327 |
| - "outputs": [] |
| 297 | + " print_html('\u003chr/\u003e')" |
| 298 | + ] |
328 | 299 | },
|
329 | 300 | {
|
330 | 301 | "cell_type": "markdown",
|
|
345 | 316 | },
|
346 | 317 | {
|
347 | 318 | "cell_type": "code",
|
| 319 | + "execution_count": null, |
348 | 320 | "metadata": {
|
349 | 321 | "id": "9BKccvcTpj1k"
|
350 | 322 | },
|
| 323 | + "outputs": [], |
351 | 324 | "source": [
|
352 | 325 | "ZIP = '/content/images.zip'\n",
|
353 | 326 | "\n",
|
|
357 | 330 | " zf.write(f.full_path, os.path.basename(path_with_bpp))\n",
|
358 | 331 | "\n",
|
359 | 332 | "files.download(ZIP) "
|
| 333 | + ] |
| 334 | + } |
| 335 | + ], |
| 336 | + "metadata": { |
| 337 | + "accelerator": "GPU", |
| 338 | + "colab": { |
| 339 | + "collapsed_sections": [], |
| 340 | + "last_runtime": { |
| 341 | + "build_target": "//research/colab/notebook:notebook_backend_py3", |
| 342 | + "kind": "private" |
| 343 | + }, |
| 344 | + "name": "HiFiC_Interactive_Colab.ipynb", |
| 345 | + "provenance": [ |
| 346 | + { |
| 347 | + |
| 348 | + "timestamp": 1615973093906 |
| 349 | + } |
360 | 350 | ],
|
361 |
| - "execution_count": null, |
362 |
| - "outputs": [] |
| 351 | + "toc_visible": true |
| 352 | + }, |
| 353 | + "kernelspec": { |
| 354 | + "display_name": "Python 3", |
| 355 | + "name": "python3" |
363 | 356 | }
|
364 |
| - ] |
| 357 | + }, |
| 358 | + "nbformat": 4, |
| 359 | + "nbformat_minor": 0 |
365 | 360 | }
|
0 commit comments