Reputation: 290
I'm just learning TensorFlow, so sorry if this is obvious. I've checked the documentation and experimented quite a bit and I just can't seem to get this to work.
def train_network():
OUT_DIMS = 1
FIN_SIZE = 500
x = tf.placeholder(tf.float32, [OUT_DIMS, FIN_SIZE], name="x")
w = tf.Variable(tf.zeros([FIN_SIZE, OUT_DIMS]), name="w")
b = tf.Variable(tf.zeros([OUT_DIMS]), name="b")
y = tf.tanh(tf.matmul(x, w) + b)
yhat = tf.placeholder(tf.float32, [None, OUT_DIMS])
cross_entropy = -tf.reduce_sum(yhat*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
# Launch the model
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for this_x, this_y in yield_financials():
sess.run(train_step, feed_dict={x: this_x,
yhat: this_y})
print(end=".")
sys.stdout.flush()
yield_financials() outputs an numpy array of 500 numbers and the number that I want it to guess. I've tried shuffling OUT_DIMS and FIN_SIZE around, I tried accumulating them into batches to more closely match what the tutorial looked like, I tried setting OUT_DIMS to 0, removing it entirely, and I tried replacing None with other numbers, but have not made any progress.
Upvotes: 0
Views: 11972
Reputation: 1
I had the same problem and I solved this problem.I hope that it's helpful for u.
firstly,I transformed load data into :
train_data = np.genfromtxt(train_data1, delimiter=',')
train_label = np.transpose(train_label1, delimiter=',')
test_data = np.genfromtxt(test_data1, delimiter=',')
test_label = np.transpose(test_label1, delimiter=',')
Then,transformed trX, trY, teX, teY data into:
# convert the data
trX, trY, teX, teY = train_data,train_label, test_data, test_label
temp = trY.shape
trY = trY.reshape(temp[0], 1)
trY = np.concatenate((1-trY, trY), axis=1)
temp = teY.shape
teY = teY.reshape(temp[0], 1)
teY = np.concatenate((1-teY, teY), axis=1)
Finally,I transformed launching the graph in a session into:
with tf.Session() as sess:
# you need to initialize all variables
tf.initialize_all_variables().run()
for i in range(100):
sess.run(train_op, feed_dict={X: trX, Y: trY})
print(i, np.mean(np.argmax(teY, axis=1) == sess.run(predict_op, feed_dict={X: teX})))
That's all.
Upvotes: 0
Reputation: 57973
Try
this_x = np.reshape(this_x,(1, FIN_SIZE))
sess.run(train_step, feed_dict={x: this_x,
yhat: this_y})
Upvotes: 2