Evaluating ANN and CNN on CIFAR-10: A Complete Evaluation | by Ravjot Singh | Jul, 2024

[ad_1]

Are you interested by how completely different neural networks stack up towards one another? On this weblog, we dive into an thrilling comparability between Synthetic Neural Networks (ANN) and Convolutional Neural Networks (CNN) utilizing the favored CIFAR-10 dataset. We’ll break down the important thing ideas, architectural variations, and real-world functions of ANNs and CNNs. Be a part of us as we uncover which mannequin reigns supreme for picture classification duties and why. Let’s get began!

Dataset Overview

The CIFAR-10 dataset is a widely-used dataset for machine studying and laptop imaginative and prescient duties. It consists of 60,000 32×32 colour photos in 10 completely different lessons, with 50,000 coaching photos and 10,000 take a look at photos. The lessons are airplanes, automobiles, birds, cats, deer, canines, frogs, horses, ships, and vans. This weblog explores the efficiency of Synthetic Neural Networks (ANN) and Convolutional Neural Networks (CNN) on the CIFAR-10 dataset.

Pattern dataset

What’s ANN?

Synthetic Neural Networks (ANN) are computational fashions impressed by the human mind. They encompass interconnected teams of synthetic neurons (nodes) that course of info utilizing a connectionist method. ANNs are used for quite a lot of duties, together with classification, regression, and sample recognition.

Rules of ANN

  • Layers: ANNs encompass enter, hidden, and output layers.
  • Neurons: Every layer has a number of neurons that course of inputs and produce outputs.
  • Activation Features: Features like ReLU or Sigmoid introduce non-linearity, enabling the community to be taught complicated patterns.
  • Backpropagation: The training course of entails adjusting weights based mostly on the error gradient.

ANN Structure

ANN = fashions.Sequential([
layers.Flatten(input_shape=(32, 32, 3)),
layers.Dense(3000, activation='relu'),
layers.Dense(1000, activation='relu'),
layers.Dense(10, activation='sigmoid')
])
ANN.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'

What is CNN?

Convolutional Neural Networks (CNN) are specialized ANNs designed for processing structured grid data, like images. They are particularly effective for tasks involving spatial hierarchies, such as image classification and object detection.

Principles of CNN

  • Convolutional Layers: These layers apply convolutional filters to the input to extract features.
  • Pooling Layers: Pooling layers reduce the spatial dimensions, retaining important information while reducing computational load.
  • Fully Connected Layers: After convolutional and pooling layers, fully connected layers are used to make final predictions.

CNN Architecture

CNN = models.Sequential([
layers.Conv2D(input_shape=(32, 32, 3), filters=32, kernel_size=(3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Flatten(),
layers.Dense(2000, activation='relu'),
layers.Dense(1000, activation='relu'),
layers.Dense(10, activation='softmax')
])
CNN.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

Coaching and Analysis

Each fashions had been skilled for 10 epochs on the CIFAR-10 dataset. The ANN mannequin makes use of dense layers and is easier, whereas the CNN mannequin makes use of convolutional and pooling layers, making it extra complicated and appropriate for picture information.

ANN.match(X_train, y_train, epochs=10)
ANN.consider(X_test, y_test)

CNN.match(X_train, y_train, epochs=10)
CNN.consider(X_test, y_test)

Coaching ANN Mannequin
Coaching CNN Mannequin

Outcomes Comparability

The analysis outcomes for each fashions present the accuracy and loss on the take a look at information.

ANN Analysis

  • Accuracy: 0.4960
  • Loss: 1.4678
Check Knowledge Analysis for ANN Mannequin

CNN Analysis

  • Accuracy: 0.7032
  • Loss: 0.8321
Check Knowledge Analysis for CNN Mannequin

The CNN considerably outperforms the ANN when it comes to accuracy and loss.

Confusion Matrices and Classification Reviews

To additional analyze the fashions’ efficiency, confusion matrices and classification experiences had been generated.

ANN Confusion Matrix and Report

y_pred_ann = ANN.predict(X_test)
y_pred_labels_ann = [np.argmax(i) for i in y_pred_ann]
plot_confusion_matrix(y_test, y_pred_labels_ann, "Confusion Matrix for ANN")
print("Classification Report for ANN:")
print(classification_report(y_test, y_pred_labels_ann))

CNN Confusion Matrix and Report

y_pred_cnn = CNN.predict(X_test)
y_pred_labels_cnn = [np.argmax(i) for i in y_pred_cnn]
plot_confusion_matrix(y_test, y_pred_labels_cnn, "Confusion Matrix for CNN")
print("Classification Report for CNN:")
print(classification_report(y_test, y_pred_labels_cnn))

Conclusion

The CNN mannequin outperforms the ANN mannequin on the CIFAR-10 dataset as a result of its potential to seize spatial hierarchies and native patterns within the picture information. Whereas ANNs are highly effective for normal duties, CNNs are particularly designed for image-related duties, making them simpler for this software.

In abstract, for picture classification duties like these within the CIFAR-10 dataset, CNNs supply a big efficiency benefit over ANNs as a result of their specialised structure tailor-made for processing visible information.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *