-1
import tensorflow as tf
import numpy as np
layer1_weight = tf.Variable(tf.zeros([2 , 3]))
layer1_bias = tf.Variable(tf.zeros([3 , 1]))
layer2_weight = tf.Variable(tf.zeros([3, 1]))
layer2_bias = tf.Variable(tf.constant([[0.]]))
input = tf.placeholder(tf.float32 , [2 , 1])
result = tf.placeholder(tf.float32 ,[1 , 1])
data_input = [np.float32([[0.],[0.]]) , np.float32([[0.],[1.]]) ,
np.float32([[1.],[0.]]) , np.float32([[1.],[1.]])]
data_output = [np.float32([[0.]]) , np.float32([[1.]]) ,
np.float32([[1.]]) , np.float32([[0.]])]
layer1_output = tf.add(tf.matmul(tf.transpose(layer1_weight) , input) ,
layer1_bias)
layer2_output = tf.add(tf.matmul(tf.transpose(layer2_weight) ,
layer1_output) , layer2_bias)
print (data_input[0])
loss = tf.square(tf.subtract(result , layer2_output))
optimizer = tf.train.GradientDescentOptimizer(0.0001)
train_step = optimizer.minimize(loss)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
for i in range(30) :
j = int(i % 4)
result = data_output[j]
sess.run(train_step , feed_dict= {input : data_input[j] , result :
data_output[j]})
print(str(layer2_output))
的代碼返回錯誤Tensorflow錯誤「unhashable類型:‘numpy.ndarray’」
TypeError: unhashable type: 'numpy.ndarray'
在這裏,我想實現與神經網絡的異或門,但無法找到錯誤。