The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

556085 (1) [Avatar] Offline
#1
Cannot get this line working:

summary_str, curr_avg = sess.run([merged, update_avg], feed_dict={curr_value: raw_data[i]})

Error:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float

If I change merged to either avg_hist or value_hist, it will work, but not with them merged, can someone help me?
581905 (2) [Avatar] Offline
#2
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! smilie

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)

475381 (3) [Avatar] Offline
#3
thanks but the logs file created contains:

error not UTF-8 encoded.