【发布时间】:2021-05-13 15:17:01
【问题描述】:
我有一个名为 train_ds 的 tf 数据集:
directory = 'Data/dataset_train'
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
directory,
validation_split=0.2,
subset="training",
color_mode='grayscale',
seed=123,
image_size=(28, 28),
batch_size=32)
这个数据集由 20000 张“假”图像和 20000 张“真实”图像组成,我想从这个 tf 数据集中以 numpy 形式提取 X_train 和 y_train,但我只设法用
y_train = np.concatenate([y for x, y in train_ds], axis=0)
我也试过这个,但它似乎没有遍历 20000 张图像:
for images, labels in train_ds.take(-1):
X_train = images.numpy()
y_train = labels.numpy()
我真的想将图像提取到 X_train 并将标签提取到 y_train 但我想不通! 对于我所犯的任何错误,我提前道歉,并感谢我能得到的所有帮助:)
【问题讨论】:
标签: python tensorflow tensorflow-datasets