mackey-glass problem with LMU giving out the error with the recent updates of keras-lmu 0.2.0 and 0.3.0 versions
Opened this issue · 6 comments
<ipython-input-16-f9340b4f7a97> in <module>()
50 layers = 4
51 lstm_model = make_lstm(units=25, layers=layers)
---> 52 lmu_model = make_lmu(units=49, layers=layers)
53 hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)
1 frames
<ipython-input-16-f9340b4f7a97> in delay_layer(units, **kwargs)
18 #memory_d=memory_d,
19 #hidden_cell=tf.keras.layers.SimpleRNNCell(212),
---> 20 theta=4,
21 ),
22 return_sequences=True,
TypeError: __init__() missing 2 required positional arguments: 'memory_d' and 'hidden_cell'
]
Here I passed the missing parameters..
def make_lstm(units, layers):
model = Sequential()
model.add(LSTM(units,
input_shape=(train_X.shape[1], 1), # (timesteps, input_dims)
return_sequences=True)) # continuously outputs per timestep
for _ in range(layers-1):
model.add(LSTM(units, return_sequences=True))
model.add(Dense(train_X.shape[-1], activation='tanh'))
model.compile(loss="mse", optimizer="adam")
model.summary()
return model
def delay_layer(units, **kwargs):
return RNN(LMUCell(units=units,
order=4,
memory_d=4,
hidden_cell=tf.keras.layers.Layer,
#memory_d=memory_d,
#hidden_cell=tf.keras.layers.SimpleRNNCell(212),
theta=4,
),
return_sequences=True,
**kwargs)
def make_lmu(units, layers):
model = Sequential()
model.add(delay_layer(units,
input_shape=(train_X.shape[1], 1))) # (timesteps, input_dims)
for _ in range(layers-1):
model.add(delay_layer(units))
model.add(Dense(train_X.shape[-1], activation='linear'))
model.compile(loss="mse", optimizer="adam")
model.summary()
return model
def make_hybrid(units_lstm, units_lmu, layers):
assert layers == 4, "unsupported"
model = Sequential()
model.add(delay_layer(units=units_lmu,input_shape=(train_X.shape[1], 1)))
model.add(LSTM(units=units_lstm, return_sequences=True))
model.add(delay_layer(units=units_lmu))
model.add(LSTM(units=units_lstm, return_sequences=True))
model.add(Dense(train_X.shape[-1], activation='tanh'))
model.compile(loss="mse", optimizer="adam")
model.summary()
return model
layers = 4
lstm_model = make_lstm(units=25, layers=layers)
lmu_model = make_lmu(units=49, layers=layers)
hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)
Even after passing out the missing parameters giving another error with units, even I installed the latest keras-lmu but same problem I think because version 0.2.0 removed the units and hidden_activation parameters of LMUCell (these are now specified directly in the hidden_cell. (#22) So please provide the updated codes for mackey-glass prediction problem also. Thanks in advance
TypeError Traceback (most recent call last)
<ipython-input-17-1c880cdb37fc> in <module>()
50 layers = 4
51 lstm_model = make_lstm(units=25, layers=layers)
---> 52 lmu_model = make_lmu(units=49, layers=layers)
53 hybrid_model = make_hybrid(units_lstm=25, units_lmu=40, layers=layers)
6 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in validate_kwargs(kwargs, allowed_kwargs, error_message)
776 for kwarg in kwargs:
777 if kwarg not in allowed_kwargs:
--> 778 raise TypeError(error_message, kwarg)
779
780
TypeError: ('Keyword argument not understood:', 'units')
Which Mackey-Glass code are you trying to run? If it's the results from the original LMU paper, that code base is preserved here https://github.com/nengo/keras-lmu/blob/paper/experiments/mackey-glass.ipynb and should continue to run (note that you will need to be on the paper
branch of the LMU repo). If it's your own code that you're trying to get running with KerasLMU 0.3.0 I'd recommend coming by the forum and we can help you there, it's just a better format for these kinds of questions.
However, from a brief look at your code, it looks like the problem is here
LMUCell(units=units,
order=4,
memory_d=4,
hidden_cell=tf.keras.layers.Layer,
#memory_d=memory_d,
#hidden_cell=tf.keras.layers.SimpleRNNCell(212),
theta=4,
),
As you said
0.2.0 removed the units and hidden_activation parameters of LMUCell (these are now specified directly in the hidden_cell.
So the units
should be specified in the hidden cell, like
LMUCell(order=4,
memory_d=4,
hidden_cell=tf.keras.layers.SimpleRNNCell(units=212),
theta=4,
),
You can see the API of LMUCell here and an example of using the API in practice here.
So please send me the correct code to run it on colab without errors
It shouldn't make any difference whether you're running on Colab or not (it's just a Python environment in any case).
If you just want to recreate the results from the paper (from https://github.com/nengo/keras-lmu/blob/paper/experiments/mackey-glass.ipynb), then as mentioned you should install the paper
branch of the LMU repo. You can do this in Colab by adding !pip install git+https://github.com/nengo/keras-lmu@paper
at the top of your code. Or, if you wanted to install the 0.1.0 version (which I'm guessing is what you were using before), you can install that by putting !pip install lmu==0.1.0
at the top of your code. In either case, you should then be able to recreate the results from the paper.
If you're wanting to update the code from the paper to work with recent KerasLMU versions, I'd recommend coming by the forum and we can help you there (that's a better format for those kinds of research support questions). I don't see any errors in the output you posted, just looks like you're getting a few warnings (which should be safe to ignore).
Sure sir, thank you very much for the help as you said I tried on colab(!pip
install git+https://github.com/nengo/keras-lmu@paper at the top of your
code. Or, if you wanted to install the 0.1.0 version (which I'm guessing is
what you were using before), you can install that by putting !pip install
lmu==0.1.0 at the top of your code) but it returned same only.
That means that it did not install correctly. To be clear, you need to have a line at the top of your notebook that looks like this:
That will install the 0.1.0 version, and you will not get that error.