我正在编写 Python/tensorflow/mnist 教程。
自从使用来自 tensorflow 网站的原始代码几周以来,我收到警告说图像数据集很快就会被弃用,我应该使用以下数据集: https://github.com/tensorflow/models/blob/master/official/mnist/dataset.py
我使用我的代码加载它:
from tensorflow.models.official.mnist import dataset
trainfile = dataset.train(data_dir)
哪个返回:
tf.data.Dataset.zip((images, labels))
问题是我找不到以下列方式将它们分开的方法,例如:
trainfile = dataset.train(data_dir)
train_data= trainfile.images
train_label= trainfile.label
但这显然不起作用,因为属性图像和标签不存在。 trainfile 是一个 tf.dataset。
知道 tf.dataset 是由 int32 和 float32 组成的我尝试过:
train_data = trainfile.map(lambda x,y : x.dtype == tf.float32)
但它返回并清空了数据集。
我坚持(但会公开)这样做(两批完整的图像和标签),因为这就是教程的工作方式:
https://www.tensorflow.org/tutorials/estimators/cnn
我看到了很多从数据集中获取元素的解决方案,但没有什么可以从以下代码中完成的 zip 操作返回
tf.data.Dataset.zip((images, labels))
预先感谢您的帮助。
最佳答案
希望对您有所帮助:
inputs = tf.placeholder(tf.float32, shape=(None, 784), name='inputs')
outputs = tf.placeholder(tf.float32, shape=(None,), name='outputs')
#Prepare a tensorflow dataset
ds = tf.data.Dataset.from_tensor_slices((x_train, y_train))
ds = ds.shuffle(buffer_size=10, reshuffle_each_iteration=True).batch(batch_size=batch_size, drop_remainder=True).repeat()
iter = ds.make_one_shot_iterator()
next = iter.get_next()
inputs = next[0]
outputs = next[1]
关于python - 如何从 tf.data.Dataset.zip((images, labels)) 获取两个 tf.dataset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52918090/