简体   繁体   中英

TypeError: unhashable type: 'numpy.ndarray' - Tensor Flow - Numpy

import matplotlib.pyplot as plt

x_arr = np.arange(-2, 4, 0.1)

g2 = tf.Graph()

with tf.Session(graph = g2) as sess:
    new_saver = tf.train.import_meta_graph(
    "./trained-model.meta")
    
    new_saver.restore(sess, "./trained-model")
    
    y_arr = sess.run("y_hat:0", 
                     feed_dict = {"tf_x:0", x_arr})
    
plt.figure()
plt.plot(x_train, y_train, "bo")
plt.plot(x_test, y_test, "bo", alpha = 0.3)
plt.plot(x_arr, y_arr.T[:,0], "-r", lw = 3)
plt.show()


OUTPUT



INFO:tensorflow:Restoring parameters from ./trained-model

TypeError Traceback (most recent call last) in 12 13 y_arr = sess.run("y_hat:0", ---> 14 feed_dict = {"tf_x:0", x_arr}) 15 16 plt.figure()

TypeError: unhashable type: 'numpy.ndarray'


You need to convert x_arr into a tensor type. You can do this by tf.convert_to_tensor(x_arr) .

Source:convert_to_tensor documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM