ML Lab Session 05 - CNN Implementation
ML Lab Session 05 - CNN Implementation
Faculty of Technology
Department of Information and Communication Technology
ITC2252_ Introduction to Machine Learning
● import numpy as np: This imports the NumPy library for numerical computations and array
operations. It's given the shorthand alias np for easier use.
● import random: This imports the random library for generating random numbers.
● import matplotlib.pyplot as plt: This imports the Matplotlib library for creating visualizations
and plots. It's given the alias plt.
● from tensorflow.keras.models import Sequential: This imports the Sequential model class from
the TensorFlow Keras library, which is used for building neural networks.
● from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten: This imports
several layers commonly used in convolutional neural networks (CNNs) from TensorFlow Keras:
1. Conv2D: Convolutional layer for extracting features from images.
2. MaxPooling2D: Downsampling layer for reducing dimensionality.
3. Dense: Fully connected layer for final classification or regression.
4. Flatten: Layer for reshaping multidimensional data into a single vector.
2.
● ImageDataGenerator is a class in Keras that helps generate augmented images for training neural
networks.
● rescale=1./255: Scales the pixel values of the images to be between 0 and 1. This is a standard
preprocessing step for neural networks.
● shear_range=0.2: Introduces shearing transformations, which slant the image in a specified
direction.
● zoom_range=0.2: Applies random zooming to the images.
● horizontal_flip=True: Allows horizontal flipping of the images.
3.
5.
6.