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

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


Are you interested in how completely different neural networks stack up in opposition to 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 purposes 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 shade photos in 10 completely different lessons, with 50,000 coaching photos and 10,000 check photos. The lessons are airplanes, vehicles, 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 data utilizing a connectionist strategy. ANNs are used for quite a lot of duties, together with classification, regression, and sample recognition.

Ideas 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 study advanced patterns.
  • Backpropagation: The educational course of entails adjusting weights primarily based 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 less complicated, whereas the CNN mannequin makes use of convolutional and pooling layers, making it extra advanced and appropriate for picture knowledge.

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 check knowledge.

ANN Analysis

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

CNN Analysis

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

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

Confusion Matrices and Classification Studies

To additional analyze the fashions’ efficiency, confusion matrices and classification stories 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 consequence of its capability to seize spatial hierarchies and native patterns within the picture knowledge. Whereas ANNs are highly effective for normal duties, CNNs are particularly designed for image-related duties, making them more practical 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 consequence of their specialised structure tailor-made for processing visible knowledge.