类型错误:不可散列类型:'numpy.ndarray' Tensorflow [英] TypeError: unhashable type: 'numpy.ndarray' Tensorflow

查看:33
本文介绍了类型错误:不可散列类型:'numpy.ndarray' Tensorflow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在改编 MNIST tensorflow 教程之一,但收到此 TypeError.根据这个问题,您必须在字典键,因为 numpy 数组是可变的.我相信我正在这样做,但我仍然收到此错误.

I'm working on adapting one of the MNIST tensorflow tutorials, and I receive this TypeError. According to this question you have to use a placeholder in the dictionary key because numpy arrays are mutable. I believe I'm doing that, but I'm still receiving this error.

# Network Parameters
n_input = 44100 # length of FFT
n_classes = 6 # 6 instrument classes
dropout = 0.75 # Dropout, probability to keep units

# TF Graph input
x = tf.placeholder(tf.float32, [None, n_input])
y = tf.placeholder(tf.float32, [None, n_classes])
keep_prob = tf.placeholder(tf.float32)

我填写我的批次,然后将它们传递给会话.

I fill up my batches and then pass them to the session.

for file_name in os.listdir('./Input_FFTs'):
    if file_name.endswith('.txt'):
        path = './Input_FFTs/' + file_name
        y, x = getData(path)
        batch_ys[count] = y
        batch_xs[count] = x
        count += 1
sess.run(optimizer, feed_dict={x: batch_xs, y: batch_ys,
                                   keep_prob: dropout})

当我打印并检查batch_xs 和batch_ys 的大小时,它们是[batch_size, 44100] 和[batch_size, 6],数据正确.这些匹配 x 和 y 占位符的预期大小.

When I print and check the sizes of batch_xs and batch_ys, they are [batch_size, 44100] and [batch_size, 6] with the correct data. These match the expected sizes of the x and y placeholders.

谁能告诉我可能是什么问题?

Can anyone tell me what the problem may be?

谢谢!

推荐答案

注意变量名!

我在循环中用数组 x 和 y 替换了占位符 x、y,以填充我的训练和测试补丁.

I was replacing my placeholders x, y with arrays x, and y in my loops to fill my train and test patches.

这篇关于类型错误:不可散列类型:'numpy.ndarray' Tensorflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆