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

DL 7

The document outlines the implementation of the AlexNet architecture using TensorFlow and Keras on the MNIST dataset. It details the data preprocessing, model architecture with convolutional layers, compilation, training, and evaluation, achieving a test accuracy of approximately 98.88%. The model summary indicates a total of 24,733,898 parameters, all of which are trainable.

Uploaded by

mannasubhadip021
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)
3 views3 pages

DL 7

The document outlines the implementation of the AlexNet architecture using TensorFlow and Keras on the MNIST dataset. It details the data preprocessing, model architecture with convolutional layers, compilation, training, and evaluation, achieving a test accuracy of approximately 98.88%. The model summary indicates a total of 24,733,898 parameters, all of which are trainable.

Uploaded by

mannasubhadip021
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

7.

IMPLEMENTATION OF ALEX-NET ARCHITECTURE IN


TENSORFLOW / KERAS.

import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz


11490434/11490434 [==============================] - 0s 0us/step

train_images = train_images.reshape((60000, 28, 28, 1)).astype('float32') / 255


test_images = test_images.reshape((10000, 28, 28, 1)).astype('float32') / 255

train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)

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


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

# Compile the model


model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])

# Train the model


model.fit(train_images, train_labels, epochs=5, batch_size=64, validation_split=0.2)
Epoch 1/5
750/750 [==============================] - 29s 27ms/step - loss: 0.2858 - accuracy: 0.9063
Epoch 2/5
750/750 [==============================] - 18s 24ms/step - loss: 0.0627 - accuracy: 0.9827
Epoch 3/5
750/750 [==============================] - 18s 24ms/step - loss: 0.0482 - accuracy: 0.9867
Epoch 4/5
750/750 [==============================] - 19s 25ms/step - loss: 0.0401 - accuracy: 0.9886
Epoch 5/5
750/750 [==============================] - 18s 24ms/step - loss: 0.0366 - accuracy: 0.9900
<keras.src.callbacks.History at 0x79cd2c74d420>

# Evaluate the model


test_loss, test_acc = model.evaluate(test_images, test_labels)
print('Test accuracy:', test_acc)

313/313 [==============================] - 2s 6ms/step - loss: 0.0511 - accuracy: 0.9888


Test accuracy: 0.9887999892234802

model.summary()

Model: "sequential"

Layer (type) Output Shape Param #


=================================================================
conv2d (Conv2D) (None, 26, 26, 96) 960

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


D)

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

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


g2D)

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

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

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

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


g2D)

flatten (Flatten) (None, 1024) 0

dense (Dense) (None, 4096) 4198400

dense_1 (Dense) (None, 4096) 16781312

dense_2 (Dense) (None, 10) 40970

=================================================================
Total params: 24733898 (94.35 MB)
Trainable params: 24733898 (94.35 MB)
Non-trainable params: 0 (0.00 Byte)

You might also like