Image classification using the SVM with data augmentation on the MNIST dataset
Let us see how we can apply data augmentation for image classification using an SVM with the MNIST dataset. All the steps are similar to the previous example with the CIFAR-10 dataset, except the dataset itself:
import tensorflow as tf from sklearn.svm import SVC from sklearn.model_selection import GridSearchCV from keras.datasets import mnist from keras.preprocessing.image import ImageDataGenerator # load MNIST dataset (x_train, y_train), (x_test, y_test) = mnist.load_data() # normalize pixel values between 0 and 1 x_train = x_train / 255.0 x_test = x_test / 255.0 # convert labels to one-hot encoded vectors y_train = tf.keras.utils.to_categorical(y_train) y_test = tf.keras.utils.to_categorical(y_test) # create image data generator for data augmentation datagen = ImageDataGenerator(rotation_range=20, \ Â Â Â Â width_shift_range=0.1, height_shift_range=0.1, zoom_range=0.2) # fit image data...