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

Method get_initial_state

tensorflow/python/ops/rnn_cell_impl.py:281–309  ·  view source on GitHub ↗
(self, inputs=None, batch_size=None, dtype=None)

Source from the content-addressed store, hash-verified

279 pass
280
281 def get_initial_state(self, inputs=None, batch_size=None, dtype=None):
282 if inputs is not None:
283 # Validate the given batch_size and dtype against inputs if provided.
284 inputs = ops.convert_to_tensor(inputs, name="inputs")
285 if batch_size is not None:
286 if tensor_util.is_tensor(batch_size):
287 static_batch_size = tensor_util.constant_value(
288 batch_size, partial=True)
289 else:
290 static_batch_size = batch_size
291 if inputs.shape.dims[0].value != static_batch_size:
292 raise ValueError(
293 "batch size from input tensor is different from the "
294 "input param. Input tensor batch: {}, batch_size: {}".format(
295 inputs.shape.dims[0].value, batch_size))
296
297 if dtype is not None and inputs.dtype != dtype:
298 raise ValueError(
299 "dtype from input tensor is different from the "
300 "input param. Input tensor dtype: {}, dtype: {}".format(
301 inputs.dtype, dtype))
302
303 batch_size = inputs.shape.dims[0].value or array_ops.shape(inputs)[0]
304 dtype = inputs.dtype
305 if batch_size is None or dtype is None:
306 raise ValueError(
307 "batch_size and dtype cannot be None while constructing initial "
308 "state: batch_size={}, dtype={}".format(batch_size, dtype))
309 return self.zero_state(batch_size, dtype)
310
311 def zero_state(self, batch_size, dtype):
312 """Return zero-filled state tensor(s).

Callers 11

zero_stateMethod · 0.45
_assert_cell_buildsMethod · 0.45
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45
dynamic_rnnFunction · 0.45
get_initial_stateFunction · 0.45
mainFunction · 0.45
trainMethod · 0.45
decode_greedyMethod · 0.45
mainFunction · 0.45

Calls 4

zero_stateMethod · 0.95
is_tensorMethod · 0.80
formatMethod · 0.45
shapeMethod · 0.45

Tested by 2

_assert_cell_buildsMethod · 0.36