【发布时间】:2021-04-23 06:37:45
【问题描述】:
我从头开始为我的 tensorflow 模型创建了一个数据集。我正在使用 TensorFlow 2.4.0。为了加速,我决定将数据存储在 .tfrecord 文件类型中,现在我想检查它是否存储在 .tfrecord 文件中。 我编写了一个代码来在 .tfrecord 文件中打印一个图像,但出现以下错误:
imageRaw = imageFeautre['image/width'].numpy()
TypeError: 'TakeDataset' object is not subscriptable
我将自己定位在官方的 tensorflow 教程 (https://www.tensorflow.org/tutorials/load_data/tfrecord#write_the_tfrecord_file)
我可以加载数据集并读取它,内容是正确的。我无法在其中打印一张图片,我只想在其中打印一张图片我在网上找不到解决方案。
这是我的代码:
import tensorflow as tf
import numpy as np
import IPython.display as display
tf.compat.v1.enable_eager_execution()
tfrecordPath='/home/adem/PycharmProjects/dcganAlgorithmus/dataHandler/preparedData/train.tfrecord'
rfrecordDataSet=tf.data.TFRecordDataset(tfrecordPath)
imageFeatureDescription ={
'image/width:':tf.io.FixedLenFeature([],tf.int64),
'image/height':tf.io.FixedLenFeature([], tf.int64),
'image/xmin':tf.io.FixedLenFeature([], tf.int64),
'image/ymin':tf.io.FixedLenFeature([],tf.int64),
'image/xmax':tf.io.FixedLenFeature([],tf.int64),
'image/ymin':tf.io.FixedLenFeature([],tf.int64),
}
def _parse_image_function(example_proto):
# Parse the input tf.train.Example proto using the dictionary above.
return tf.io.parse_single_example(example_proto, imageFeatureDescription)
ParsedImageDataset = rfrecordDataSet.map(_parse_image_function)
imageFeautre=ParsedImageDataset.take(1)
imageRaw = imageFeautre['image/width'].numpy()
display.display(display.Image(data=imageRaw))
【问题讨论】:
标签: python tensorflow tensorflow2.0 tensorflow-datasets