I'm a beginner in Keras and just write a toy example. It reports a TypeError
. The code and error are as follows:
Code:
inputs = keras.Input(shape=(3, ))
cell = keras.layers.SimpleRNNCell(units=5, activation='softmax')
label = keras.layers.RNN(cell)(inputs)
model = keras.models.Model(inputs=inputs, outputs=label)
model.compile(optimizer='rmsprop',
loss='mae',
metrics=['acc'])
data = np.array([[1, 2, 3], [3, 4, 5]])
labels = np.array([1, 2])
model.fit(x=data, y=labels)
Error:
Traceback (most recent call last):
File "/Users/david/Documents/code/python/Tensorflow/test.py", line 27, in <module>
run()
File "/Users/david/Documents/code/python/Tensorflow/test.py", line 21, in run
label = keras.layers.RNN(cell)(inputs)
File "/Users/david/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py", line 619, in __call__
...
File "/Users/david/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/init_ops.py", line 473, in __call__
scale /= max(1., (fan_in + fan_out) / 2.)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
So how can I deal with it?