Skip to content
Snippets Groups Projects
user avatar
selalimi authored
48ec7d69
History

Image Classification Project

This project aims to implement an image classification program using two successive models: k-nearest neighbors (KNN) and artificial neural networks (ANN).

CIFAR-10 Dataset

The CIFAR-10 dataset is a commonly used database in computer vision for image classification. It consists of 60,000 color images of 32x32 pixels, distributed across 10 distinct classes, representing different objects or animals.

CIFAR-10 Dataset Classes:

  1. airplane
  2. automobile
  3. bird
  4. cat
  5. deer
  6. dog
  7. frog
  8. horse
  9. ship
  10. truck

Accomplished Steps

CIFAR Database Preparation

Database Download:

The CIFAR-10 database was downloaded from Dataset_Cifar-10.

Creating the data Folder:

A folder named data was created to store the CIFAR-10 database files.

Writing the read_cifar.py Script:

A Python file named read_cifar.py was created, including the following functions:

  • read_cifar_batch
  • read_cifar
  • split_dataset

Implementation of k-nearest neighbors (KNN)

Writing the knn.py Script:

A Python file named knn.py was created, including the following functions:

  • distance_matrix
  • knn_predict
  • evaluate_knn
  • plot_KNN

Performance Study

The effectiveness of the KNN algorithm was evaluated based on the number of neighbors (k) for split_factor=0.9.

Running the Code

To execute the models, follow these steps in the terminal:

Ensure requirements are installed before running KNN or MLP

pip install -r requirements.txt

  1. KNN Model:

python knn.py

  1. MLP Model:

python mlp.py

Results

Generating the Graph

  1. Results using KNN:

A graph showing the accuracy variation with k was generated using matplotlib and saved as "knn.png" in the "Results" folder.

Semantic description of image

  1. Results using ANN :

A graph showing the accuracy variation with the number of epochs was generated using matplotlib and saved as "mlp.png" in the "Results" folder.

Semantic description of image

Analysis of KNN Results

Unfortunately, the performance of the KNN algorithm was disappointing, with accuracy ranging between 33% and 34% for different values of k (up to k=20). Several reasons may explain these mixed results:

  1. High Dimensionality of Data: CIFAR-10 dataset images are 32x32 pixels, resulting in high-dimensional data. This can make Euclidean distance less discriminative, affecting KNN's performance.

  2. Scale Sensitivity: KNN is sensitive to different feature scales. Pixels in an image can have different values, and KNN may be influenced by these disparities.

  3. Choice of k: The choice of the number of neighbors (k) can significantly influence results. An inappropriate k value can lead to underestimation or overestimation of the model's complexity.

  4. Lack of Feature Abstraction: KNN directly uses pixels as features. More advanced feature extraction techniques could improve performance

Analysis of ANN Results

The deep learning algorithm (ANN) used for our dataset has relatively low performance, with test set accuracy plateauing around 14% over 100 epochs.

These results suggest that adjustments to certain aspects of the model, such as complexity, hyperparameters, or weight initialization, may be necessary to improve its ability to generalize to new data. Further exploration of these aspects could be beneficial in optimizing model performance.

Conculsion

The best accuracy is achieved with the KNN model, reaching 34%. However, it could be further improved by using Convolutional Neural Networks (CNN) instead of Artificial Neural Networks (ANN). CNNs are particularly recognized for their effectiveness in image recognition, analysis, and classification of images and videos.

Author

Sara EL ALIMI.

Licence

Ce projet est sous licence MIT.