Unpack the tensor. See tf.unpack. Args: labeled_tensor: The input tensor. axis_name: Optional name of axis to unpack. By default, the first axis is used. name: Optional op name. Returns: The list of unpacked LabeledTensors. Raises: ValueError: If `axis_name` is
(labeled_tensor, axis_name=None, name=None)
| 261 | @tc.accepts(core.LabeledTensorLike, |
| 262 | tc.Optional(string_types), tc.Optional(string_types)) |
| 263 | def unpack(labeled_tensor, axis_name=None, name=None): |
| 264 | """Unpack the tensor. |
| 265 | |
| 266 | See tf.unpack. |
| 267 | |
| 268 | Args: |
| 269 | labeled_tensor: The input tensor. |
| 270 | axis_name: Optional name of axis to unpack. By default, the first axis is |
| 271 | used. |
| 272 | name: Optional op name. |
| 273 | |
| 274 | Returns: |
| 275 | The list of unpacked LabeledTensors. |
| 276 | |
| 277 | Raises: |
| 278 | ValueError: If `axis_name` is not an axis on the input. |
| 279 | """ |
| 280 | with ops.name_scope(name, 'lt_unpack', [labeled_tensor]) as scope: |
| 281 | labeled_tensor = core.convert_to_labeled_tensor(labeled_tensor) |
| 282 | |
| 283 | axis_names = list(labeled_tensor.axes.keys()) |
| 284 | if axis_name is None: |
| 285 | axis_name = axis_names[0] |
| 286 | |
| 287 | if axis_name not in axis_names: |
| 288 | raise ValueError('%s not in %s' % (axis_name, axis_names)) |
| 289 | axis = axis_names.index(axis_name) |
| 290 | |
| 291 | unpack_ops = array_ops.unstack(labeled_tensor.tensor, axis=axis, name=scope) |
| 292 | axes = [a for i, a in enumerate(labeled_tensor.axes.values()) if i != axis] |
| 293 | return [core.LabeledTensor(t, axes) for t in unpack_ops] |
| 294 | |
| 295 | |
| 296 | @tc.returns(core.LabeledTensor) |