I have just started learning tensorflow coding and I am stuck with very basic code for creating a neural network. Below is the the code:
import tensorflow as tf
import numpy as np
a = tf.placeholder(shape=(1,1),dtype=tf.float16)
b = tf.placeholder(shape=(1,1),dtype=tf.float16)
y= tf.placeholder(shape=(1,1),dtype=tf.float16)
addition = tf.add(a, b)
correct_prediction = tf.equal(addition,y,name=None)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
a1=[[0.2]]
b1=[[0.3]]
y1=[[0.5]]
a = sess.run(addition, feed_dict={a: a1, b: b1})
b = sess.run(correct_prediction, feed_dict={a: a1, b: b1, y: y1})
sess.close()
It is giving me the following error
*Traceback (most recent call last):
File "D:/NN/pyNN/new_main.py", line 35, in <module>
b = sess.run(correct_prediction, feed_dict={a: a1, b: b1, y: y1})
TypeError: unhashable type: 'numpy.ndarray'*
I have tried multiple ways for providing the input and output but I end up with the same error. Any help will be highly appreciated
You are assigning the result of session.run() to a. This means a is a numpy array after the first run, overwriting the original definition as a placeholder. Then you are using this array as a key in the dictionary for the second run, which obviously doesn't work.
Renaming the a and b variables within the session context should fix it, e.g.
a_array = sess.run(addition, feed_dict={a: a1, b: b1})
b_array = sess.run(correct_prediction, feed_dict={a: a1, b: b1, y: y1})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With