您使用的格式基本上不正确,keras 数据集的返回格式为带有图像的单独数据标签
这段代码对我有用
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
print(tf.__version__)
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
print(train_images.shape)
print(test_images.shape)
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import np_utils
y_train = np_utils.to_categorical(train_labels, 10)
y_test = np_utils.to_categorical(test_labels,10)
datagen = ImageDataGenerator(
featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
train_images=train_images.reshape(60000,28,28,1)
test_images=test_images.reshape(10000,28,28,1)
datagen.fit(train_images)
准备你的模型和编译
# fits the model on batches with real-time data augmentation:
model.fit_generator(datagen.flow(train_images,train_labels, batch_size=32),
steps_per_epoch=len(x_train) / 32, epochs=epochs)