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

Function set_tensor_shapes

tensorflow/lite/python/util.py:126–154  ·  view source on GitHub ↗

Sets Tensor shape for each tensor if the shape is defined. Args: tensors: TensorFlow ops.Tensor. shapes: Dict of strings representing input tensor names to list of integers representing input shapes (e.g., {"foo": : [1, 16, 16, 3]}). Raises: ValueError: `shapes` contain

(tensors, shapes)

Source from the content-addressed store, hash-verified

124
125
126def set_tensor_shapes(tensors, shapes):
127 """Sets Tensor shape for each tensor if the shape is defined.
128
129 Args:
130 tensors: TensorFlow ops.Tensor.
131 shapes: Dict of strings representing input tensor names to list of
132 integers representing input shapes (e.g., {"foo": : [1, 16, 16, 3]}).
133
134 Raises:
135 ValueError:
136 `shapes` contains an invalid tensor.
137 `shapes` contains an invalid shape for a valid tensor.
138 """
139 if shapes:
140 tensor_names_to_tensor = {
141 get_tensor_name(tensor): tensor for tensor in tensors
142 }
143 for name, shape in shapes.items():
144 if name not in tensor_names_to_tensor:
145 raise ValueError("Invalid tensor \'{}\' found in tensor shapes "
146 "map.".format(name))
147 if shape is not None:
148 tensor = tensor_names_to_tensor[name]
149 try:
150 tensor.set_shape(shape)
151 except ValueError as error:
152 message = ("The shape of tensor '{0}' cannot be changed from {1} to "
153 "{2}. {3}".format(name, tensor.shape, shape, str(error)))
154 raise ValueError(message)
155
156
157def get_grappler_config(optimizers_list):

Callers

nothing calls this directly

Calls 3

get_tensor_nameFunction · 0.85
formatMethod · 0.45
set_shapeMethod · 0.45

Tested by

no test coverage detected