Impact of Image Flattening
Flattening is a technique that is used to convert multi-dimensional arrays into a 1-D array, it is generally used in Deep Learning while feeding the 1-D array information to the classification model.
What is the need for Flattening of an Image?
Multi-Dimensional arrays take more amount of memory while 1-D arrays take less memory, which is the most important reason why we flatten the Image Array before processing/feeding the information to our model. In most cases, we will be dealing with a dataset which contains a large amount of images thus flattening helps in decreasing the memory as well as reducing the time to train the model.
Step 1: Importing the necessary libraries
Step 2: Fetching a random image through web
Step 3: Transforming the image into a multi-dimensional array
Step 4: Now Flattening the multi-dimensional array using flatten() function
Step5: Results of Flattening
Size of Multidimensional Image : 1324928 Size of Flattened Image : 1324896 Size difference in the images: 32
Step 6: Full Code
After running the whole code we see that there is not a major difference in memory used in the multi-dimensional image array and the flattened array. Then people may ask why we are doing the flattening when the effect is negligible. In a large datasets when we are dealing with thousands of images the net amount of the memory saved due to all the images accumulates to be pretty big.
Attention reader! Don’t stop learning now. Get hold of all the important Machine Learning Concepts with the Machine Learning Foundation Course at a student-friendly price and become industry ready.