【发布时间】:2021-05-25 00:37:18
【问题描述】:
import tensorflow_datasets as tfds
train_ds = tfds.load('cifar100', split='train[:90%]').shuffle(1024).batch(32)
val_ds = tfds.load('cifar100', split='train[-10%:]').shuffle(1024).batch(32)
我想将train_ds 和val_ds 转换成这样的形式:x_train, y_train 和x_val, y_val(x 代表图像,y 代表标签)。
Keras API 使用训练和测试数据拆分(sklearn 中似乎也是这种情况),但我确实不想在这里使用任何测试数据。
我试过这个,但没有用(我明白为什么这不起作用,但我不知道如何将我的训练数据转换为图像和标签):
x_train = train_ds['image']
# TypeError: 'BatchDataset' object is not subscriptable
【问题讨论】:
-
Does this回答你的问题?
-
我尝试了所有建议的解决方案,但我一直遇到这个错误
ValueError: too many values to unpack (expected 2) -
我认为该问题中提出的问题与我在这里的问题不同。
标签: python tensorflow machine-learning