| 591 | raise validation_error |
| 592 | |
| 593 | def get_initial_state(self, inputs): |
| 594 | get_initial_state_fn = getattr(self.cell, 'get_initial_state', None) |
| 595 | |
| 596 | if nest.is_sequence(inputs): |
| 597 | # The input are nested sequences. Use the first element in the seq to get |
| 598 | # batch size and dtype. |
| 599 | inputs = nest.flatten(inputs)[0] |
| 600 | |
| 601 | input_shape = array_ops.shape(inputs) |
| 602 | batch_size = input_shape[1] if self.time_major else input_shape[0] |
| 603 | dtype = inputs.dtype |
| 604 | if get_initial_state_fn: |
| 605 | init_state = get_initial_state_fn( |
| 606 | inputs=None, batch_size=batch_size, dtype=dtype) |
| 607 | else: |
| 608 | init_state = _generate_zero_filled_state(batch_size, self.cell.state_size, |
| 609 | dtype) |
| 610 | # Keras RNN expect the states in a list, even if it's a single state tensor. |
| 611 | if not nest.is_sequence(init_state): |
| 612 | init_state = [init_state] |
| 613 | # Force the state to be a list in case it is a namedtuple eg LSTMStateTuple. |
| 614 | return list(init_state) |
| 615 | |
| 616 | def __call__(self, inputs, initial_state=None, constants=None, **kwargs): |
| 617 | inputs, initial_state, constants = _standardize_args(inputs, |