當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.raw_ops.DeserializeSparse用法及代碼示例

反序列化 SparseTensor 對象。

用法

tf.raw_ops.DeserializeSparse(
    serialized_sparse, dtype, name=None
)

參數

  • serialized_sparse 一個Tensor。必須是以下類型之一:string , variant。序列化的SparseTensor 對象。最後一個維度必須有 3 列。
  • dtype 一個tf.DType。序列化的SparseTensor 對象的dtype
  • name 操作的名稱(可選)。

返回

  • Tensor 對象的元組(sparse_indices、sparse_values、sparse_shape)。
  • sparse_indices Tensor 類型為 int64
  • sparse_values Tensor 類型為 dtype
  • sparse_shape Tensor 類型為 int64

輸入 serialized_sparse 的形狀必須為 [?, ?, ..., ?, 3],其中最後一個維度存儲序列化的 SparseTensor 對象,其他 N 個維度 (N >= 0) 對應於一個批次。原始SparseTensor 對象的等級必須全部匹配。當最後的SparseTensor被創建時,它的rank是傳入的SparseTensor對象的rank加上N;稀疏張量已沿新維度連接,每批一個。

原始尺寸的輸出SparseTensor 對象的形狀值是對應尺寸的輸入SparseTensor 對象的形狀值的最大值。新尺寸與批次的大小相匹配。

假設輸入SparseTensor 對象的索引按標準字典順序排序。如果不是這種情況,則在此步驟之後運行SparseReorder 以恢複索引順序。

例如,如果序列化輸入是一個 [2 x 3] 矩陣,表示兩個原始 SparseTensor 對象:

index = [ 0]
        [10]
        [20]
values = [1, 2, 3]
shape = [50]

index = [ 2]
        [10]
values = [4, 5]
shape = [30]

那麽最終反序列化的SparseTensor 將是:

index = [0  0]
        [0 10]
        [0 20]
        [1  2]
        [1 10]
values = [1, 2, 3, 4, 5]
shape = [2 50]

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.raw_ops.DeserializeSparse。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。