Issues with using stateful in StackedRNN cells Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsTensorFlow and Categorical variablesHow many LSTM cells should I use?Issues with NLTK lemmatizer (WordNet)Time series forecasting with RNN(stateful LSTM) produces constant valuesWhen to use Stateful LSTM?Predictions with arbitrairy sequence length for stateful RNN (LSTM/GRU) in KerasDynamic rnn for toysequence classificationwith tf.device(DEVICE): model = modellib.MaskRCNN(mode = “inference”, model_dir = LOGS_DIR, config = config)Issues with pandas chunk mergeIssues with training SSD on own dataset

How to translate "red flag" into Spanish?

What is ls Largest Number Formed by only moving two sticks in 508?

What helicopter has the most rotor blades?

How did Elite on the NES work?

Why didn't the Space Shuttle bounce back into space many times as possible so that it loose lot of kinetic energy over there?

Why does Java have support for time zone offsets with seconds precision?

Where did Arya get these scars?

What *exactly* is electrical current, voltage, and resistance?

Did war bonds have better investment alternatives during WWII?

Where to find documentation for `whois` command options?

Will I lose my paid in full property

How to dissolve shared line segments together in QGIS?

Is it acceptable to use working hours to read general interest books?

What do you call an IPA symbol that lacks a name (e.g. ɲ)?

PIC mathematical operations weird problem

Bright yellow or light yellow?

Can I criticise the more senior developers around me for not writing clean code?

Retract an already submitted recommendation letter (written for an undergrad student)

What were wait-states, and why was it only an issue for PCs?

What is a good proxy for government quality?

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

yticklabels on the right side of yaxis

My admission is revoked after accepting the admission offer

What is the evidence that custom checks in Northern Ireland are going to result in violence?



Issues with using stateful in StackedRNN cells



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsTensorFlow and Categorical variablesHow many LSTM cells should I use?Issues with NLTK lemmatizer (WordNet)Time series forecasting with RNN(stateful LSTM) produces constant valuesWhen to use Stateful LSTM?Predictions with arbitrairy sequence length for stateful RNN (LSTM/GRU) in KerasDynamic rnn for toysequence classificationwith tf.device(DEVICE): model = modellib.MaskRCNN(mode = “inference”, model_dir = LOGS_DIR, config = config)Issues with pandas chunk mergeIssues with training SSD on own dataset










0












$begingroup$


I am having issues with using the 'stateful' feature when building stacked RNN using LSTMCell object. I am following the instructions on tensorflow on how to set 'stateful = True' by passing the 'batch_shape' to the input layer and the 'batch_input_shape' to the first cell, and also tried to set it in the second cell but it still does not work; tried various combinations but nothing works. The code only works with one cell but not with more than one. I am not sure what I am missing.



The problem I am working on is Sentiment Analysis. 292 is the sequence length I am passing to predict if the sentiment is 1 or 0.



I realize I could use the Sequential model of Keras but I would like to learn the finer features of tensorflow.



import tensorflow as tf

tf.reset_default_graph()

batch_size = 10
embed_size = 5
dropout = 0.5
n_unique_words = 102966
ntimesteps = 292


x = tf.placeholder(dtype = tf.int32, shape = (batch_size, ntimesteps), name='tf_x')
print(x)

y = tf.placeholder(dtype = tf.float32, shape = (batch_size), name = 'tf_y')
print(y)

embed_variable = tf.get_variable(name = 'embedding', shape = [n_unique_words, embed_size], initializer=tf.glorot_uniform_initializer)
print(embed_variable)

embed_x = tf.nn.embedding_lookup(embed_variable, x, name = 'embedded_x')
print(embed_x)

cell1 = tf.keras.layers.LSTMCell(units = 256, batch_input_shape = (10,292,5), dtype = tf.float32)#, dropout=dropout, name = 'lstm1')
print(cell1)


cell2 = tf.keras.layers.LSTMCell(units = 512, batch_input_shape = (10,292,5), dtype = tf.float32)#, name='lstm2', recurrent_dropout=0.5)
print(cell2)


rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
return_state = True, stateful = True, dtype = tf.float32)(rnn_input)


print(rnn_object)


Output:



Tensor("tf_x:0", shape=(10, 292), dtype=int32)
Tensor("tf_y:0", shape=(10,), dtype=float32)
<tf.Variable 'embedding:0' shape=(102966, 5) dtype=float32_ref>
Tensor("embedded_x/Identity:0", shape=(10, 292, 5), dtype=float32)
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3b38>
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3fd0>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-641a99b06a11> in <module>
32 rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
33 rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
---> 34 return_state = True, stateful = True, dtype = tf.float32)(rnn_input)
35
36

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
699
700 if initial_state is None and constants is None:
--> 701 return super(RNN, self).__call__(inputs, **kwargs)
702
703 # If any of `initial_state` or `constants` are specified and are Keras

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
536 if not self.built:
537 # Build layer if applicable (if the `build` method has been overridden).
--> 538 self._maybe_build(inputs)
539 # We must set self.built since user defined build functions are not
540 # constrained to set self.built.

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
1601 # Only call `build` if the user has manually overridden the build method.
1602 if not hasattr(self.build, '_is_default'):
-> 1603 self.build(input_shapes)
1604
1605 def __setattr__(self, name, value):

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in build(self, input_shape)
634 ]
635 if self.stateful:
--> 636 self.reset_states()
637 self.built = True
638

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in reset_states(self, states)
904 K.set_value(state,
905 np.zeros([batch_size] +
--> 906 tensor_shape.as_shape(dim).as_list()))
907 else:
908 K.set_value(self.states[0], np.zeros(

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in set_value(x, value)
2831 (of the same shape).
2832 """
-> 2833 value = np.asarray(value, dtype=dtype(x))
2834 if ops.executing_eagerly_outside_functions():
2835 x.assign(value)

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in dtype(x)
1013 ```
1014 """
-> 1015 return x.dtype.base_dtype.name
1016
1017

AttributeError: 'list' object has no attribute 'dtype'









share|improve this question











$endgroup$











  • $begingroup$
    Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
    $endgroup$
    – Esmailian
    Apr 5 at 11:59











  • $begingroup$
    Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
    $endgroup$
    – Sameer Kesava
    Apr 6 at 13:49
















0












$begingroup$


I am having issues with using the 'stateful' feature when building stacked RNN using LSTMCell object. I am following the instructions on tensorflow on how to set 'stateful = True' by passing the 'batch_shape' to the input layer and the 'batch_input_shape' to the first cell, and also tried to set it in the second cell but it still does not work; tried various combinations but nothing works. The code only works with one cell but not with more than one. I am not sure what I am missing.



The problem I am working on is Sentiment Analysis. 292 is the sequence length I am passing to predict if the sentiment is 1 or 0.



I realize I could use the Sequential model of Keras but I would like to learn the finer features of tensorflow.



import tensorflow as tf

tf.reset_default_graph()

batch_size = 10
embed_size = 5
dropout = 0.5
n_unique_words = 102966
ntimesteps = 292


x = tf.placeholder(dtype = tf.int32, shape = (batch_size, ntimesteps), name='tf_x')
print(x)

y = tf.placeholder(dtype = tf.float32, shape = (batch_size), name = 'tf_y')
print(y)

embed_variable = tf.get_variable(name = 'embedding', shape = [n_unique_words, embed_size], initializer=tf.glorot_uniform_initializer)
print(embed_variable)

embed_x = tf.nn.embedding_lookup(embed_variable, x, name = 'embedded_x')
print(embed_x)

cell1 = tf.keras.layers.LSTMCell(units = 256, batch_input_shape = (10,292,5), dtype = tf.float32)#, dropout=dropout, name = 'lstm1')
print(cell1)


cell2 = tf.keras.layers.LSTMCell(units = 512, batch_input_shape = (10,292,5), dtype = tf.float32)#, name='lstm2', recurrent_dropout=0.5)
print(cell2)


rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
return_state = True, stateful = True, dtype = tf.float32)(rnn_input)


print(rnn_object)


Output:



Tensor("tf_x:0", shape=(10, 292), dtype=int32)
Tensor("tf_y:0", shape=(10,), dtype=float32)
<tf.Variable 'embedding:0' shape=(102966, 5) dtype=float32_ref>
Tensor("embedded_x/Identity:0", shape=(10, 292, 5), dtype=float32)
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3b38>
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3fd0>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-641a99b06a11> in <module>
32 rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
33 rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
---> 34 return_state = True, stateful = True, dtype = tf.float32)(rnn_input)
35
36

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
699
700 if initial_state is None and constants is None:
--> 701 return super(RNN, self).__call__(inputs, **kwargs)
702
703 # If any of `initial_state` or `constants` are specified and are Keras

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
536 if not self.built:
537 # Build layer if applicable (if the `build` method has been overridden).
--> 538 self._maybe_build(inputs)
539 # We must set self.built since user defined build functions are not
540 # constrained to set self.built.

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
1601 # Only call `build` if the user has manually overridden the build method.
1602 if not hasattr(self.build, '_is_default'):
-> 1603 self.build(input_shapes)
1604
1605 def __setattr__(self, name, value):

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in build(self, input_shape)
634 ]
635 if self.stateful:
--> 636 self.reset_states()
637 self.built = True
638

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in reset_states(self, states)
904 K.set_value(state,
905 np.zeros([batch_size] +
--> 906 tensor_shape.as_shape(dim).as_list()))
907 else:
908 K.set_value(self.states[0], np.zeros(

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in set_value(x, value)
2831 (of the same shape).
2832 """
-> 2833 value = np.asarray(value, dtype=dtype(x))
2834 if ops.executing_eagerly_outside_functions():
2835 x.assign(value)

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in dtype(x)
1013 ```
1014 """
-> 1015 return x.dtype.base_dtype.name
1016
1017

AttributeError: 'list' object has no attribute 'dtype'









share|improve this question











$endgroup$











  • $begingroup$
    Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
    $endgroup$
    – Esmailian
    Apr 5 at 11:59











  • $begingroup$
    Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
    $endgroup$
    – Sameer Kesava
    Apr 6 at 13:49














0












0








0





$begingroup$


I am having issues with using the 'stateful' feature when building stacked RNN using LSTMCell object. I am following the instructions on tensorflow on how to set 'stateful = True' by passing the 'batch_shape' to the input layer and the 'batch_input_shape' to the first cell, and also tried to set it in the second cell but it still does not work; tried various combinations but nothing works. The code only works with one cell but not with more than one. I am not sure what I am missing.



The problem I am working on is Sentiment Analysis. 292 is the sequence length I am passing to predict if the sentiment is 1 or 0.



I realize I could use the Sequential model of Keras but I would like to learn the finer features of tensorflow.



import tensorflow as tf

tf.reset_default_graph()

batch_size = 10
embed_size = 5
dropout = 0.5
n_unique_words = 102966
ntimesteps = 292


x = tf.placeholder(dtype = tf.int32, shape = (batch_size, ntimesteps), name='tf_x')
print(x)

y = tf.placeholder(dtype = tf.float32, shape = (batch_size), name = 'tf_y')
print(y)

embed_variable = tf.get_variable(name = 'embedding', shape = [n_unique_words, embed_size], initializer=tf.glorot_uniform_initializer)
print(embed_variable)

embed_x = tf.nn.embedding_lookup(embed_variable, x, name = 'embedded_x')
print(embed_x)

cell1 = tf.keras.layers.LSTMCell(units = 256, batch_input_shape = (10,292,5), dtype = tf.float32)#, dropout=dropout, name = 'lstm1')
print(cell1)


cell2 = tf.keras.layers.LSTMCell(units = 512, batch_input_shape = (10,292,5), dtype = tf.float32)#, name='lstm2', recurrent_dropout=0.5)
print(cell2)


rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
return_state = True, stateful = True, dtype = tf.float32)(rnn_input)


print(rnn_object)


Output:



Tensor("tf_x:0", shape=(10, 292), dtype=int32)
Tensor("tf_y:0", shape=(10,), dtype=float32)
<tf.Variable 'embedding:0' shape=(102966, 5) dtype=float32_ref>
Tensor("embedded_x/Identity:0", shape=(10, 292, 5), dtype=float32)
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3b38>
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3fd0>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-641a99b06a11> in <module>
32 rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
33 rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
---> 34 return_state = True, stateful = True, dtype = tf.float32)(rnn_input)
35
36

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
699
700 if initial_state is None and constants is None:
--> 701 return super(RNN, self).__call__(inputs, **kwargs)
702
703 # If any of `initial_state` or `constants` are specified and are Keras

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
536 if not self.built:
537 # Build layer if applicable (if the `build` method has been overridden).
--> 538 self._maybe_build(inputs)
539 # We must set self.built since user defined build functions are not
540 # constrained to set self.built.

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
1601 # Only call `build` if the user has manually overridden the build method.
1602 if not hasattr(self.build, '_is_default'):
-> 1603 self.build(input_shapes)
1604
1605 def __setattr__(self, name, value):

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in build(self, input_shape)
634 ]
635 if self.stateful:
--> 636 self.reset_states()
637 self.built = True
638

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in reset_states(self, states)
904 K.set_value(state,
905 np.zeros([batch_size] +
--> 906 tensor_shape.as_shape(dim).as_list()))
907 else:
908 K.set_value(self.states[0], np.zeros(

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in set_value(x, value)
2831 (of the same shape).
2832 """
-> 2833 value = np.asarray(value, dtype=dtype(x))
2834 if ops.executing_eagerly_outside_functions():
2835 x.assign(value)

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in dtype(x)
1013 ```
1014 """
-> 1015 return x.dtype.base_dtype.name
1016
1017

AttributeError: 'list' object has no attribute 'dtype'









share|improve this question











$endgroup$




I am having issues with using the 'stateful' feature when building stacked RNN using LSTMCell object. I am following the instructions on tensorflow on how to set 'stateful = True' by passing the 'batch_shape' to the input layer and the 'batch_input_shape' to the first cell, and also tried to set it in the second cell but it still does not work; tried various combinations but nothing works. The code only works with one cell but not with more than one. I am not sure what I am missing.



The problem I am working on is Sentiment Analysis. 292 is the sequence length I am passing to predict if the sentiment is 1 or 0.



I realize I could use the Sequential model of Keras but I would like to learn the finer features of tensorflow.



import tensorflow as tf

tf.reset_default_graph()

batch_size = 10
embed_size = 5
dropout = 0.5
n_unique_words = 102966
ntimesteps = 292


x = tf.placeholder(dtype = tf.int32, shape = (batch_size, ntimesteps), name='tf_x')
print(x)

y = tf.placeholder(dtype = tf.float32, shape = (batch_size), name = 'tf_y')
print(y)

embed_variable = tf.get_variable(name = 'embedding', shape = [n_unique_words, embed_size], initializer=tf.glorot_uniform_initializer)
print(embed_variable)

embed_x = tf.nn.embedding_lookup(embed_variable, x, name = 'embedded_x')
print(embed_x)

cell1 = tf.keras.layers.LSTMCell(units = 256, batch_input_shape = (10,292,5), dtype = tf.float32)#, dropout=dropout, name = 'lstm1')
print(cell1)


cell2 = tf.keras.layers.LSTMCell(units = 512, batch_input_shape = (10,292,5), dtype = tf.float32)#, name='lstm2', recurrent_dropout=0.5)
print(cell2)


rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
return_state = True, stateful = True, dtype = tf.float32)(rnn_input)


print(rnn_object)


Output:



Tensor("tf_x:0", shape=(10, 292), dtype=int32)
Tensor("tf_y:0", shape=(10,), dtype=float32)
<tf.Variable 'embedding:0' shape=(102966, 5) dtype=float32_ref>
Tensor("embedded_x/Identity:0", shape=(10, 292, 5), dtype=float32)
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3b38>
<tensorflow.python.keras.layers.recurrent.LSTMCell object at 0x7fd8088a3fd0>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-641a99b06a11> in <module>
32 rnn_input = tf.keras.Input(batch_shape = (batch_size, 292, 5), dtype = tf.float32) #shape = (batch_size, 292))#
33 rnn_object = tf.keras.layers.RNN(cell = [cell1, cell2], batch_size = 10, return_sequences = True,
---> 34 return_state = True, stateful = True, dtype = tf.float32)(rnn_input)
35
36

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
699
700 if initial_state is None and constants is None:
--> 701 return super(RNN, self).__call__(inputs, **kwargs)
702
703 # If any of `initial_state` or `constants` are specified and are Keras

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
536 if not self.built:
537 # Build layer if applicable (if the `build` method has been overridden).
--> 538 self._maybe_build(inputs)
539 # We must set self.built since user defined build functions are not
540 # constrained to set self.built.

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
1601 # Only call `build` if the user has manually overridden the build method.
1602 if not hasattr(self.build, '_is_default'):
-> 1603 self.build(input_shapes)
1604
1605 def __setattr__(self, name, value):

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in build(self, input_shape)
634 ]
635 if self.stateful:
--> 636 self.reset_states()
637 self.built = True
638

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/layers/recurrent.py in reset_states(self, states)
904 K.set_value(state,
905 np.zeros([batch_size] +
--> 906 tensor_shape.as_shape(dim).as_list()))
907 else:
908 K.set_value(self.states[0], np.zeros(

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in set_value(x, value)
2831 (of the same shape).
2832 """
-> 2833 value = np.asarray(value, dtype=dtype(x))
2834 if ops.executing_eagerly_outside_functions():
2835 x.assign(value)

~/anaconda3/envs/condapy36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py in dtype(x)
1013 ```
1014 """
-> 1015 return x.dtype.base_dtype.name
1016
1017

AttributeError: 'list' object has no attribute 'dtype'






python tensorflow rnn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 5 at 11:12









Tasos

1,62011138




1,62011138










asked Apr 5 at 10:38









Sameer KesavaSameer Kesava

1




1











  • $begingroup$
    Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
    $endgroup$
    – Esmailian
    Apr 5 at 11:59











  • $begingroup$
    Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
    $endgroup$
    – Sameer Kesava
    Apr 6 at 13:49

















  • $begingroup$
    Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
    $endgroup$
    – Esmailian
    Apr 5 at 11:59











  • $begingroup$
    Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
    $endgroup$
    – Sameer Kesava
    Apr 6 at 13:49
















$begingroup$
Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
$endgroup$
– Esmailian
Apr 5 at 11:59





$begingroup$
Welcome to the site! All LSTMs are stateful by definition, you cannot turn it off. Variable stateful = True is something different, turn it False. And I don't think removing the stateful make this error go away, you have a problem with your input, see this stackoverflow post.
$endgroup$
– Esmailian
Apr 5 at 11:59













$begingroup$
Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
$endgroup$
– Sameer Kesava
Apr 6 at 13:49





$begingroup$
Yes, that is for LSTM layer. But I am building an RNN using LSTMCell and there is no option for setting stateful in LSTMCell. Its only in the RNN layer where that option is. As mentioned in my issue, I followed the instructions in the tf documentation to set stateful but nothing worked - I dont know if I have missed something. Also, with stateful = False, when I tried to set the states of the next batch using rnn.reset_states(states = [from previous batch]) I get the error 'AttributeError: Layer must be stateful.'
$endgroup$
– Sameer Kesava
Apr 6 at 13:49











0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48688%2fissues-with-using-stateful-in-stackedrnn-cells%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Data Science Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48688%2fissues-with-using-stateful-in-stackedrnn-cells%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High