Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Alexnet

DR. DEEPAK MEHTA


Basic Intuition
Input Image Size: 227X227X3
Conv1: 11X11, Stride:4, No. of Filters: 96  55X55X96
Maxpooling: Kernel: 3X3, Stride:2 27X27X96
Conv2: 5X5, Stride:1, No. of Filters:256,padding: 2 27X27X256
Maxpooling: 3X3, Stride:2 13X13X256
Conv3: 3X3, pad:1, no. of filters: 384,padding:1 13X13X384
Conv4: 3X3, pad:1, no. of filters:384, padding:1 13X13X384
Conv5: 3X3,pad:1, no. of fiters: 256 13X13X256
Maxpooling: 3X3, Stride:26X6X256 FCFC
Import Libraries
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, BatchNormalization,
Dropout
Model Implementation
model = Sequential()
# Layer 1: Convolutional Layer
model.add(Conv2D(96, (11, 11), strides=(4, 4), input_shape=(227, 227, 3), activation='relu'))
# Layer 2: Max Pooling
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
# Layer 3: Convolutional Layer
model.add(Conv2D(256, (5, 5), padding='same', activation='relu'))
# Layer 4: Max Pooling
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
# Layer 5: Convolutional Layer
model.add(Conv2D(384, (3, 3), padding='same', activation='relu'))
# Layer 6: Convolutional Layer
model.add(Conv2D(384, (3, 3), padding='same', activation='relu'))
# Layer 7: Convolutional Layer
model.add(Conv2D(256, (3, 3), padding='same', activation='relu'))
# Layer 8: Max Pooling
model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2))
# Layer 9: Flatten
model.add(Flatten())
# Layer 10: Fully Connected Layer
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
# Layer 11: Fully Connected Layer
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
# Layer 12: Output Layer
model.add(Dense(1000, activation='softmax')) # 1000 classes in the ImageNet dataset
# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Print the model summary
model.summary()
Model Training
(x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
datagen = ImageDataGenerator(
rotation_range=15,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=True,
zoom_range=0.2,
)
datagen.fit(x_train)
model.fit(datagen.flow(x_train, y_train, batch_size=32), steps_per_epoch=len(x_train) / 32,
epochs=10, validation_data=(x_test, y_test))
test_loss, test_accuracy = model.evaluate(x_test, y_test, verbose=2)
print(f"Test accuracy: {test_accuracy*100:.2f}%")
print(f"Test loss: {test_loss:.4f}")
Thanks
Deepak.e11296@cumail.in
9812881611

You might also like