Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 222 additions & 0 deletions docs/tutorials/tqdm_progress_bar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Copyright 2019 The TensorFlow Authors."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TensorFlow Addons Callbacks: TQDM Progress Bar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://www.tensorflow.org/addons/tutorials/tqdm_progress_bar\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/tqdm_progresss_bar.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/tqdm_progress_bar.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://storage.googleapis.com/tensorflow_docs/docs/docs/tutorials/tqdm_progress_bar.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Download notebook</a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Overview\n",
"This notebook will demonstrate how to use TQDMCallback in TensorFlow Addons."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install -q tqdm>=4.36.1\n",
"\n",
"!pip install -q ipywidgets\n",
"!pip install -q --no-deps tensorflow-addons~=0.6\n",
"!jupyter nbextension enable --py widgetsnbextension --sys-prefix"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" # %tensorflow_version only exists in Colab.\n",
" %tensorflow_version 2.x\n",
"except Exception:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"import tensorflow_addons as tfa\n",
"\n",
"import tensorflow.keras as keras\n",
"from tensorflow.keras.datasets import mnist\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, Dropout, Flatten"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import and Normalize Data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# the data, split between train and test sets\n",
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
"# normalize data\n",
"x_train, x_test = x_train / 255.0, x_test / 255.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build Simple MNIST CNN Model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# build the model using the Sequential API\n",
"model = Sequential()\n",
"model.add(Flatten(input_shape=(28, 28)))\n",
"model.add(Dense(128, activation='relu'))\n",
"model.add(Dropout(0.2))\n",
"model.add(Dense(10, activation='softmax'))\n",
"\n",
"model.compile(optimizer='adam',\n",
" loss = 'sparse_categorical_crossentropy',\n",
" metrics=['accuracy'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Default TQDMCallback Usage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# initialize tqdm callback with default parameters\n",
"tqdm_callback = tfa.callbacks.TQDMProgressBar()\n",
"\n",
"# train the model with tqdm_callback\n",
"# make sure to set verbose = 0 to disable\n",
"# the default progress bar.\n",
"model.fit(x_train, y_train,\n",
" batch_size=64,\n",
" epochs=10,\n",
" verbose=0,\n",
" callbacks=[tqdm_callback],\n",
" validation_data=(x_test, y_test))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Below is the expected output when you run the cell above**\n",
"![TQDM Progress Bar Figure](https://raw.githubusercontent.com/tensorflow/addons/59961669a0e21eb4c045d4ad38d008a529d566c2/docs/tutorials/assets/tqdm_progress_bar_demo.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions tensorflow_addons/callbacks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ py_library(
name = "callbacks",
srcs = [
"__init__.py",
"tqdm_progress_bar.py",
],
srcs_version = "PY2AND3",
deps = [
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_addons/callbacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
## Maintainers
| Submodule | Maintainers | Contact Info |
|:---------- |:------------- |:--------------|
| | | |
| tqdm_progress_bar | @shun-lin | [email protected] |

## Contents
| Submodule | Metric | Reference |
| Submodule | Callback | Reference |
|:----------------------- |:-------------------|:---------------|
| | | |
| tqdm_progress_bar | TQDMProgressBar | https://tqdm.github.io/ |


## Contribution Guidelines
Expand All @@ -21,7 +21,7 @@ must:
* Add the addon to the `py_library` in this sub-package's BUILD file.

#### Testing Requirements
* Simple unittests that demonstrate the metric is behaving as expected.
* Simple unittests that demonstrate the callback is behaving as expected.
* When applicable, run all unittests with TensorFlow's
`@run_in_graph_and_eager_modes` (for test method)
or `run_all_in_graph_and_eager_modes` (for TestCase subclass)
Expand Down
2 changes: 2 additions & 0 deletions tensorflow_addons/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_addons.callbacks.tqdm_progress_bar import TQDMProgressBar
Loading