【发布时间】:2021-01-14 07:13:25
【问题描述】:
t = 'comcom.android.systemuicom.android.systemuicom.android.systemui'
def pad_trunc_shingle(t):
shingle_max = 300
actual_len = tf.strings.length(t).numpy()
if actual_len > shingle_max:
return tf.strings.substr(t, 0, shingle_max)
else:
return tf.strings.join(('#' * (shingle_max- actual_len) ,t))
这个功能可以工作:
<tf.Tensor: shape=(), dtype=string, numpy=b'#############################################################################################################################################################################################################################################comcom.android.systemuicom.android.systemuicom.android.systemui'>
然而,当我使用这个函数时,是数据集映射函数。 它引发错误:
AttributeError: 'Tensor' 对象没有属性 'numpy'
处理数据集映射函数时如何获取actual_len?
tf 版本:2.3.1
【问题讨论】:
标签: python tensorflow tensorflow2.0 tensorflow-datasets