我有使用TFRecord的tensorflow程序,我想用tf.contrib.data.TFRecordDataset读取数据但是当我尝试解析示例时我得到一个异常:“TypeError:无法将类型的对象转换为Tensor “ 仅尝试
时代码是:
printDoc
答案 0 :(得分:2)
TensorFlow在v1.5中添加了对此的支持
https://github.com/tensorflow/tensorflow/releases/tag/v1.5.0
" tf.data现在支持数据集元素中的tf.SparseTensor组件。"
答案 1 :(得分:0)
Tensor Flow编程中的教程guide有不同的缩进。
# 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解释器处理不需要的控制流。
答案 2 :(得分:0)
.VarLenFeature创建SparseTensor。大多数情况下,SparseTensors与迷你批次相关联。你可以试试下面的吗?
dataset = tf.contrib.data.TFRecordDataset(filenames)
dataset = dataset.batch(batch_size = 32)
dataset = dataset.map(_parse_function)