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

Function _padded_shape_to_tensor

tensorflow/python/data/ops/dataset_ops.py:3340–3386  ·  view source on GitHub ↗

Converts `padded_shape` to a `tf.Tensor` representing that shape. Args: padded_shape: A shape-like object, which may be a `tf.TensorShape`, a Python sequence, or a 1-D `tf.Tensor` of `tf.int64` elements. input_component_shape: A `tf.TensorShape`, with which `padded_shape` must

(padded_shape, input_component_shape)

Source from the content-addressed store, hash-verified

3338
3339
3340def _padded_shape_to_tensor(padded_shape, input_component_shape):
3341 """Converts `padded_shape` to a `tf.Tensor` representing that shape.
3342
3343 Args:
3344 padded_shape: A shape-like object, which may be a `tf.TensorShape`, a Python
3345 sequence, or a 1-D `tf.Tensor` of `tf.int64` elements.
3346 input_component_shape: A `tf.TensorShape`, with which `padded_shape` must
3347 be compatible.
3348
3349 Returns:
3350 A 1-D `tf.Tensor` of `tf.int64` elements, representing `padded_shape`.
3351
3352 Raises:
3353 ValueError: If `padded_shape` is not a shape or not compatible with
3354 `input_component_shape`.
3355 TypeError: If `padded_shape` is not convertible to a `tf.int64` tensor.
3356 """
3357 try:
3358 # Try to convert the `padded_shape` to a `tf.TensorShape`
3359 padded_shape_as_shape = tensor_shape.as_shape(padded_shape)
3360 # We will return the "canonical" tensor representation, which uses
3361 # `-1` in place of `None`.
3362 ret = ops.convert_to_tensor(
3363 [dim if dim is not None else -1
3364 for dim in padded_shape_as_shape.as_list()], dtype=dtypes.int64)
3365 except (TypeError, ValueError):
3366 # The argument was not trivially convertible to a
3367 # `tf.TensorShape`, so fall back on the conversion to tensor
3368 # machinery.
3369 ret = ops.convert_to_tensor(padded_shape, preferred_dtype=dtypes.int64)
3370 if ret.shape.dims is not None and len(ret.shape.dims) != 1:
3371 raise ValueError(
3372 "Padded shape %s must be a 1-D tensor of tf.int64 values, but its "
3373 "shape was %s." % (padded_shape, ret.shape))
3374 if ret.dtype != dtypes.int64:
3375 raise TypeError(
3376 "Padded shape %s must be a 1-D tensor of tf.int64 values, but its "
3377 "element type was %s." % (padded_shape, ret.dtype.name))
3378 padded_shape_as_shape = tensor_util.constant_value_as_shape(ret)
3379
3380 if not _is_padded_shape_compatible_with(padded_shape_as_shape,
3381 input_component_shape):
3382 raise ValueError("The padded shape %s is not compatible with the "
3383 "corresponding input component shape %s."
3384 % (padded_shape_as_shape, input_component_shape))
3385
3386 return ret
3387
3388
3389def _padding_value_to_tensor(value, output_type):

Callers 1

__init__Method · 0.85

Calls 2

as_listMethod · 0.45

Tested by

no test coverage detected