farizrahman4u / recurrentshop

Framework for building complex recurrent neural networks with Keras
MIT License
767 stars 218 forks source link

Unable to connect tensorflow placeholder with recurrent shop model? #79

Open liquidscience opened 7 years ago

liquidscience commented 7 years ago

I am trying to connect a tensorflow placeholder with a keras recuurent shop model,Everything works fine when i use a simple keras model and feed it with a tensorflow placeholder , but the code throws an error when i 'm trying to use a recurrent shop model with it.

import keras.backend as K
from keras.layers import *
from keras.models import *
from recurrentshop import *
import tensorflow as tf`
sess = tf.Session()
K.set_session(sess) 
x_t = Input((None,5)) 
h_tm1 = Input((10,))  
h_t = add([Dense(10)(x_t), Dense(10, use_bias=False)(h_tm1)])
h_t = Activation('tanh')(h_t)
rnn = RecurrentModel(input=x_t, initial_states=[h_tm1], output=h_t, final_states=[h_t])
x = Input((None,5))
y = rnn(x)
model = Model(x, y)
image_data = tf.placeholder(tf.float32, shape=[None,None,5])
sess.run(tf.global_variables_initializer())
y1=model(image_data)
sess.run(y1,feed_dict={image_data :np.random.random((7,5, 5))})

This throws a key error with trace :-

  ' Found: ' + str(self.outputs))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sam/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)
  File "/home/sam/ana
```conda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile(filename, *where)
  File "/home/sam/test/garbage.py", line 233, in <module>
    y1=model(image_data)
  File "/home/sam/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 615, in __call__
    output_shape = self.compute_output_shape(input_shape)
  File "/home/sam/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 2123, in compute_output_shape
    input_shape = layers_to_output_shapes[shape_key]
KeyError: 'private__optional_input_place_holder_3_0_0'

While a non recurrent model like below works just fine :-


from keras.layers import *
from keras.models import *
from recurrentshop import *
import tensorflow as tf
sess = tf.Session()
K.set_session(sess) 
inp = Input(([5]))
h_t = Dense(10)(inp)
h_t = Activation('tanh')(h_t)
model = Model(inp, h_t)
image_data = tf.placeholder(tf.float32, shape=[None,5])
y1=model(image_data)
sess.run(tf.global_variables_initializer())
sess.run(y1,feed_dict={image_data :np.random.random((7, 5))})