codecamp

TensorFlow函数教程:tf.io.SparseFeature

tf.io.SparseFeature函数

类 SparseFeature

别名:

  • 类 tf.SparseFeature
  • 类 tf.io.SparseFeature

定义在:tensorflow/python/ops/parsing_ops.py。

用于解析Example的稀疏输入要素的配置。

注意,最好使用VarLenFeature(可能与SequenceExample结合使用),以便解析SparseTensors而不是SparseFeature,因为它的简单性。

通过使用SparseFeature配置解析Example获得的非常相似的SparseTensor,SparseFeature包含:

  • value_key:Example中Feature的键名称,解析Tensor将是生成的sparsetensor. value。
  • index_key:一个名称列表 - 一个用于生成的SparseTensor中的每个维度,其indices[i][dim]表示dim维度中第i个值的位置将等于Feature中的第i个值,并在Example中命名为index_key [dim]。
  • size:生成的SparseTensor.dense_shape的整数列表。

例如,我们可以表示以下2D SparseTensor

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:

SparseFeature(index_key=["ix0", "ix1"],
              value_key="val",
              dtype=tf.float32,
              size=[100, 3])

字段:

  • index_key:单个字符串名称或索引功能的字符串名称列表。对于每个键,基础特性的类型必须是int64,并且其长度必须始终与value_key特性的长度匹配。若要表示具有rank大于1的dense_shape的SparseTensor,应使用长度rank列表。
  • value_key:值特性的名称。底层特性的类型必须是dtype,并且其长度必须始终与所有index_keys特性的长度相匹配。
  • dtype:value_key特性的数据类型。
  • size:Python int或其列表,指定密集形状。当且仅当index_key是列表时,应该是列表。在这种情况下,列表必须等于index_key的长度。index_key [i]特性中的每个条目i的所有值都必须位于[0, size[i])中。
  • already_sorted:一个Python布尔值,用于指定value_key中的值是否已按其索引位置排序。如果是,请跳过排序。默认为False(可选)。

__new__

@staticmethod
__new__(
    cls,
    index_key,
    value_key,
    dtype,
    size,
    already_sorted=False
)

创建SparseFeature(index_key, value_key, dtype, size, already_sorted)的新实例。

属性

index_key

value_key

dtype

size

already_sorted

TensorFlow函数教程:tf.io.serialize_tensor
TensorFlow函数教程:tf.io.TFRecordCompressionType
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }