I have been working on a project involving CNN and its weights and I have been trying to reduce the number of weights present in the CNN. I want to resize the MNIST images from 28x28 into 14x14 before training the CNN but I have no idea how to do it in Keras.
Here is a sample of the code used in importing the MNIST dataset and building the CNN:
# LOAD MNIST DATA
(X_train, y_train), (X_test, y_test) = mnist.load_data()
# RESHAPE TO [SAMPLES][PIXELS][WIDTH][HEIGHT]
X_train = X_train.reshape(X_train.shape[0], 1, 28, 28).astype('float32')
X_test = X_test.reshape(X_test.shape[0], 1, 28, 28).astype('float32')
# NORMALIZE 0-255 TO 0-1
X_train = X_train / 255
X_test = X_test / 255
# ONE HOT ENCODE
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]
#DEFINE MODEL
def larger_model():
# CREATE MODEL
model = Sequential()
model.add(Conv2D(2, (5, 5), input_shape=(1, 28, 28), activation='relu',
padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(2, (5, 5), activation='relu', padding="same"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(16, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
# COMPILE MODEL
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=
['accuracy'])
return model
# BUILD MODEL
model = larger_model()
model.summary()
The X_train variable is the one used in the training of the model. What adjustments should I make to reduce the size of the X_train into 14x14 before the training starts?
Thank you!