MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _validate_state_spec

Method _validate_state_spec

tensorflow/python/keras/layers/recurrent.py:565–591  ·  view source on GitHub ↗

Validate the state spec between the initial_state and the state_size. Args: cell_state_sizes: list, the `state_size` attribute from the cell. init_state_specs: list, the `state_spec` from the initial_state that is passed in `call()`. Raises: ValueError: When initi

(cell_state_sizes, init_state_specs)

Source from the content-addressed store, hash-verified

563
564 @staticmethod
565 def _validate_state_spec(cell_state_sizes, init_state_specs):
566 """Validate the state spec between the initial_state and the state_size.
567
568 Args:
569 cell_state_sizes: list, the `state_size` attribute from the cell.
570 init_state_specs: list, the `state_spec` from the initial_state that is
571 passed in `call()`.
572
573 Raises:
574 ValueError: When initial state spec is not compatible with the state size.
575 """
576 validation_error = ValueError(
577 'An `initial_state` was passed that is not compatible with '
578 '`cell.state_size`. Received `state_spec`={}; '
579 'however `cell.state_size` is '
580 '{}'.format(init_state_specs, cell_state_sizes))
581 flat_cell_state_size = nest.flatten(cell_state_sizes)
582 flat_state_spec = nest.flatten(init_state_specs)
583
584 if len(flat_cell_state_size) != len(flat_state_spec):
585 raise validation_error
586 for i in range(len(flat_cell_state_size)):
587 if not tensor_shape.TensorShape(
588 # Ignore the first axis for init_state which is for batch
589 flat_state_spec[i].shape[1:]).is_compatible_with(
590 tensor_shape.TensorShape(flat_cell_state_size[i])):
591 raise validation_error
592
593 def get_initial_state(self, inputs):
594 get_initial_state_fn = getattr(self.cell, 'get_initial_state', None)

Callers 1

buildMethod · 0.95

Calls 4

rangeFunction · 0.50
formatMethod · 0.45
flattenMethod · 0.45
is_compatible_withMethod · 0.45

Tested by

no test coverage detected