Warning: This project is deprecated. TensorFlow Addons has stopped development,
The project will only be providing minimal maintenance releases until May 2024. See the full
announcement here or on
github.
TensorFlow Addons Callbacks: TQDM Progress Bar
Stay organized with collections
Save and categorize content based on your preferences.
Overview
This notebook will demonstrate how to use TQDMCallback in TensorFlow Addons.
Setup
pip install -U tensorflow-addons
!pip install -q "tqdm>=4.36.1"
import tensorflow as tf
import tensorflow_addons as tfa
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten
import tqdm
# quietly deep-reload tqdm
import sys
from IPython.lib import deepreload
stdout = sys.stdout
sys.stdout = open('junk','w')
deepreload.reload(tqdm)
sys.stdout = stdout
tqdm.__version__
'4.64.0'
Import and Normalize Data
# the data, split between train and test sets
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# normalize data
x_train, x_test = x_train / 255.0, x_test / 255.0
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11490434/11490434 [==============================] - 0s 0us/step
Build Simple MNIST CNN Model
# build the model using the Sequential API
model = Sequential()
model.add(Flatten(input_shape=(28, 28)))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer='adam',
loss = 'sparse_categorical_crossentropy',
metrics=['accuracy'])
Default TQDMCallback Usage
# initialize tqdm callback with default parameters
tqdm_callback = tfa.callbacks.TQDMProgressBar()
# train the model with tqdm_callback
# make sure to set verbose = 0 to disable
# the default progress bar.
model.fit(x_train, y_train,
batch_size=64,
epochs=10,
verbose=0,
callbacks=[tqdm_callback],
validation_data=(x_test, y_test))
Training: 0%| 0/10 ETA: ?s, ?epochs/s
Epoch 1/10
0/938 ETA: ?s -
Epoch 2/10
0/938 ETA: ?s -
Epoch 3/10
0/938 ETA: ?s -
Epoch 4/10
0/938 ETA: ?s -
Epoch 5/10
0/938 ETA: ?s -
Epoch 6/10
0/938 ETA: ?s -
Epoch 7/10
0/938 ETA: ?s -
Epoch 8/10
0/938 ETA: ?s -
Epoch 9/10
0/938 ETA: ?s -
Epoch 10/10
0/938 ETA: ?s -
<keras.callbacks.History at 0x7f49161ea7f0>
Below is the expected output when you run the cell above

# TQDMProgressBar() also works with evaluate()
model.evaluate(x_test, y_test, batch_size=64, callbacks=[tqdm_callback], verbose=0)
0/157 ETA: ?s - Evaluating
[0.07728561758995056, 0.9760000109672546]
Below is the expected output when you run the cell above

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-05-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-05-26 UTC."],[],[],null,["# TensorFlow Addons Callbacks: TQDM Progress Bar\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|\n| [View on TensorFlow.org](https://www.tensorflow.org/addons/tutorials/tqdm_progress_bar) | [Run in Google Colab](https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/tqdm_progress_bar.ipynb) | [View source on GitHub](https://github.com/tensorflow/addons/blob/master/docs/tutorials/tqdm_progress_bar.ipynb) | [Download notebook](https://storage.googleapis.com/tensorflow_docs/addons/docs/tutorials/tqdm_progress_bar.ipynb) |\n\nOverview\n--------\n\nThis notebook will demonstrate how to use TQDMCallback in TensorFlow Addons.\n\nSetup\n-----\n\n pip install -U tensorflow-addons\n\n !pip install -q \"tqdm\u003e=4.36.1\"\n\n import tensorflow as tf\n import tensorflow_addons as tfa\n\n from tensorflow.keras.datasets import mnist\n from tensorflow.keras.models import Sequential\n from tensorflow.keras.layers import Dense, Dropout, Flatten\n\n import tqdm\n\n # quietly deep-reload tqdm\n import sys\n from IPython.lib import deepreload \n\n stdout = sys.stdout\n sys.stdout = open('junk','w')\n deepreload.reload(tqdm)\n sys.stdout = stdout\n\n tqdm.__version__\n\n```\n'4.64.0'\n```\n\nImport and Normalize Data\n-------------------------\n\n # 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\n\n```\nDownloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n11490434/11490434 [==============================] - 0s 0us/step\n```\n\nBuild Simple MNIST CNN Model\n----------------------------\n\n # 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'])\n\nDefault TQDMCallback Usage\n--------------------------\n\n # 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))\n\n```\nTraining: 0%| 0/10 ETA: ?s, ?epochs/s\nEpoch 1/10\n0/938 ETA: ?s -\nEpoch 2/10\n0/938 ETA: ?s -\nEpoch 3/10\n0/938 ETA: ?s -\nEpoch 4/10\n0/938 ETA: ?s -\nEpoch 5/10\n0/938 ETA: ?s -\nEpoch 6/10\n0/938 ETA: ?s -\nEpoch 7/10\n0/938 ETA: ?s -\nEpoch 8/10\n0/938 ETA: ?s -\nEpoch 9/10\n0/938 ETA: ?s -\nEpoch 10/10\n0/938 ETA: ?s -\n\u003ckeras.callbacks.History at 0x7f49161ea7f0\u003e\n```\n\n**Below is the expected output when you run the cell above** \n\n # TQDMProgressBar() also works with evaluate()\n model.evaluate(x_test, y_test, batch_size=64, callbacks=[tqdm_callback], verbose=0)\n\n```\n0/157 ETA: ?s - Evaluating\n[0.07728561758995056, 0.9760000109672546]\n```\n\n**Below is the expected output when you run the cell above**"]]