From 1ce792ec72ea4232dfafff0e603cb5f57e6a8b98 Mon Sep 17 00:00:00 2001 From: Sumanth Rao Date: Wed, 27 Jun 2018 16:18:49 +0530 Subject: [PATCH 1/7] Updated engine.py Fixed the bug! --- recurrentshop/engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recurrentshop/engine.py b/recurrentshop/engine.py index e8deb67..527e795 100644 --- a/recurrentshop/engine.py +++ b/recurrentshop/engine.py @@ -839,13 +839,13 @@ def _get_optional_input_placeholder(self, name=None, num=1): self._optional_input_placeholders[name] = self._get_optional_input_placeholder() return self._optional_input_placeholders[name] if num == 1: - optional_input_placeholder = _to_list(_OptionalInputPlaceHolder().inbound_nodes[0].output_tensors)[0] + optional_input_placeholder = _to_list(_OptionalInputPlaceHolder()._inbound_nodes[0].output_tensors)[0] assert self._is_optional_input_placeholder(optional_input_placeholder) return optional_input_placeholder else: y = [] for _ in range(num): - optional_input_placeholder = _to_list(_OptionalInputPlaceHolder().inbound_nodes[0].output_tensors)[0] + optional_input_placeholder = _to_list(_OptionalInputPlaceHolder()._inbound_nodes[0].output_tensors)[0] assert self._is_optional_input_placeholder(optional_input_placeholder) y.append(optional_input_placeholder) return y From 00861ac8fc0716cf274df3fdc8965c49b897da06 Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 13:26:11 +0200 Subject: [PATCH 2/7] Update Readme.md to correct some mistakes. --- README.md | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 658ddcf..bda43fb 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ from keras.layers import * from keras.models import * from recurrentshop import * -x_t = Input(5,)) # The input to the RNN at time t -h_tm1 = Input((10,)) # Previous hidden state +x_t = Input(shape=(5,)) # The input to the RNN at time t +h_tm1 = Input(shape=(10,)) # Previous hidden state # Compute new hidden state h_t = add([Dense(10)(x_t), Dense(10, use_bias=False)(h_tm1)]) @@ -34,17 +34,34 @@ h_t = add([Dense(10)(x_t), Dense(10, use_bias=False)(h_tm1)]) h_t = Activation('tanh')(h_t) # Build the RNN -rnn = RecurrentModel(input=x_t, initial_states=[h_tm1], output=h_t, output_states=[h_t]) - -# rnn is a standard Keras `Recurrent` instance. RecuurentModel also accepts arguments such as unroll, return_sequences etc +# RecurrentModel is a standard Keras `Recurrent` layer. +# RecurrentModel also accepts arguments such as unroll, return_sequences etc +rnn = RecurrentModel(input=x_t, initial_states=[h_tm1], output=h_t, final_states=[h_t]) +# return_sequences is False by default +# so it only returns the last h_t state + +# Build a Keras Model using our RNN layer +# input dimensions are (Time_steps, Depth) +x = Input(shape=(7,5)) +y = rnn(x) +model = Model(x, y) # Run the RNN over a random sequence +# Don't forget the batch shape when calling the model! +out=model.predict(np.random.random((1, 7, 5))) +print(out.shape)#->(1,10) -x = Input((7,5)) -y = rnn(x) -model = Model(x, y) -model.predict(np.random.random((7, 5))) +# to get one output per input sequence element, set return_sequences=True +rnn2 = RecurrentModel(input=x_t, initial_states=[h_tm1], output=h_t, final_states=[h_t],return_sequences=True) + +# Time_steps can also be None +x = Input(shape=(None ,5)) +y = rnn2(x) +model2 = Model(x, y) + +out2=model2.predict(np.random.random((1, 7, 5))) +print(out2.shape)#->(1,7,10) ``` @@ -134,6 +151,12 @@ cd recurrentshop python setup.py install ``` +note that Recurrentshop is not compatible with keras 2.2.*, so it is recommended to use keras==2.0.5: + +```shell +pip install -U keras==2.0.5 +``` + # Contribute Pull requests are highly welcome. From f106cda40b7fcd19a6f224da63244d82bd182997 Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 13:29:34 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bda43fb..2c4e6c2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ print(out.shape)#->(1,10) # to get one output per input sequence element, set return_sequences=True rnn2 = RecurrentModel(input=x_t, initial_states=[h_tm1], output=h_t, final_states=[h_t],return_sequences=True) -# Time_steps can also be None +# Time_steps can also be None to allow variable Sequence Length +# Note that this is not compatible with unroll=True x = Input(shape=(None ,5)) y = rnn2(x) model2 = Model(x, y) From 09792f094aba7fc42a4dfb6728e78b5f7fbb3abb Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 13:53:59 +0200 Subject: [PATCH 4/7] Fix Keras 2.2? --- recurrentshop/engine.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recurrentshop/engine.py b/recurrentshop/engine.py index 527e795..9cb1505 100644 --- a/recurrentshop/engine.py +++ b/recurrentshop/engine.py @@ -3,7 +3,8 @@ from keras import initializers from .backend import rnn, learning_phase_scope from .generic_utils import serialize_function, deserialize_function -from keras.engine.topology import Node, _collect_previous_mask, _collect_input_shape +from keras.engine.topology import Node +from keras.engine.base_layer import _collect_previous_mask, _collect_input_shape import inspect From 2e34bf7a7b4fe1aa3609b355c74e6e88c00839f5 Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 14:00:16 +0200 Subject: [PATCH 5/7] Update README.md --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 2c4e6c2..017590c 100644 --- a/README.md +++ b/README.md @@ -147,17 +147,11 @@ See docs/ directory for more features. # Installation ```shell -git clone https://www.github.com/datalogai/recurrentshop.git +git clone https://www.github.com/pyrestone/recurrentshop.git cd recurrentshop python setup.py install ``` -note that Recurrentshop is not compatible with keras 2.2.*, so it is recommended to use keras==2.0.5: - -```shell -pip install -U keras==2.0.5 -``` - # Contribute Pull requests are highly welcome. From c6dfc712c70f870e940edf59bd0960f6ede130f4 Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 14:01:01 +0200 Subject: [PATCH 6/7] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index b439e29..ec8fc40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -keras>=2.0.0 +keras>=2.2.0 numpy>=1.8.0 -theano>=0.8.0 +tensorflow>=1.9 From 5c3a4c2b8730d8730dcf5a3728b9c18f0c91b8f7 Mon Sep 17 00:00:00 2001 From: Marc Uecker Date: Sat, 30 Jun 2018 14:22:48 +0200 Subject: [PATCH 7/7] Update engine.py --- recurrentshop/engine.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recurrentshop/engine.py b/recurrentshop/engine.py index 9cb1505..b28085a 100644 --- a/recurrentshop/engine.py +++ b/recurrentshop/engine.py @@ -3,8 +3,7 @@ from keras import initializers from .backend import rnn, learning_phase_scope from .generic_utils import serialize_function, deserialize_function -from keras.engine.topology import Node -from keras.engine.base_layer import _collect_previous_mask, _collect_input_shape +from keras.engine.base_layer import Node,_collect_previous_mask, _collect_input_shape import inspect