I'm getting an error but it's buried down in the TensorFlow library so I'm struggling to figure out what's wrong with my model.
I'm trying to use an RNN with LSTM. My model looks like this:
model = Sequential()
model.add(LSTM(128, activation='relu',
input_shape=1000, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(128, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(2, activation='softmax'))
opt = tf.keras.optimizers.Adam(lr=1e-3, decay=1e-5)
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=3, validation_data=(x_test, y_test))
My training data is a list of lists each comprised of 1000 floats. For example, x_train[0] =
[0.0, 0.0, 0.1, 0.25, 0.5, ...]
I'm getting this error:
File "C:\Users\bencu\Desktop\ProjectFiles\Code\Program.py", line 74, in FitModel
input_shape=1000, return_sequences=True))
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\layers\recurrent_v2.py", line 881, in __init__
**kwargs)
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\layers\recurrent.py", line 1007, in __init__
super(DropoutRNNCellMixin, self).__init__(*args, **kwargs)
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\layers\recurrent.py", line 2541, in __init__
**kwargs)
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\layers\recurrent.py", line 395, in __init__
super(RNN, self).__init__(**kwargs)
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\training\tracking\base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 356, in __init__
batch_input_shape = (batch_size,) + tuple(kwargs['input_shape'])
TypeError: 'int' object is not iterable
I'm pretty new to ML so if someone could figure out where I'm going wrong that would be much appreciated. Thank you.
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float).
– Frigorific