tf.raw_ops.LoadAndRemapMatrix
Loads a 2-D (matrix) Tensor
with name old_tensor_name
from the checkpoint
tf.raw_ops.LoadAndRemapMatrix( ckpt_path, old_tensor_name, row_remapping, col_remapping, initializing_values, num_rows, num_cols, max_rows_in_memory=-1, name=None )
at ckpt_path
and potentially reorders its rows and columns using the specified remappings.
Most users should use one of the wrapper initializers (such as tf.contrib.framework.load_and_remap_matrix_initializer
) instead of this function directly.
The remappings are 1-D tensors with the following properties:
-
row_remapping
must have exactlynum_rows
entries. Rowi
of the output matrix will be initialized from the row corresponding to indexrow_remapping[i]
in the oldTensor
from the checkpoint. -
col_remapping
must have either 0 entries (indicating that no column reordering is needed) ornum_cols
entries. If specified, columnj
of the output matrix will be initialized from the column corresponding to indexcol_remapping[j]
in the oldTensor
from the checkpoint. - A value of -1 in either of the remappings signifies a "missing" entry. In that case, values from the
initializing_values
tensor will be used to fill that missing row or column. Ifrow_remapping
hasr
missing entries andcol_remapping
hasc
missing entries, then the following condition must be true:
(r * num_cols) + (c * num_rows) - (r * c) == len(initializing_values)
The remapping tensors can be generated using the GenerateVocabRemapping op.
As an example, with row_remapping = [1, 0, -1], col_remapping = [0, 2, -1], initializing_values = [0.5, -0.5, 0.25, -0.25, 42], and w(i, j) representing the value from row i, column j of the old tensor in the checkpoint, the output matrix will look like the following:
[[w(1, 0), w(1, 2), 0.5], [w(0, 0), w(0, 2), -0.5], [0.25, -0.25, 42]]
Args | |
---|---|
ckpt_path | A Tensor of type string . Path to the TensorFlow checkpoint (version 2, TensorBundle ) from which the old matrix Tensor will be loaded. |
old_tensor_name | A Tensor of type string . Name of the 2-D Tensor to load from checkpoint. |
row_remapping | A Tensor of type int64 . An int Tensor of row remappings (generally created by generate_vocab_remapping ). Even if no row remapping is needed, this must still be an index-valued Tensor (e.g. [0, 1, 2, ...]), or a shifted index-valued Tensor (e.g. [8, 9, 10, ...], for partitioned Variables ). |
col_remapping | A Tensor of type int64 . An int Tensor of column remappings (generally created by generate_vocab_remapping ). May be a size-0 Tensor if only row remapping is to be done (e.g. column ordering is the same). |
initializing_values | A Tensor of type float32 . A float Tensor containing values to fill in for cells in the output matrix that are not loaded from the checkpoint. Length must be exactly the same as the number of missing / new cells. |
num_rows | An int that is >= 0 . Number of rows (length of the 1st dimension) in the output matrix. |
num_cols | An int that is >= 1 . Number of columns (length of the 2nd dimension) in the output matrix. |
max_rows_in_memory | An optional int . Defaults to -1 . The maximum number of rows to load from the checkpoint at once. If less than or equal to 0, the entire matrix will be loaded into memory. Setting this arg trades increased disk reads for lower memory usage. |
name | A name for the operation (optional). |
Returns | |
---|---|
A Tensor of type float32 . |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/raw_ops/LoadAndRemapMatrix