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

Method get_initial_state

tensorflow/python/keras/layers/recurrent.py:593–614  ·  view source on GitHub ↗
(self, inputs)

Source from the content-addressed store, hash-verified

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,

Callers 10

_process_inputsMethod · 0.95
callMethod · 0.45
callMethod · 0.45
_assert_cell_buildsMethod · 0.45
callMethod · 0.45
_run_cellMethod · 0.45

Calls 3

flattenMethod · 0.45
shapeMethod · 0.45

Tested by 8

callMethod · 0.36
callMethod · 0.36
_assert_cell_buildsMethod · 0.36
_run_cellMethod · 0.36