{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "MIRNet_TFJS.ipynb", "provenance": [], "authorship_tag": "ABX9TyMeW+fgCGdDA9xYVibPEI0Y", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "nvl_Sp72Cndi" }, "source": [ "

MIRNet TFJS

\r\n", "\r\n", "This notebook shows the the process of converting the `SavedModel` we built in the [prequel notebook](https://github.com/Rishit-dagli/MIRNet-TFJS/blob/main/MIRNet_Saved_Model.ipynb) for the **MIRNet** model as proposed by [Learning Enriched Features for Real Image Restoration and Enhancement](https://arxiv.org/pdf/2003.06792v2.pdf) by Zamir et al. This model is capable of enhancing low-light images upto a great extent.\r\n", "\r\n", "

A bit about the architecture

\r\n", "\r\n", "The MIRNet presents a novel architecture with the collective goals of maintaining high-resolution representations through the entire network, and\r\n", "receiving strong contextual information from the low-resolution representations.\r\n", "\r\n", "The core of this approach is a multi-scale residual block containing the following key elements:\r\n", "- parallel multi-resolution convolution streams for extracting multi-scale features\r\n", "- information exchange across the multi-resolution streams\r\n", "- spatial and channel attention mechanisms for capturing contextual information\r\n", "- attention based multi-scale feature aggregation.\r\n", "\r\n", "![](https://i.imgur.com/VOzfG9a.png)\r\n", "

\r\n", "Framework of MIRNet\r\n", "

\r\n", "\r\n", "The figure above shows the framework of the proposed network MIRNet that learns enriched feature representations for image restoration and enhancement.\r\n", "\r\n", "

Examples

\r\n", "\r\n", "

\r\n", "
\r\n", "Source\r\n", "

\r\n", "\r\n", "Model training code and pre-trained weights are provided by Soumik through [this repository](https://github.com/soumik12345/MIRNet/)." ] }, { "cell_type": "markdown", "metadata": { "id": "jJdrvLEmDWj4" }, "source": [ "## Setup" ] }, { "cell_type": "markdown", "metadata": { "id": "OncYoUYmD3mo" }, "source": [ "Installing TensorFlow JS" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "T7NLYo9iDBxC", "outputId": "bbb77bba-a2f0-4cb8-e5ce-64291ba0b11a" }, "source": [ "!sudo pip install tensorflowjs" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Collecting tensorflowjs\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/fe/7e/b005271236ddb90fb8a85e29e32ba0841e6737faf9068adbc5ca28df6a41/tensorflowjs-2.8.1-py3-none-any.whl (63kB)\n", "\u001b[K |████████████████████████████████| 71kB 3.8MB/s \n", "\u001b[?25hCollecting tensorflow-hub<0.10,>=0.7.0\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/ac/83/a7df82744a794107641dad1decaad017d82e25f0e1f761ac9204829eef96/tensorflow_hub-0.9.0-py2.py3-none-any.whl (103kB)\n", "\u001b[K |████████████████████████████████| 112kB 3.9MB/s \n", "\u001b[?25hRequirement already satisfied: h5py<3,>=2.8.0 in /usr/local/lib/python3.6/dist-packages (from tensorflowjs) (2.10.0)\n", "Requirement already satisfied: tensorflow<3,>=2.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflowjs) (2.4.0)\n", "Requirement already satisfied: six<2,>=1.12.0 in /usr/local/lib/python3.6/dist-packages (from tensorflowjs) (1.15.0)\n", "Requirement already satisfied: numpy>=1.12.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-hub<0.10,>=0.7.0->tensorflowjs) (1.19.4)\n", "Requirement already satisfied: protobuf>=3.8.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-hub<0.10,>=0.7.0->tensorflowjs) (3.12.4)\n", "Requirement already satisfied: tensorboard~=2.4 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (2.4.0)\n", "Requirement already satisfied: tensorflow-estimator<2.5.0,>=2.4.0rc0 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (2.4.0)\n", "Requirement already satisfied: absl-py~=0.10 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (0.10.0)\n", "Requirement already satisfied: wrapt~=1.12.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.12.1)\n", "Requirement already satisfied: flatbuffers~=1.12.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.12)\n", "Requirement already satisfied: google-pasta~=0.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (0.2.0)\n", "Requirement already satisfied: keras-preprocessing~=1.1.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.1.2)\n", "Requirement already satisfied: opt-einsum~=3.3.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (3.3.0)\n", "Requirement already satisfied: termcolor~=1.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.1.0)\n", "Requirement already satisfied: typing-extensions~=3.7.4 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (3.7.4.3)\n", "Requirement already satisfied: wheel~=0.35 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (0.36.2)\n", "Requirement already satisfied: gast==0.3.3 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (0.3.3)\n", "Requirement already satisfied: grpcio~=1.32.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.32.0)\n", "Requirement already satisfied: astunparse~=1.6.3 in /usr/local/lib/python3.6/dist-packages (from tensorflow<3,>=2.1.0->tensorflowjs) (1.6.3)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf>=3.8.0->tensorflow-hub<0.10,>=0.7.0->tensorflowjs) (50.3.2)\n", "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (0.4.2)\n", "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (1.7.0)\n", "Requirement already satisfied: google-auth<2,>=1.6.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (1.17.2)\n", "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (1.0.1)\n", "Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (2.23.0)\n", "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (3.3.3)\n", "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (1.3.0)\n", "Requirement already satisfied: rsa<5,>=3.1.4; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (4.6)\n", "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (4.2.0)\n", "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (0.2.8)\n", "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (1.24.3)\n", "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (3.0.4)\n", "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (2.10)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (2020.12.5)\n", "Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from markdown>=2.6.8->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (3.3.0)\n", "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (3.1.0)\n", "Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python3.6/dist-packages (from rsa<5,>=3.1.4; python_version >= \"3\"->google-auth<2,>=1.6.3->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (0.4.8)\n", "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < \"3.8\"->markdown>=2.6.8->tensorboard~=2.4->tensorflow<3,>=2.1.0->tensorflowjs) (3.4.0)\n", "Installing collected packages: tensorflow-hub, tensorflowjs\n", " Found existing installation: tensorflow-hub 0.10.0\n", " Uninstalling tensorflow-hub-0.10.0:\n", " Successfully uninstalled tensorflow-hub-0.10.0\n", "Successfully installed tensorflow-hub-0.9.0 tensorflowjs-2.8.1\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "qWGE63UxD7R6" }, "source": [ "Downloading the TensorFlow `SavedModel` which we made in the [prequel notebook](https://github.com/Rishit-dagli/MIRNet-TFJS/blob/main/MIRNet_Saved_Model.ipynb)" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "qX-LWeQGCM8B", "outputId": "ad84ec2b-eea9-4a1f-a62b-eb642b0dff78" }, "source": [ "!wget --load-cookies /tmp/cookies.txt \"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1SyqUAkixPfdd1894GcILtmTY3owaUem_' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\\1\\n/p')&id=1SyqUAkixPfdd1894GcILtmTY3owaUem_\" -O saved-model.tar.gz && rm -rf /tmp/cookies.txt" ], "execution_count": 6, "outputs": [ { "output_type": "stream", "text": [ "--2020-12-20 17:07:16-- https://docs.google.com/uc?export=download&confirm=axhL&id=1SyqUAkixPfdd1894GcILtmTY3owaUem_\n", "Resolving docs.google.com (docs.google.com)... 108.177.125.102, 108.177.125.101, 108.177.125.113, ...\n", "Connecting to docs.google.com (docs.google.com)|108.177.125.102|:443... connected.\n", "HTTP request sent, awaiting response... 302 Moved Temporarily\n", "Location: https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e=download [following]\n", "--2020-12-20 17:07:16-- https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e=download\n", "Resolving doc-0k-3k-docs.googleusercontent.com (doc-0k-3k-docs.googleusercontent.com)... 64.233.189.132, 2404:6800:4008:c07::84\n", "Connecting to doc-0k-3k-docs.googleusercontent.com (doc-0k-3k-docs.googleusercontent.com)|64.233.189.132|:443... connected.\n", "HTTP request sent, awaiting response... 302 Found\n", "Location: https://docs.google.com/nonceSigner?nonce=id312lnjknjjm&continue=https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e%3Ddownload&hash=m67p4s3qnm6e8us05glq6mngl1ig11dg [following]\n", "--2020-12-20 17:07:16-- https://docs.google.com/nonceSigner?nonce=id312lnjknjjm&continue=https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e%3Ddownload&hash=m67p4s3qnm6e8us05glq6mngl1ig11dg\n", "Connecting to docs.google.com (docs.google.com)|108.177.125.102|:443... connected.\n", "HTTP request sent, awaiting response... 302 Found\n", "Location: https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e=download&nonce=id312lnjknjjm&user=13527291313208939176Z&hash=5olnpr7a7b83qnj2qalk2slp7abji431 [following]\n", "--2020-12-20 17:07:16-- https://doc-0k-3k-docs.googleusercontent.com/docs/securesc/m88g6hel12mvkfm4f18onshjdeivqv9k/mq5aj7eqd54h9pp60aag90p70pek0edn/1608483975000/11941728310014738790/13527291313208939176Z/1SyqUAkixPfdd1894GcILtmTY3owaUem_?e=download&nonce=id312lnjknjjm&user=13527291313208939176Z&hash=5olnpr7a7b83qnj2qalk2slp7abji431\n", "Connecting to doc-0k-3k-docs.googleusercontent.com (doc-0k-3k-docs.googleusercontent.com)|64.233.189.132|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: unspecified [application/x-gzip]\n", "Saving to: ‘saved-model.tar.gz’\n", "\n", "saved-model.tar.gz [ <=> ] 128.86M 132MB/s in 1.0s \n", "\n", "2020-12-20 17:07:17 (132 MB/s) - ‘saved-model.tar.gz’ saved [135118861]\n", "\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "JNtfNoeJELeg" }, "source": [ "Let us take a look if the `saved-model.tar.gz` appears which we just downloaded." ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "nJPQrF_xDyl6", "outputId": "0b743db0-fed9-4f44-dd17-c28b9e7c99d7" }, "source": [ "!ls" ], "execution_count": 7, "outputs": [ { "output_type": "stream", "text": [ "sample_data saved-model.tar.gz\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "mlkWCUo_ETup" }, "source": [ "We will now unzip the `saved-model.tar.gz` which we just downloaded." ] }, { "cell_type": "code", "metadata": { "id": "1VEYuMMPEcQh" }, "source": [ "saved_model_dir = \"savedmodel\" #@param {type:\"string\"}\n", "\n", "import shutil\n", "shutil.unpack_archive(\"saved-model.tar.gz\", saved_model_dir)" ], "execution_count": 10, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "isIrQonlI6jq" }, "source": [ "### A couple of imports" ] }, { "cell_type": "code", "metadata": { "id": "XaSqlinXDctI" }, "source": [ "from PIL import Image\r\n", "import os\r\n", "import tensorflow as tf\r\n", "import tensorflowjs as tfjs\r\n", "import numpy as np" ], "execution_count": 25, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "nRBNviigJWor" }, "source": [ "## About the model\r\n", "\r\n", "If you recall in the last notebook we downloaded pre-trained weights and our model looked like this:\r\n", "\r\n", "![](https://i.imgur.com/Nn6jap7.jpg)\r\n", "\r\n", "We will now be converting this model to the TFJS format." ] }, { "cell_type": "markdown", "metadata": { "id": "l3MV9st0KPyo" }, "source": [ "## Convert to TFJS" ] }, { "cell_type": "markdown", "metadata": { "id": "bTEGUhfXKTG3" }, "source": [ "First off this is the directory structure you would end up with after making the conversions:\r\n", "\r\n", "```\r\n", "tfjs\r\n", "├── no-comp\r\n", "| └── model.json\r\n", "| └── ...\r\n", "├── float-16\r\n", "| └── model.json\r\n", "| └── ...\r\n", "├── uint-16\r\n", "| └── model.json\r\n", "| └── ...\r\n", "├── uint-8\r\n", "| └── model.json\r\n", "| └── ...\r\n", "```" ] }, { "cell_type": "markdown", "metadata": { "id": "vxF81aKUM-Da" }, "source": [ "### No Compression Model" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "y7ILjzGRJ-8J", "outputId": "58136902-b757-4b1c-a220-92416880c8dc" }, "source": [ "!tensorflowjs_converter --input_format=keras_saved_model --metadata= savedmodel tfjs/no-comp" ], "execution_count": 16, "outputs": [ { "output_type": "stream", "text": [ "2020-12-20 17:27:28.828428: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:27:30.833580: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:27:30.834864: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1\n", "2020-12-20 17:27:30.888209: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:30.889181: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:27:30.889283: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:27:31.143335: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:27:31.143430: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:27:31.262238: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:27:31.286064: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:27:31.575261: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:27:31.628847: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:27:32.139377: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:27:32.139635: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:32.140455: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:32.144623: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:27:32.145401: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:27:32.145564: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:32.146320: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:27:32.146380: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:27:32.146435: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:27:32.146475: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:27:32.146509: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:27:32.146542: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:27:32.146576: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:27:32.146610: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:27:32.146644: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:27:32.146727: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:32.147637: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:32.148526: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:27:32.154328: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:27:36.144855: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:\n", "2020-12-20 17:27:36.144909: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0 \n", "2020-12-20 17:27:36.144936: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N \n", "2020-12-20 17:27:36.154090: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:36.155078: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:36.155885: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:27:36.156564: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n", "2020-12-20 17:27:36.156645: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10629 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)\n", "WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.\n", "2020-12-20 17:28:19.355643: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)\n", "2020-12-20 17:28:19.715344: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299995000 Hz\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "D511cJx3NBq3" }, "source": [ "### Float 16 Model" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "BZt_d7EjMFED", "outputId": "e72e3c12-09a4-4ae1-add1-6f643e4fea1a" }, "source": [ "!tensorflowjs_converter --input_format=keras_saved_model --metadata= --quantize_float16=* savedmodel tfjs/float-16" ], "execution_count": 18, "outputs": [ { "output_type": "stream", "text": [ "2020-12-20 17:35:04.799758: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:35:06.788642: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:35:06.789798: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1\n", "2020-12-20 17:35:06.807993: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.808713: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:35:06.808761: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:35:06.810810: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:35:06.810888: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:35:06.812764: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:35:06.813143: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:35:06.815305: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:35:06.816437: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:35:06.820428: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:35:06.820535: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.821388: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.822012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:35:06.822566: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:35:06.822719: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.823468: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:35:06.823513: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:35:06.823565: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:35:06.823620: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:35:06.823663: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:35:06.823703: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:35:06.823742: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:35:06.823796: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:35:06.823848: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:35:06.823969: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.824737: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:06.825447: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:35:06.825522: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:35:07.348477: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:\n", "2020-12-20 17:35:07.348570: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0 \n", "2020-12-20 17:35:07.348591: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N \n", "2020-12-20 17:35:07.348850: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:07.349603: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:07.350379: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:35:07.351132: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n", "2020-12-20 17:35:07.351204: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10629 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)\n", "WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.\n", "2020-12-20 17:35:48.799339: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)\n", "2020-12-20 17:35:49.167608: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299995000 Hz\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "r-cYGNc0OgqP" }, "source": [ "### UINT-16 Model\r\n", "\r\n", "Quantizing to `float16` may provide better accuracy over 2 byte affine integer scaling (`uint16`)" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "IBAm-ofgOAlP", "outputId": "df36d6f6-b842-4ff8-8a17-9dba92244d75" }, "source": [ "!tensorflowjs_converter --input_format=keras_saved_model --metadata= --quantize_uint16=* savedmodel tfjs/uint-16" ], "execution_count": 21, "outputs": [ { "output_type": "stream", "text": [ "2020-12-20 17:40:32.129611: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:40:34.106746: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:40:34.107742: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1\n", "2020-12-20 17:40:34.125978: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.126605: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:40:34.126650: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:40:34.128760: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:40:34.128841: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:40:34.130839: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:40:34.131348: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:40:34.133724: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:40:34.135024: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:40:34.139249: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:40:34.139348: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.140188: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.140921: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:40:34.141376: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:40:34.141584: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.142254: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:40:34.142293: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:40:34.142333: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:40:34.142371: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:40:34.142405: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:40:34.142448: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:40:34.142497: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:40:34.142529: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:40:34.142562: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:40:34.142643: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.143342: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.144106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:40:34.144161: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:40:34.662068: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:\n", "2020-12-20 17:40:34.662134: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0 \n", "2020-12-20 17:40:34.662163: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N \n", "2020-12-20 17:40:34.662401: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.663172: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.663810: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:40:34.664433: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n", "2020-12-20 17:40:34.664510: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10629 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)\n", "WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.\n", "2020-12-20 17:41:14.756642: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)\n", "2020-12-20 17:41:15.086392: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299995000 Hz\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "RSRQ-fW2Ou1y" }, "source": [ "### UINT-8 Model\r\n", "\r\n", "1-byte affine quantization, `uint8` in most cases provides a 4x size reduction at the cost of accuracy" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "fok_SXNPOuDg", "outputId": "46fde1b9-4961-4ece-a745-55ba7a0dc246" }, "source": [ "!tensorflowjs_converter --input_format=keras_saved_model --metadata= --quantize_uint8=* savedmodel tfjs/test" ], "execution_count": 22, "outputs": [ { "output_type": "stream", "text": [ "2020-12-20 17:44:35.559183: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:44:37.335927: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:44:37.337095: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1\n", "2020-12-20 17:44:37.354870: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.355567: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:44:37.355623: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:44:37.357533: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:44:37.357597: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:44:37.359221: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:44:37.359546: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:44:37.361357: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:44:37.362525: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:44:37.366083: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:44:37.366187: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.366813: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.367459: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:44:37.367899: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set\n", "2020-12-20 17:44:37.368043: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.368828: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: \n", "pciBusID: 0000:00:04.0 name: Tesla K80 computeCapability: 3.7\n", "coreClock: 0.8235GHz coreCount: 13 deviceMemorySize: 11.17GiB deviceMemoryBandwidth: 223.96GiB/s\n", "2020-12-20 17:44:37.368907: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:44:37.368957: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10\n", "2020-12-20 17:44:37.369001: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10\n", "2020-12-20 17:44:37.369044: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10\n", "2020-12-20 17:44:37.369088: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10\n", "2020-12-20 17:44:37.369139: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10\n", "2020-12-20 17:44:37.369180: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10\n", "2020-12-20 17:44:37.369218: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7\n", "2020-12-20 17:44:37.369304: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.370025: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.370590: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0\n", "2020-12-20 17:44:37.370644: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1\n", "2020-12-20 17:44:37.853073: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:\n", "2020-12-20 17:44:37.853135: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0 \n", "2020-12-20 17:44:37.853155: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N \n", "2020-12-20 17:44:37.853337: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.854092: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.854778: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n", "2020-12-20 17:44:37.855381: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n", "2020-12-20 17:44:37.855450: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10629 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)\n", "WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.\n", "2020-12-20 17:45:16.774180: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)\n", "2020-12-20 17:45:17.102707: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299995000 Hz\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "uNyDDILsPT9m" }, "source": [ "## Comparing Model sizes" ] }, { "cell_type": "code", "metadata": { "id": "ZBuBsdhTPJLf" }, "source": [ "model_type = \"no-comp\" #@param [\"no-comp\", \"float-16\", \"uint-16\", \"uint-8\"]\n", "\n", "def get_size(start_path):\n", " total_size = 0\n", " for dirpath, dirnames, filenames in os.walk(start_path):\n", " for f in filenames:\n", " fp = os.path.join(dirpath, f)\n", " # skip if it is symbolic link\n", " if not os.path.islink(fp):\n", " total_size += os.path.getsize(fp)\n", "\n", " return total_size" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "ed8X6NDnQ-2e", "outputId": "78feb50e-ea2a-42e5-f9cc-3ef72b5ed055" }, "source": [ "def model_size(model_dir):\r\n", " size = get_size(model_dir)\r\n", " print('Model size is %f MBs.' % (size / 1024.0 / 1024.0))\r\n", "\r\n", "model_size(\"tfjs/\" + model_type)" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Model size is 139.255836 MBs.\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "GMYtB4gWRovJ" }, "source": [ "As an example you can see here that the `float-16` model is almost half the size of the original model" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "t8ucl95LRJ79", "outputId": "2d3b8b49-9bc0-43e9-a0d6-0f0b549b0651" }, "source": [ "model_size(\"tfjs/float-16\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Model size is 69.984879 MBs.\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "pCo3AaVTR_gQ" }, "source": [ "And that is all for this notebook where we first dwonlaoded the model we built earlier, converted the model to TFJS format and finally compared model sizes for different compression techniques." ] } ] }