18.4 C
New York
Monday, March 10, 2025

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 functions of ANNs and CNNs. Be 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 pictures in 10 completely different courses, with 50,000 coaching pictures and 10,000 take a look at pictures. The courses are airplanes, vehicles, birds, cats, deer, canine, frogs, horses, ships, and vehicles. 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 include interconnected teams of synthetic neurons (nodes) that course of info 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 include 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 advanced patterns.
  • Backpropagation: The educational course of includes 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 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 take a look at knowledge.

ANN Analysis

  • Accuracy: 0.4960
  • Loss: 1.4678
Take a look at Knowledge Analysis for ANN Mannequin

CNN Analysis

  • Accuracy: 0.7032
  • Loss: 0.8321
Take a look at Knowledge 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 reviews 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 on account of its capacity to seize spatial hierarchies and native patterns within the picture knowledge. Whereas ANNs are highly effective for common duties, CNNs are particularly designed for image-related duties, making them simpler for this utility.

In abstract, for picture classification duties like these within the CIFAR-10 dataset, CNNs provide a big efficiency benefit over ANNs on account of their specialised structure tailor-made for processing visible knowledge.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles