我开始使用Keras,并希望从多个TFRecord文件创建一个数据集。
下面是我到目前为止拥有的代码。
dataset <- tfrecord_dataset(filenames) %>%
dataset_map(function(example_proto) {
features <- list(
label = tf$FixedLenFeature(shape(), tf$float32),
a = tf$FixedLenFeature(shape(), tf$float32),
b = tf$FixedLenFeature(shape(), tf$float32),
c = tf$FixedLenFeature(shape(), tf$float32),
d = tf$FixedLenFeature(shape(), tf$float32)
)
features <- tf$parse_single_example(example_proto, features)
x <- list(features$a,
features$b,
features$c
features$d
)
y <- tf$one_hot(tf$cast(features$label, tf$int32), 3L)
list(x, y)
}) %>%
dataset_shuffle(150) %>%
dataset_batch(16)只需一个and记录(例如,具有a、b和c特性的file1 ),一切都可以正常工作。
如果我添加第二个带有特征d的tfrecord,使得file2 = c(file1,file2),那么我会得到以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
InvalidArgumentError: Feature: d (data type: float) is required but could not be found.有没有一种用tfrecord_dataset读取多个tfrecord文件的有效方法?
谢谢..!
发布于 2019-08-17 21:25:58
至少在TensorFlow 1.14中,您可以将参数default_value传递给tf$io$FixedLenFeature,该参数将在文件中缺少该列的情况下使用。
从文档中:
示例缺少此功能时使用的
default_value:值。它必须与dtype兼容并且具有指定的形状。https://stackoverflow.com/questions/57534864
复制相似问题