【发布时间】:2019-03-28 13:40:35
【问题描述】:
我写了一个 tfrecord 文件,其中我有图像和它们的标签。然后我可以使用它们来获取它们
def parserTrain(record):
keys_to_features = {
"image_raw": tf.FixedLenFeature((), tf.string, default_value=""),
"label": tf.FixedLenFeature((), tf.int64,
default_value=tf.zeros([], dtype=tf.int64)),
}
parsed = tf.parse_single_example(record, keys_to_features)
# Perform additional preprocessing on the parsed data.
image = tf.image.decode_jpeg(parsed["image_raw"])
image = tf.reshape(image, [256, 256, 3])
image = tf.transpose(image, perm=[2, 0, 1]) # channels first
image = tf.truediv(image, 255.0)
label = tf.cast(parsed["label"], tf.int32)
return {"image": image}, label
# Set up training input function.
def train_input_fn():
"""Prepare data for training."""
train_tfrecord = 'Dataset/train_images.tfrecords'
dataset = tf.data.TFRecordDataset(train_tfrecord)
dataset = dataset.map(parserTrain)
之后,我想过滤掉一些例子,可能是这样的:
def f(x):
return x[1] == 1
ds1 = dataset.filter(f)
但我收到此错误:
TypeError: f() 接受 1 个位置参数,但给出了 2 个
【问题讨论】:
标签: python-3.x tensorflow tensorflow-datasets tfrecord