Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image-Classification-using-Convolutional-Neural-Networks #811

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Datasets/CIFAR-10 Dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## CIFAR-10 Dataset

### Overview
The CIFAR-10 dataset is a collection of images commonly used for training machine learning and computer vision algorithms. It consists of 60,000 32x32 color images in 10 different classes, with 6,000 images per class. The dataset is divided into 50,000 training images and 10,000 test images.

### Classes
The 10 classes in the CIFAR-10 dataset are:
1. Airplane
2. Automobile
3. Bird
4. Cat
5. Deer
6. Dog
7. Frog
8. Horse
9. Ship
10. Truck

### Files
- `data_batch_1.bin` to `data_batch_5.bin`: Training data batches.
- `test_batch.bin`: Test data batch.
- `batches.meta.txt`: Contains label names.

### Download
The CIFAR-10 dataset can be downloaded from the following URL: [CIFAR-10 Dataset](https://www.cs.toronto.edu/~kriz/cifar.html)

### References
- [CIFAR-10 Dataset Page](https://www.cs.toronto.edu/~kriz/cifar.html)
- Krizhevsky, A., & Hinton, G. (2009). Learning multiple layers of features from tiny images.
17 changes: 17 additions & 0 deletions Datasets/MNIST_Dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## MNIST Dataset

### Overview
The MNIST dataset is a large collection of handwritten digits commonly used for training various image processing systems. It contains 70,000 grayscale images of handwritten digits, each 28x28 pixels in size, divided into a training set of 60,000 images and a test set of 10,000 images.

### Files
- `train-images-idx3-ubyte.gz`: Training set images.
- `train-labels-idx1-ubyte.gz`: Training set labels.
- `t10k-images-idx3-ubyte.gz`: Test set images.
- `t10k-labels-idx1-ubyte.gz`: Test set labels.

### Download
The MNIST dataset can be downloaded from the following URL: [MNIST Dataset](http://yann.lecun.com/exdb/mnist/)

### References
- [MNIST Dataset Page](http://yann.lecun.com/exdb/mnist/)
- LeCun, Y., Bottou, L., Bengio, Y., & Haffner, P. (1998). Gradient-based learning applied to document recognition. Proceedings of the IEEE.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/EDA/MNIST/Class Comparison for MNIST.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/EDA/MNIST/Class Histogram for MNIST.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/EDA/MNIST/PCA Visualization for MNIST.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/EDA/MNIST/UMAP Visualization for MNIST.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/CIFAR-10/LeNet5_Model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/CIFAR-10/MobileNet_Model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/CIFAR-10/ResNet50_Model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/CIFAR-10/Simple_CNN_Model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/CIFAR-10/VGG16_Model.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Models/MNIST/LeNet5_Model.jpg
Binary file added Images/Models/MNIST/MobileNet_Model.jpg
Binary file added Images/Models/MNIST/ResNet50_Model.jpg
Binary file added Images/Models/MNIST/Simple_CNN_Model.jpg
Binary file added Images/Models/MNIST/VGG16_Model.jpg
674 changes: 674 additions & 0 deletions Models/EDA.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Models/LeNet5_Model/LeNet5_Model.ipynb

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions Models/LeNet5_Model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# 🖼️ LeNet-5 Model for Image Classification

## 📝 Overview
This project implements a LeNet-5 Convolutional Neural Network (CNN) for image classification using the CIFAR-10 and MNIST datasets. The notebook `LeNet5_model.ipynb` contains the entire workflow from data loading and preprocessing to model training, evaluation, and visualization.

## ⚙️ Installation
To run this project, you'll need to install the required libraries. You can do this by running:

```bash
pip install -r requirements.txt
```

## 🚀 Usage

1. **Clone the repository**:
```bash
git clone https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks.git
cd Image-Classification-using-Convolutional-Neural-Networks/Models/LeNet5_Model/
```

2. **Install the required packages**:
```bash
pip install -r requirements.txt
```

3. **Run the Jupyter Notebook**:
```bash
jupyter notebook LeNet5_model.ipynb
```

## 📦 Dataset

### CIFAR-10
- **Description**: The CIFAR-10 dataset consists of 60,000 32x32 color images in 10 different classes.
- **Classes**: 🛩️ Airplane, 🚗 Automobile, 🐦 Bird, 🐱 Cat, 🦌 Deer, 🐶 Dog, 🐸 Frog, 🐴 Horse, 🚢 Ship, 🚚 Truck.

### MNIST
- **Description**: The MNIST dataset consists of 70,000 28x28 grayscale images of handwritten digits.
- **Classes**: Digits 0 through 9.

## 🏗️ Model Architecture

The LeNet-5 model for CIFAR-10 and MNIST has the following architecture:

```python
def create_lenet5(input_shape, num_classes):
model = tf.keras.Sequential([
Conv2D(6, kernel_size=(5, 5), activation='relu', input_shape=input_shape),
MaxPooling2D(pool_size=(2, 2)),
Conv2D(16, kernel_size=(5, 5), activation='relu'),
MaxPooling2D(pool_size=(2, 2)),
Flatten(),
Dense(120, activation='relu'),
Dense(84, activation='relu'),
Dense(num_classes, activation='softmax')
])
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model
```

## 📝 Steps

### 1. Data Loading and Preprocessing
- Load the CIFAR-10 and MNIST datasets.
- Normalize the pixel values to the range [0, 1].
- Convert class labels to categorical format.

### 2. Model Training
- Train the LeNet-5 model on both CIFAR-10 and MNIST datasets.
- Record the training and validation accuracy and loss over epochs.

### 3. Model Evaluation
- Evaluate the trained model on the test data.
- Calculate accuracy and precision.
- Generate a detailed classification report.

### 4. Visualization
- Plot training and validation accuracy and loss for each epoch.
- Display class distribution and exploratory data analysis (EDA) plots.

## 📊 Results

### CIFAR-10
- **Accuracy**: Achieved accuracy on the CIFAR-10 test set - `0.5802000000`
- **Precision**: Achieved precision on the CIFAR-10 test set - `0.5827235484`
- **Classification Report**: Detailed classification report for CIFAR-10.

| Class | Precision | Recall | F1-Score | Support |
|-------------|-----------|--------|----------|---------|
| Airplane | 0.71 | 0.58 | 0.64 | 1000 |
| Automobile | 0.57 | 0.83 | 0.68 | 1000 |
| Bird | 0.51 | 0.41 | 0.45 | 1000 |
| Cat | 0.49 | 0.25 | 0.34 | 1000 |
| Deer | 0.65 | 0.37 | 0.48 | 1000 |
| Dog | 0.50 | 0.51 | 0.51 | 1000 |
| Frog | 0.55 | 0.76 | 0.64 | 1000 |
| Horse | 0.57 | 0.73 | 0.64 | 1000 |
| Ship | 0.72 | 0.70 | 0.71 | 1000 |
| Truck | 0.55 | 0.65 | 0.60 | 1000 |
| **Accuracy**| | | 0.58 | 10000 |
| **Macro Avg** | 0.58 | 0.58 | 0.57 | 10000 |
| **Weighted Avg** | 0.58 | 0.58 | 0.57 | 10000 |

### MNIST
- **Accuracy**: Achieved accuracy on the MNIST test set - `0.9862000000`
- **Precision**: Achieved precision on the MNIST test set - `0.9862803962`
- **Classification Report**: Detailed classification report for MNIST.

| Class | Precision | Recall | F1-Score | Support |
|-------|-----------|--------|----------|---------|
| 0 | 0.99 | 0.99 | 0.99 | 980 |
| 1 | 0.99 | 1.00 | 0.99 | 1135 |
| 2 | 0.99 | 0.99 | 0.99 | 1032 |
| 3 | 0.97 | 0.99 | 0.98 | 1010 |
| 4 | 0.99 | 0.99 | 0.99 | 982 |
| 5 | 0.97 | 0.99 | 0.98 | 892 |
| 6 | 0.99 | 0.99 | 0.99 | 958 |
| 7 | 0.99 | 0.98 | 0.98 | 1028 |
| 8 | 1.00 | 0.97 | 0.98 | 974 |
| 9 | 0.99 | 0.97 | 0.98 | 1009 |
| **Accuracy** | | | 0.99 | 10000 |
| **Macro Avg** | 0.99 | 0.99 | 0.99 | 10000 |
| **Weighted Avg** | 0.99 | 0.99 | 0.99 | 10000 |

## 📈 Visualizations

### CIFAR-10
- **Training and Validation Accuracy**: Line plot of training and validation accuracy per epoch.
- **Training and Validation Loss**: Line plot of training and validation loss per epoch.
- ![image](https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks/assets/119779889/0850e3db-cfe2-43ea-9fa2-fbdee733e612)

### MNIST
- **Training and Validation Accuracy**: Line plot of training and validation accuracy per epoch.
- **Training and Validation Loss**: Line plot of training and validation loss per epoch.
![image](https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks/assets/119779889/cb3c8a92-f909-4cdc-8209-280dca76a7de)

## 🎉 Conclusion
This notebook demonstrates the implementation of a LeNet-5 model for image classification on the CIFAR-10 and MNIST datasets. The models achieve high accuracy and precision, indicating the effectiveness of LeNet-5 for image classification tasks.
1 change: 1 addition & 0 deletions Models/MobileNet_Model/MobileNet_Model.ipynb

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions Models/MobileNet_Model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# 📱 MobileNet Model for Image Classification

## 📝 Overview
This project implements a MobileNet Convolutional Neural Network (CNN) for image classification using the CIFAR-10 and MNIST datasets. The notebook `MobileNet_model.ipynb` contains the entire workflow from data loading and preprocessing to model training, evaluation, and visualization.

## ⚙️ Installation
To run this project, you'll need to install the required libraries. You can do this by running:

```bash
pip install -r requirements.txt
```

## 🚀 Usage

1. **Clone the repository**:
```bash
git clone https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks.git
cd Image-Classification-using-Convolutional-Neural-Networks/Models/MobileNet_Model/
```

2. **Install the required packages**:
```bash
pip install -r requirements.txt
```

3. **Run the Jupyter Notebook**:
```bash
jupyter notebook MobileNet_model.ipynb
```

## 📦 Dataset

### CIFAR-10
- **Description**: The CIFAR-10 dataset consists of 60,000 32x32 color images in 10 different classes.
- **Classes**: 🛩️ Airplane, 🚗 Automobile, 🐦 Bird, 🐱 Cat, 🦌 Deer, 🐶 Dog, 🐸 Frog, 🐴 Horse, 🚢 Ship, 🚚 Truck.

### MNIST
- **Description**: The MNIST dataset consists of 70,000 28x28 grayscale images of handwritten digits.
- **Classes**: Digits 0 through 9.

## 🏗️ Model Architecture

The MobileNet model for CIFAR-10 has the following architecture:
```python
def create_mobilenet_cifar10(input_shape, num_classes):
base_model = tf.keras.applications.MobileNet(weights=None, include_top=False, input_shape=input_shape)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dropout(0.5)(x)
predictions = Dense(num_classes, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model
```

The MobileNet model for MNIST has the following architecture:
```python
def create_mobilenet_mnist(input_shape, num_classes):
base_model = tf.keras.applications.MobileNet(weights=None, include_top=False, input_shape=input_shape)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
x = Dropout(0.5)(x)
predictions = Dense(num_classes, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model
```

## 📝 Steps

### 1. Data Loading and Preprocessing
- Load the CIFAR-10 and MNIST datasets.
- Normalize the pixel values to the range [0, 1].
- Convert class labels to categorical format.

### 2. Model Training
- Train the MobileNet model on both CIFAR-10 and MNIST datasets.
- Record the training and validation accuracy and loss over epochs.

### 3. Model Evaluation
- Evaluate the trained model on the test data.
- Calculate accuracy and precision.
- Generate a detailed classification report.

### 4. Visualization
- Plot training and validation accuracy and loss for each epoch.
- Display class distribution and exploratory data analysis (EDA) plots.

## 📊 Results

### CIFAR-10
- **Accuracy**: Achieved accuracy on the CIFAR-10 test set - `0.5521000000`
- **Precision**: Achieved precision on the CIFAR-10 test set - `0.5592675699`
- **Classification Report**: Detailed classification report for CIFAR-10.

| Class | Precision | Recall | F1-Score | Support |
|-------------|-----------|--------|----------|---------|
| Airplane | 0.57 | 0.63 | 0.60 | 1000 |
| Automobile | 0.78 | 0.56 | 0.65 | 1000 |
| Bird | 0.47 | 0.33 | 0.39 | 1000 |
| Cat | 0.33 | 0.11 | 0.17 | 1000 |
| Deer | 0.48 | 0.46 | 0.47 | 1000 |
| Dog | 0.39 | 0.70 | 0.50 | 1000 |
| Frog | 0.72 | 0.59 | 0.65 | 1000 |
| Horse | 0.51 | 0.72 | 0.60 | 1000 |
| Ship | 0.73 | 0.68 | 0.71 | 1000 |
| Truck | 0.61 | 0.72 | 0.66 | 1000 |
| **Accuracy**| | | 0.55 | 10000 |
| **Macro Avg** | 0.56 | 0.55 | 0.54 | 10000 |
| **Weighted Avg** | 0.56 | 0.55 | 0.54 | 10000 |

### MNIST
- **Accuracy**: Achieved accuracy on the MNIST test set - `0.9843000000`
- **Precision**: Achieved precision on the MNIST test set - `0.9844091197`
- **Classification Report**: Detailed classification report for MNIST.

| Class | Precision | Recall | F1-Score | Support |
|-------|-----------|--------|----------|---------|
| 0 | 0.98 | 1.00 | 0.99 | 980 |
| 1 | 1.00 | 0.99 | 1.00 | 1135 |
| 2 | 0.97 | 1.00 | 0.99 | 1032 |
| 3 | 0.98 | 1.00 | 0.99 | 1010 |
| 4 | 1.00 | 0.98 | 0.99 | 982 |
| 5 | 0.98 | 0.99 | 0.98 | 892 |
| 6 | 0.99 | 0.98 | 0.99 | 958 |
| 7 | 0.98 | 0.98 | 0.98 | 1028 |
| 8 | 0.98 | 0.97 | 0.97 | 974 |
| 9 | 0.99 | 0.96 | 0.97 | 1009 |
| **Accuracy** | | | 0.98 | 10000 |
| **Macro Avg** | 0.98 | 0.98 | 0.98 | 10000 |
| **Weighted Avg** | 0.98 | 0.98 | 0.98 | 10000 |

## 📈 Visualizations

### CIFAR-10
- **Training and Validation Accuracy**: Line plot of training and validation accuracy per epoch.
- **Training and Validation Loss**: Line plot of training and validation loss per epoch.
![image](https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks/assets/119779889/94c43184-43ee-4c05-b99e-6809103857ec)


### MNIST
- **Training and Validation Accuracy**: Line plot of training and validation accuracy per epoch.
- **Training and Validation Loss**: Line plot of training and validation loss per epoch.
![image](https://github.com/UTSAVS26/Image-Classification-using-Convolutional-Neural-Networks/assets/119779889/6655a5d9-313e-4bab-a624-0ed1ca07a001)


## 🎉 Conclusion
This notebook demonstrates the implementation of a MobileNet model for image classification on the CIFAR-10 and MNIST datasets. The models achieve good accuracy and precision, showcasing the effectiveness of deep learning architectures like MobileNet for image classification tasks.
Loading
Loading