簡體   English   中英

使用Tensorflow變換/波束時,出現'ValueError:遇到無法由ListColumnRepresentation解碼的SparseTensorValue'

[英]'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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM