Quantcast
Channel: How can I resolve the, "feed a value for placeholder tensor" error? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How can I resolve the, "feed a value for placeholder tensor" error?

$
0
0

I'm brand new to Tensorflow and while following through a book I have found that their sample data is too verbose for me to follow what Tensorflow is doing. That being the case I have made my own ultra small csv file instead. After working through several errors I am at the end of my script and can't seem to work through this final error:

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'y' with dtype float and shape [?,1]
[[Node: y = Placeholderdtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

Below is my code and below that I have included the output of the print statements. Can anyone help me understand this error. Also, I am aware that my mock data will not output any sensible model I just want to get it working first before switching to more complicated data. Thanks!

import tensorflow as tf
import numpy as np
import pandas as pd
import tarfile
import os

def load_data():
    return pd.read_csv("datasets/housing/mock.csv")

#load the data  
mockData = load_data()
print("mock data:")
print(mockData)

#add the bias
mockDataPlusBias = np.c_[np.ones((3,1)), mockData]
print("Mock data and bias:")
print(mockDataPlusBias)

#create placeholders
X = tf.constant(mockDataPlusBias, dtype=tf.float32, name="X")
y = tf.placeholder(tf.float32, shape=(None,1), name="y")

#for use with matmul
XT = tf.transpose(X)
print("X:")
print(X)
print("XT:")
print(XT)
print("y:")
print(y)

theta = tf.matmul(tf.matmul(tf.matrix_inverse(tf.matmul(XT, XT)), XT), y)
with tf.Session() as sess:
    theta_value = theta.eval()
    print(theta_value)

And lastly the print statements:

mock data:
   col1  col2
0     1     2
1     4     5
2     7     8
Mock data and bias:
[[1. 1. 2.]
 [1. 4. 5.]
 [1. 7. 8.]]
X:
Tensor("X:0", shape=(3, 3), dtype=float32)
XT:
Tensor("transpose:0", shape=(3, 3), dtype=float32)
y:
Tensor("y:0", shape=(?, 1), dtype=float32)

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images