當預測新的圖片,但預測錯誤時,例如下圖的數字7,卻預測成1
我們常用的方法Data Augmentation,把這張圖片利用ImageDataGenerator,放大、縮小、旋轉、平移等等,從一張圖片變成更多張圖片,並且標籤是正確答案7
然後加入訓練集後一起訓練
y_image_real = np_utils.to_categorical(np.array([[7]]), num_classes=10)
x_images = x_image.repeat(10, axis=0)
y_image_reals = y_image_real.repeat(10, axis=0)
datagen = ImageDataGenerator(rotation_range=45)
aug_data = datagen.flow(x_images, y_image_reals, batch_size=10, shuffle = False)
x_batch, y_batch = aug_data[0]
x_train = np.vstack([x_train, x_batch])
y_train = np.vstack([y_train, y_batch])
model.fit(x_train, y_train, epochs=1, batch_size=64)
用新的模型再預測一次,答對了!