用于从 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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
