Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds TQDMProgressBar in callbacks #610

Merged
merged 10 commits into from
Oct 30, 2019
Binary file added docs/tutorials/assets/tqdm_progress_bar_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
201 changes: 201 additions & 0 deletions docs/tutorials/tqdm_progress_bar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
shun-lin marked this conversation as resolved.
Show resolved Hide resolved
shun-lin marked this conversation as resolved.
Show resolved Hide resolved
shun-lin marked this conversation as resolved.
Show resolved Hide resolved
shun-lin marked this conversation as resolved.
Show resolved Hide resolved
shun-lin marked this conversation as resolved.
Show resolved Hide resolved
"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\n",
"\n",
"!pip install -q ipywidgets\n",
"!jupyter nbextension enable --py widgetsnbextension --sys-prefix"
]
},
{
"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 Demo](assets/tqdm_progress_bar_demo.png)"
]
}
],
"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