Operations on a Computational Graph

We start by loading the necessary libraries and resetting the computational graph.

In [2]:
import os
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow.python.framework import ops
ops.reset_default_graph()

Start a graph session

In [3]:
sess = tf.Session()

Create tensors

In [4]:
# Create data to feed in the placeholder
x_vals = np.array([1., 3., 5., 7., 9.])

# Create the TensorFlow Placceholder
x_data = tf.placeholder(tf.float32)

# Constant for multilication
m = tf.constant(3.)

We loop through the input values and print out the multiplication operation for each input.

In [5]:
# Multiplication
prod = tf.multiply(x_data, m)
for x_val in x_vals:
    print(sess.run(prod, feed_dict={x_data: x_val}))
3.0
9.0
15.0
21.0
27.0

Output graph to Tensorboard

In [6]:
merged = tf.summary.merge_all(key='summaries')
if not os.path.exists('tensorboard_logs/'):
    os.makedirs('tensorboard_logs/')

my_writer = tf.summary.FileWriter('tensorboard_logs/', sess.graph)

Operations on a Graph

In [ ]: