Ian Marci
Ian Marci

Reputation: 141

TypeError: unhashable type: 'numpy.ndarray' Tensorflow

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})

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?

Thank you!

Upvotes: 2

Views: 9999

Answers (1)

Ian Marci
Ian Marci

Reputation: 141

Be very careful about your variable names!

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

Upvotes: 12

Related Questions