用於從 Example 解析稀疏輸入特征的配置。
用法
tf.io.SparseFeature(
index_key, value_key, dtype, size, already_sorted=False
)屬性
-
index_key字段編號 0 的namedtuple別名 -
value_key字段編號 1 的namedtuple別名 -
dtype字段編號 2 的namedtuple別名 -
size字段編號 3 的namedtuple別名 -
already_sorted字段編號 4 的namedtuple別名
請注意,由於其簡單性,最好使用 VarLenFeature(可能與 SequenceExample 組合)以解析出 SparseTensor 而不是 SparseFeature。
密切模仿將通過使用SparseFeature 配置解析Example 獲得的SparseTensor,SparseFeature 包含
value_key:Example中Feature的鍵名,其解析後的Tensor將是生成的SparseTensor.values。index_key:名稱列表 - 生成的SparseTensor中的每個維度都有一個名稱,其indices[i][dim]表示i-th 值在dim維度中的位置將等於i-th Feature 中的值與Example中名為index_key[dim]的鍵。size:生成的SparseTensor.dense_shape的整數列表。
比如我們可以表示下麵的2DSparseTensor
SparseTensor(indices=[[3, 1], [20, 0]],
values=[0.5, -1.0]
dense_shape=[100, 3])
帶有 Example 輸入原型
features {
feature { key:"val" value { float_list { value:[ 0.5, -1.0 ] } } }
feature { key:"ix0" value { int64_list { value:[ 3, 20 ] } } }
feature { key:"ix1" value { int64_list { value:[ 1, 0 ] } } }
}
和 SparseFeature 配置 2 index_key s
SparseFeature(index_key=["ix0", "ix1"],
value_key="val",
dtype=tf.float32,
size=[100, 3])
領域:
index_key:單個字符串名稱或索引特征的字符串名稱列表。對於每個鍵,基礎函數的類型必須是int64並且它的長度必須始終與value_key特征。代表SparseTensor帶有一個dense_shape的rank大於 1 的長度列表rank應該使用。value_key:價值特征的名稱。基礎特征的類型必須是dtype並且它的長度必須總是匹配所有的index_keys 的特點。dtype:數據類型value_key特征。size:指定密集形狀的 Python int 或其列表。當且僅當應該是一個列表index_key是一個列表。在這種情況下,列表必須等於index_key.每個條目i中的所有值index_key[i] 特征必須在[0, size[i]).already_sorted:一個 Python 布爾值,用於指定是否在value_key已按其索引位置排序。如果是這樣跳過排序。默認為 False(可選)。
相關用法
- Python tf.io.gfile.GFile.close用法及代碼示例
- Python tf.io.gfile.join用法及代碼示例
- Python tf.io.parse_example用法及代碼示例
- Python tf.io.gfile.exists用法及代碼示例
- Python tf.io.serialize_tensor用法及代碼示例
- Python tf.io.gfile.GFile用法及代碼示例
- Python tf.io.gfile.copy用法及代碼示例
- Python tf.io.gfile.glob用法及代碼示例
- Python tf.io.decode_json_example用法及代碼示例
- Python tf.io.TFRecordWriter用法及代碼示例
- Python tf.io.decode_gif用法及代碼示例
- Python tf.io.decode_raw用法及代碼示例
- Python tf.io.RaggedFeature用法及代碼示例
- Python tf.io.read_file用法及代碼示例
- Python tf.io.deserialize_many_sparse用法及代碼示例
- Python tf.io.write_graph用法及代碼示例
- Python tf.io.TFRecordOptions.get_compression_type_string用法及代碼示例
- Python tf.io.decode_proto用法及代碼示例
- Python tf.image.random_brightness用法及代碼示例
- Python tf.image.pad_to_bounding_box用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.io.SparseFeature。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
