![](/img/trans.png)
[英]Issue with TensorFlow tensorflow_transform.beam on Windows
[英]'ValueError: Encountered a SparseTensorValue that cannot be decoded by ListColumnRepresentation' when working with Tensorflow Transform / Beam
我正在运行一个Tensorflow转换/梁管道以加载/预处理并另存为TFRecords。 这些记录然后被加载。 在Tensorflow Transform中进行预处理期间,我想填充稀疏张量。 因此,我想将其转换为密集的,填充的并转换回稀疏的。
代码看起来像这样:
import tensorflow_transform as tft
import tensorflow as tf
#...
def preprocess_fn(input_features):
output_features = {}
output_features[CATEGORICAL_FEATURE_NAMES] = tft.compute_and_apply_vocabulary(...)
#dense = tf.sparse.to_dense(output_features[CATEGORICAL_FEATURE_NAMES])
## do something with dense
#output_features[CATEGORICAL_FEATURE_NAMES] = tf.contrib.layers.dense_to_sparse(dense)
return output_features
要加载TFRecords,我使用以下功能:
def tfrecords_input_fn(files_name_pattern, transformed_metadata,
mode=tf.estimator.ModeKeys.EVAL,
num_epochs=1,
batch_size=64):
dataset = tf.data.experimental.make_batched_features_dataset(
file_pattern=files_name_pattern,
batch_size=batch_size,
features=transformed_metadata.schema.as_feature_spec(),
reader=tf.data.TFRecordDataset,
num_epochs=num_epochs,
shuffle=True if mode == tf.estimator.ModeKeys.TRAIN else False,
shuffle_buffer_size=1 + (batch_size * 2),
prefetch_buffer_size=1,
drop_final_batch=True
)
iterator = dataset.make_one_shot_iterator()
features = iterator.get_next()
target = features.pop(TARGET_FEATURE_NAME)
return features, target
运行整个管道(加载原始数据,转换,保存TFRecords,然后加载那些以将它们打印到屏幕上)可以正常工作,但是取消注释“ preprocess_fn”中的两行会导致以下错误:
文件“ ... / lib / python3.6 / site-packages / tensorflow_transform / impl_helper.py”,行262,位于to_instance_dicts中,引发ValueError('遇到一个SparseTensorValue,不能为'ValueError:遇到了一个不能由ListColumnRepresentation解码的SparseTensorValue 。
...
ValueError:遇到无法由ListColumnRepresentation解码的SparseTensorValue。 [在运行'%s时-Transform / ConvertAndUnbatch']
是否有人对此代码有建议或对我错过的内容有任何提示? 很感谢任何形式的帮助!
最好,多米尼克
tf.Transform支持参差不齐的稀疏张量,因此输入和输出的每一行都应保持对齐。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.