How to resize MNIST images to fit AlexNet model

I am using the keras API to load in the MNIST dataset. My problem is I need to use AlexNet as my algorithm. Understanding the AlexNet model, I require to start with 277x277 images but the MINST dataset has 28x28. How can I reshape the numpy array so that each image is 227x277 to then use the full AlexNet model?

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

This is how I load my data in. Could someone show me the solution to change the initial images to match the AlexNet model?

Topic alex-net keras deep-learning dataset machine-learning

Category Data Science


You can use tf.image.resize, as follows:

(x_train, y_train), (_, _) = tf.keras.datasets.mnist.load_data()

print(x_trian.shape) # (60000, 28, 28)

# train set / data 
x_train = np.expand_dims(x_train, axis=-1)
x_train = tf.image.resize(x_train, [32,32]) # if we want to resize 

print(x_train.shape) # (60000, 32, 32, 1)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.