尝试解码TFRecord示例时遇到以下错误:
InvalidArgumentError: Name: , Feature: relevance (data type: float) is required but could not be found. [Op:ParseExample]
为了解码这个例子,我使用tf.io.parse_example
,如下所示
example_features = tf.compat.v1.io.parse_example(
tf.reshape(serialized_list, [-1]), peritem_feature_spec)
其中serialized_list
看起来像
并且peritem_feature_spec
看起来像
peritem_feature_spec = {
'relevance':tf.FixedLenFeature([], tf.float32),
'encoded_clust_index':tf.VarLenFeature(tf.float32)
}
我很困惑为什么找不到“相关性”这个功能。我认为我正确地编码和创建了TFRecord对象。我是否错误地创建了特性规范?我的想法是tf.VarLenFeature
是不正确的特性类型,但我无法确定什么是正确的。在
使用tensorflow_ranking.python.data.parse_from_example_in_example
可以正确地将TFRecord解码为它的特性,但是我不知道tf.io.parse_example
失败的原因
代替
VarLenFeature
你能试试tf.FixedLenSequenceFeature([], tf.float32, allow_missing = True ,default_value=0)
解释的here,看看这是否有效?在编辑:我以前的答案在这个答案下面
正确的答案是向特性规范提供
default_value
我的旧的答案如下
所以问题归结为我的特征是如何被填充在tensorflow_排名库中的。它填充了一个列表功能,比如:
^{pr2}$此方法将空字节追加到张量的末尾。解析器在空张量中寻找
feature_name
,并返回找不到它。我的解决方法是附加序列化的TFRecord示例原型,而不是一个空字节字符串。我是这样完成的:相关问题 更多 >
编程相关推荐