0% found this document useful (0 votes)
6 views3 pages

DL_EX-8

Uploaded by

spoorthiitchanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

DL_EX-8

Uploaded by

spoorthiitchanti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise-8

Module name : Advanced CNN

Exercise: Build AlexNet using Advanced CNN

Introduction
The main content of this exercise will present how the AlexNet Convolutional Neural
Network(CNN) architecture is implemented using TensorFlow and Keras.

Here are some of the key learning objectives from this article:

1. Introduction to neural network implementation with Keras and TensorFlow


2. Data preprocessing with TensorFlow
3. Training visualization with TensorBoard
4. Description of standard machine learning terms and terminologies
5. AlexNet Implementation

AlexNet CNN is probably one of the simplest methods to approach understanding deep learning
concepts and techniques.

AlexNet is not a complicated architecture when it is compared with some state of the art CNN
architectures that have emerged in the more recent years.

AlexNet is simple enough for beginners and intermediate deep learning practitioners to pick up
some good practices on model implementation techniques.

Python Code :
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense,
Dropout

def alexnet_model(input_shape, num_classes):


model = Sequential([
# First Convolutional Layer
Conv2D(96, (11,11), strides=(4,4), activation='relu',
input_shape=input_shape, padding='valid'),
MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='valid'),
# Second Convolutional Layer
Conv2D(256, (5,5), activation='relu', padding='same'),
MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='valid'),

# Third Convolutional Layer


Conv2D(384, (3,3), activation='relu', padding='same'),

# Fourth Convolutional Layer


Conv2D(384, (3,3), activation='relu', padding='same'),

# Fifth Convolutional Layer


Conv2D(256, (3,3), activation='relu', padding='same'),
MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='valid'),

# Flatten the CNN output to feed it into a Fully-Connected Dense


Layer
Flatten(),

# First Dense Layer


Dense(4096, activation='relu'),

# Add a Dropout layer to reduce overfitting


Dropout(0.5),

# Second Dense Layer


Dense(4096, activation='relu'),

# Add another Dropout layer


Dropout(0.5),

# Output Layer
Dense(num_classes, activation='softmax')
])

return model

# Define the input shape and number of classes


input_shape = (227, 227, 3) # Adjust input shape if necessary
num_classes = 1000 # Number of ImageNet classes

# Create an instance of the model


model = alexnet_model(input_shape, num_classes)

# Print the model summary


model.summary()
Output :
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 55, 55, 96) 34944

max_pooling2d (MaxPooling2 (None, 27, 27, 96) 0


D)

conv2d_1 (Conv2D) (None, 27, 27, 256) 614656

max_pooling2d_1 (MaxPoolin (None, 13, 13, 256) 0


g2D)

conv2d_2 (Conv2D) (None, 13, 13, 384) 885120

conv2d_3 (Conv2D) (None, 13, 13, 384) 1327488

conv2d_4 (Conv2D) (None, 13, 13, 256) 884992

max_pooling2d_2 (MaxPoolin (None, 6, 6, 256) 0


g2D)

flatten (Flatten) (None, 9216) 0

dense (Dense) (None, 4096) 37752832

dropout (Dropout) (None, 4096) 0

dense_1 (Dense) (None, 4096) 16781312

dropout_1 (Dropout) (None, 4096) 0

dense_2 (Dense) (None, 1000) 4097000

=================================================================
Total params: 62378344 (237.95 MB)
Trainable params: 62378344 (237.95 MB)
Non-trainable params: 0 (0.00 Byte)

You might also like