1

When running a Keras LSTM model, I am getting the above error. Here's the gist of the model:

inp = Input(shape=(170,200))
out = LSTM(25, activation='relu')(inp)
main_out = Dense(4, activation='sigmoid')(out)
model = Model(inputs = [inp], outputs = [main_out])
# optimizer, model.fit etc. etc.
model.fit([img_data, ], [y_train],
                   epochs=500, batch_size=1, callbacks = callbacks,
                   verbose=1, validation_split=0.1)

My input is a list of 250 sets of 170 vectors, each of length 200. The shape seems correct:

X.shape = (170, 200, 250)

However, when I run the model, I get

    Traceback (most recent call last):
  File "lstm_trials.py", line 62, in <module>
    model = Model(inputs = [inp], outputs = [main_out])
  File ".../keras/legacy/interfaces.py", line 88, in wrapper
    return func(*args, **kwargs)
  File ".../keras/engine/topology.py", line 1485, in __init__
    inputs_set = set(self.inputs)
TypeError: unhashable type: 'numpy.ndarray'

What is going wrong?

1

1 Answer 1

1

I believe your input data img_data has wrong type() or shape. I unsuccessfully tried to reproduce your error with the following code snippet that runs smoothly on Keras 2.0.4. Please compare its input data format to yours to find out the exact error source.

import numpy as np

from keras import optimizers, losses
from keras.models import Model
from keras.layers import Input, Dense, LSTM
from keras.utils import to_categorical

# Generate dummy data
n_classes = 4
im_height = 170
im_width = 200
n_training_examples = 250
img_data = np.random.random(size=(n_training_examples, im_height, im_width))
y_train = to_categorical(
    y=np.random.randint(n_classes, size=(n_training_examples, 1)),
    num_classes=n_classes)

inp = Input(shape=(im_height, im_width))
out = LSTM(units=25, activation='relu')(inp)
main_out = Dense(units=n_classes, activation='softmax')(out)
model = Model(inputs=[inp], outputs=[main_out])
model.compile(optimizer=optimizers.sgd(),
              loss=losses.categorical_crossentropy)
model.fit(x=[img_data], y=[y_train],
          epochs=5, batch_size=10, verbose=1, validation_split=0.2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.