A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/machine-learning/ml-getting-started-with-alexnet/ below:

ML | Getting Started With AlexNet

ML | Getting Started With AlexNet

Last Updated : 12 Jul, 2025

AlexNet is a deep learning model that made a big impact in image recognition. It became famous for its ability to classify images accurately. It won the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) 2012 with a top-5 error rate of 15.3% (beating the runner up which had a top-5 error rate of 26.2%).

Most important features of the AlexNet are:

AlexNet Architecture

Its architecture includes:

Implementation of AlexNet for Object Classification

Here we will see step by step implementation of alexnet model:

1. Import Libraries

We import tensorflow and matplotlib for it.

Python
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Activation, Dropout, BatchNormalization
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.utils import to_categorical
import matplotlib.pyplot as plt
2. Load and Preprocess CIFAR-10 Dataset Python
# Load CIFAR-10 data
(x_train, y_train), (x_test, y_test) = cifar10.load_data()

# Normalize pixel values
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0

# One-hot encode the labels
y_train = to_categorical(y_train, 10)
y_test = to_categorical(y_test, 10)
3. Define the AlexNet Model (Adjusted for CIFAR-10) Python
model = Sequential()

# Layer 1
model.add(Conv2D(96, kernel_size=(3,3), strides=(1,1), input_shape=(32,32,3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
model.add(BatchNormalization())

# Layer 2
model.add(Conv2D(256, kernel_size=(3,3), strides=(1,1), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
model.add(BatchNormalization())

# Layer 3
model.add(Conv2D(384, kernel_size=(3,3), strides=(1,1), padding='same'))
model.add(Activation('relu'))

# Layer 4
model.add(Conv2D(384, kernel_size=(3,3), strides=(1,1), padding='same'))
model.add(Activation('relu'))

# Layer 5
model.add(Conv2D(256, kernel_size=(3,3), strides=(1,1), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))

# Flatten
model.add(Flatten())

# Fully Connected Layer 1
model.add(Dense(1024))
model.add(Activation('relu'))
model.add(Dropout(0.5))

# Fully Connected Layer 2
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))

# Output Layer
model.add(Dense(10))
model.add(Activation('softmax'))
4. Compile the Model

We use adam optimizer and categorical_crossentropy for multi-class classification.

Python
model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
5. Train the Model Python
history = model.fit(x_train, y_train,
                    batch_size=128,
                    epochs=15,
                    validation_split=0.2,
                    verbose=1)

Output:

Training 6. Evaluate the Model Python
test_loss, test_acc = model.evaluate(x_test, y_test, verbose=0)
print(f'Test Accuracy: {test_acc:.4f}')

Output:

Test Accuracy: 0.7387

7. Plot Training & Validation Accuracy Python
plt.plot(history.history['accuracy'], label='Train Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.title('AlexNet on CIFAR-10 (GPU)')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.grid(True)
plt.show()

Output:

AlexNet on CIFAR-10

We can see that train and validation accuracy is quit similar in end meaning our model is working fine.

Advantages of AlexNet Disadvantages of AlexNet Applications
  1. Image Classification: Originally built for classifying high-resolution images into 1000 object categories (ImageNet dataset).
  2. Feature Extraction: Intermediate layers are often used as pretrained feature extractors for transfer learning tasks.
  3. Object Detection: Forms the backbone in early detection systems like R-CNN when combined with region proposal methods.
  4. Medical Imaging: Applied to classify abnormalities in X-rays, MRIs or retinal scans by fine-tuning on domain-specific datasets.
  5. Facial Recognition and Emotion Detection: Can be adapted for face verification, expression analysis or identity recognition tasks.
  6. Autonomous Vehicles: Used in early perception modules for identifying road signs, pedestrians or obstacles.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4