Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 29, 2021 07:05 am GMT

TensorFlow Visualization Framework

Introduction
To do good research or develop good models, we need rich, frequent feedback about whats going on inside our models during our experiments. Thats the point of running experiments: to get information about how well a model performsas much information as possible. Making progress is an iterative process or loop: we start with an idea and express it as an experiment, attempting to validate or invalidate our idea. We run this experiment and process the information it generates. This inspires our next idea. The more iterations of this loop were able to run, the more refined and powerful our ideas become. Keras helps us go from idea to experiment in the least possible time, and fast GPU s can help us get from experiment to result as quickly as possible. But what about processing the experiment results? Thats where Tensor-Board comes in.

Description
TensorBoard, a browser-based visualization tool that comes packaged with TensorFlow. Note that its only available for Keras models when were using Keras with the TensorFlow backend. The key purpose of TensorBoard is to help us visually monitor everything that goes on inside our model during training. If were monitoring more information than just the models final loss, we can develop a clearer vision of what the model does and doesnt do, and we can make progress more quickly. TensorBoard gives us access to several neat features, all in our browser:

Visually monitoring metrics during training
Visualizing our model architecture
Visualizing histograms of activations and gradients
Exploring embeddings in 3D
Lets demonstrate these features in a simple example. Well train a 1D convnet on the IMDB sentiment-analysis task. Well consider only the top 2,000 words in the IMDB vocabulary, to make visualizing word embeddings more tractable.
Text-classification model to use with TensorBoard
import keras
from keras import layers
from keras.datasets import imdb
from keras.preprocessing import sequence
Number of words to
consider as features
max_features = 2000
max_len = 500
Cuts off texts after this number of words (among max_features most common words)
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
x_train = sequence.pad_sequences(x_train, maxlen=max_len)
x_test = sequence.pad_sequences(x_test, maxlen=max_len)
model = keras.models.Sequential()
model.add(layers.Embedding(max_features, 128,
input_length=max_len,
name=embed))
model.add(layers.Conv1D(32, 7, activation=relu))
model.add(layers.MaxPooling1D(5))
model.add(layers.Conv1D(32, 7, activation=relu))
model.add(layers.GlobalMaxPooling1D())
model.add(layers.Dense(1))
model.summary()
model.compile(optimizer=rmsprop,
loss=binary_crossentropy,
metrics=[acc])
Before we start using TensorBoard, we need to create a directory where well store the log files it generates.
Creating a directory for TensorBoard log files
$ mkdir my_log_dir
Lets launch the training with a TensorBoard callback instance. This callback will write
log events to disk at the specified location.
Training the model with a TensorBoard callback
callbacks = [
Log files will be written at this location.
keras.callbacks.TensorBoard(
log_dir=my_log_dir,
histogram_freq=1,
Records activation histograms every 1 epoch
embeddings_freq=1, ) ]
Records embedding data every 1 epoch
history = model.fit(x_train, y_train,
epochs=20,
batch_size=128,
validation_split=0.2,
callbacks=callbacks)
At this point, we can launch the TensorBoard server from the command line, instructing it to read the logs the callback is currently writing. The tensorboard utility should have been automatically installed on our machine the moment we installed
TensorFlow (for example, via pip ):
$ tensorboard logdir=my_log_dir
We can then browse to http://localhost:6006 and look at our model training. In addition, to live graphs of the training and validation metrics, we get access to the Histograms tab, where we can find pretty visualizations of histograms of activation values taken by our layers.
For more details visit:https://www.technologiesinindustry4.com/2021/05/tensorflow-visualization-framework.html


Original Link: https://dev.to/ahmedmansoor012/tensorflow-visualization-framework-322k

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To