Hi!
I faced the same problem and during debugging I figured that type(raw_data) returns a np.ndarray which elements are np.float64.
According to this, I changed the dtype of tf.constant, tf.Variable and tf.placeholder to tf.float64:
alpha = tf.constant(0.05, dtype=tf.float64)
curr_value = tf.placeholder(tf.float64)
prev_avg = tf.Variable(0., dtype=tf.float64)
The other necessary change is in session:
sess.add_graph(sess.graph)
should be changed to:
writer.add_graph(sess.graph)
Just like reported in other posts.
It works fine now!
You can find here my final code:
## Importing libraries
import tensorflow as tf
import numpy as np
## Create raw data as a 100 numbers vector with mean 10 and standar deviation 1
raw_data = np.random.normal(10, 1, 100)
## Define important elements as:
# alpha as tf.constant
# curr_value as tf.placeholder
# prev_avg as tf.Variable
alpha = tf.constant(0.05, dtype=tf.float64)
curr_value = tf.placeholder(tf.float64)
prev_avg = tf.Variable(0., dtype=tf.float64) # Initialize the previous average as 0.
## Defining the average updated operator. The elements will be later defined as:
update_avg = alpha * curr_value + (1  alpha) * prev_avg
## Creating Tensorboard elements
# Create a summary node for the averages
avg_hist = tf.summary.scalar("running_average", update_avg)
# Create a summary node for the values
value_hist = tf.summary.scalar("incoming_values", curr_value)
# Merge the summaries to make it easier to run together
merged = tf.summary.merge_all()
# Pass in the "logs" directory location to the writer
writer = tf.summary.FileWriter("./logs")
## Initialize Variables
init = tf.global_variables_initializer()
## Running iteration of the exponential average algorithm
with tf.Session() as sess:
sess.run(init)
#Run the merged op and update_avg op at the same time
writer.add_graph(sess.graph)
for i in range(len(raw_data)):
summary_str, curr_avg = sess.run([merged, update_avg], feed_dict={curr_value: raw_data[i]})
sess.run(tf.assign(prev_avg, curr_avg))
print(raw_data[i], curr_avg)
# Add the summary to the writer
writer.add_summary(summary_str, i)
