A Start-to-Finish Guide to Building Deep Neural Networks in Keras

Everything from image augmentation to plotting accuracy

Andre Ye
Analytics Vidhya
Published in
5 min readMar 27, 2020

--

Learning deep learning is daunting; so libraries like Keras that make it easy are helpful. In this article, I outline, explain, and provide code for 7 steps in building an image recognition deep convolutional neural network in Keras.

1 | Loading Image Data and Basic Preprocessing

Images will (most of the time) be in a .png or .jpg format. They can be loaded using the cv2 library with image = cv2.imread(file_directory).

The cv2 library has handy exporting from a cv2 image to a numpy array, done through img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB). This will yield an array of dimensions (m, n, 3), where m and n are the dimensions of the image. 3 is representative of the depth, or the amount of red, green, and blue to incorporate for the final pixel color.

Extracting the numerical data from an image.

Finally, the data should be scaled, or put on a scale from between 0 to 1. This improves model performance (mathematically, neural networks operate better on a 0-to-1 scale). This can be done…

--

--