| 118 | return tuple(initial_states) |
| 119 | |
| 120 | def call(self, inputs, states, constants=None, **kwargs): |
| 121 | # Recover per-cell states. |
| 122 | state_size = (self.state_size[::-1] |
| 123 | if self.reverse_state_order else self.state_size) |
| 124 | nested_states = nest.pack_sequence_as(state_size, nest.flatten(states)) |
| 125 | |
| 126 | # Call the cells in order and store the returned states. |
| 127 | new_nested_states = [] |
| 128 | for cell, states in zip(self.cells, nested_states): |
| 129 | states = states if nest.is_sequence(states) else [states] |
| 130 | # TF cell does not wrap the state into list when there is only one state. |
| 131 | is_tf_rnn_cell = getattr(cell, '_is_tf_rnn_cell', None) is not None |
| 132 | states = states[0] if len(states) == 1 and is_tf_rnn_cell else states |
| 133 | if generic_utils.has_arg(cell.call, 'constants'): |
| 134 | inputs, states = cell.call(inputs, states, constants=constants, |
| 135 | **kwargs) |
| 136 | else: |
| 137 | inputs, states = cell.call(inputs, states, **kwargs) |
| 138 | new_nested_states.append(states) |
| 139 | |
| 140 | return inputs, nest.pack_sequence_as(state_size, |
| 141 | nest.flatten(new_nested_states)) |
| 142 | |
| 143 | @tf_utils.shape_type_conversion |
| 144 | def build(self, input_shape): |