Python tensorflow数据集中的稀疏张量
我有一个使用TFRecord的tensorflow程序,我想用tf.contrib.data.TFRecordDataset读取数据,但当我尝试解析示例时,我遇到一个异常:“TypeError:未能将类型的对象转换为Tensor” 当你只试着 代码是:Python tensorflow数据集中的稀疏张量,python,tensorflow,Python,Tensorflow,我有一个使用TFRecord的tensorflow程序,我想用tf.contrib.data.TFRecordDataset读取数据,但当我尝试解析示例时,我遇到一个异常:“TypeError:未能将类型的对象转换为Tensor” 当你只试着 代码是: def _parse_function(example_proto): features = {"var_len_feature": tf.VarLenFeature(tf.float32), "Fixe
def _parse_function(example_proto):
features = {"var_len_feature": tf.VarLenFeature(tf.float32),
"FixedLenFeature": tf.FixedLenFeature([10], tf.int64),
"label": tf.FixedLenFeature((), tf.int32default_value=0)}
parsed_features = tf.parse_single_example(example_proto, features)
return parsed_features["image"], parsed_features["label"]
filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"]
dataset = tf.contrib.data.TFRecordDataset(filenames)
dataset = dataset.map(_parse_function)
张量流编程中的教程具有不同的缩进
# Transforms a scalar string `example_proto` into a pair of a scalar string and
# a scalar integer, representing an image and its label, respectively.
def _parse_function(example_proto):
features = {"image": tf.FixedLenFeature((), tf.string, default_value=""),
"label": tf.FixedLenFeature((), tf.int32, default_value=0)}
parsed_features = tf.parse_single_example(example_proto, features)
return parsed_features["image"], parsed_features["label"]
# Creates a dataset that reads all of the examples from two files, and extracts
# the image and label features.
filenames = ["/var/data/file1.tfrecord", "/var/data/file2.tfrecord"]
dataset = tf.contrib.data.TFRecordDataset(filenames)
dataset = dataset.map(_parse_function)
错误的缩进可能导致TypeError,pyton解释器处理不需要的控制流 tf.VarLenFeature创建SparseTensor。大多数情况下,稀疏传感器与小批量相关。你能像下面那样试试吗 dataset=tf.contrib.data.TFRecordDataset(文件名) dataset=dataset.batch(批次大小=32)
dataset=dataset.map(_parse_函数)TensorFlow在v1.5中增加了对此的支持
“tf.data现在支持数据集元素中的tf.SparseTensor组件。”它与缩进无关。它适用于我的FixedLenFeature,但不适用于VarLenFeature。缩进就在我为StackOverflow创建的示例中,这有什么更新吗?如果你能知道answer@AdamSnaider对tf 1.5中支持它似乎还不支持VarLenFeature。@为了完全支持它,我们正在开发tensorflow 1.6,它工作正常。