tfr.utils.padded_nd_indices
Stay organized with collections
Save and categorize content based on your preferences.
Pads the invalid entries by valid ones and returns the nd_indices.
tfr.utils.padded_nd_indices(
is_valid, shuffle=False, seed=None
)
For example, when we have a batch_size = 1 and list_size = 3. Only the first 2
entries are valid. We have:
is_valid = [[True, True, False]]
nd_indices, mask = padded_nd_indices(is_valid)
nd_indices has a shape [1, 3, 2] and mask has a shape [1, 3].
nd_indices = [[[0, 0], [0, 1], [0, 0]]]
mask = [[True, True, False]]
nd_indices can be used by gather_nd on a Tensor t
padded_t = tf.gather_nd(t, nd_indices)
and get the following Tensor with first 2 dims are [1, 3]:
padded_t = [[t(0, 0), t(0, 1), t(0, 0)]]
Args |
is_valid
|
A boolean Tensor for entry validity with shape [batch_size,
list_size].
|
shuffle
|
A boolean that indicates whether valid indices should be shuffled.
|
seed
|
Random seed for shuffle.
|
Returns |
A tuple of Tensors (nd_indices, mask). The first has shape [batch_size,
list_size, 2] and it can be used in gather_nd or scatter_nd. The second has
the shape of [batch_size, list_size] with value True for valid indices.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-08-18 UTC.
[null,null,["Last updated 2023-08-18 UTC."],[],[],null,["# tfr.utils.padded_nd_indices\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/utils.py#L308-L356) |\n\nPads the invalid entries by valid ones and returns the nd_indices. \n\n tfr.utils.padded_nd_indices(\n is_valid, shuffle=False, seed=None\n )\n\nFor example, when we have a batch_size = 1 and list_size = 3. Only the first 2\nentries are valid. We have: \n\n is_valid = [[True, True, False]]\n nd_indices, mask = padded_nd_indices(is_valid)\n\nnd_indices has a shape \\[1, 3, 2\\] and mask has a shape \\[1, 3\\]. \n\n nd_indices = [[[0, 0], [0, 1], [0, 0]]]\n mask = [[True, True, False]]\n\nnd_indices can be used by gather_nd on a Tensor t \n\n padded_t = tf.gather_nd(t, nd_indices)\n\nand get the following Tensor with first 2 dims are \\[1, 3\\]: \n\n padded_t = [[t(0, 0), t(0, 1), t(0, 0)]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|-----------------------------------------------------------------------------|\n| `is_valid` | A boolean `Tensor` for entry validity with shape \\[batch_size, list_size\\]. |\n| `shuffle` | A boolean that indicates whether valid indices should be shuffled. |\n| `seed` | Random seed for shuffle. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tuple of Tensors (nd_indices, mask). The first has shape \\[batch_size, list_size, 2\\] and it can be used in gather_nd or scatter_nd. The second has the shape of \\[batch_size, list_size\\] with value True for valid indices. ||\n\n\u003cbr /\u003e"]]