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

Persian Alphabets Classification using NLP #498

Merged
merged 11 commits into from
Feb 24, 2024
Merged
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
66 changes: 66 additions & 0 deletions Persian Alphabets Classification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Persian Alphabet Classification with Hybrid CNN-LSTM Model

This repository contains the code and models for classifying Persian alphabets using a hybrid CNN-LSTM deep learning model.

## Overview

In this repo, I developed a novel deep learning approach for classifying Persian alphabet characters. We utilized a hybrid model combining Convolutional Neural Networks (CNNs) and Long Short-Term Memory (LSTM) networks to effectively capture spatial and sequential patterns in the input data, respectively.

## Dataset

The dataset used in this project consists of 51,744 images of Persian alphabets and numbers. The images are organized into folders based on their corresponding labels, making it suitable for training and evaluating machine learning models for Persian alphabet classification.

You can download the dataset from [Kaggle](https://www.kaggle.com/datasets/mostafamohammadi1/persian-alphabets-and-numbers).

## Files

- `model/notebook.ipynb`: Jupyter notebook containing the Python code for training the hybrid CNN-LSTM model and evaluating its performance on the test dataset.
- `model/cnn_model.h5 | lstm_model.h5 | hybrid_model.h5` : Model files containing the weights and architecture of the trained standalone and hybrid model of CNN and LSTM architectures.

## Usage

To use the pre-trained model for inference, follow these steps:

1. Clone or download this repository to your local machine.
2. Open the Jupyter notebook `notebook.ipynb` using Jupyter Notebook or JupyterLab.
3. Follow the instructions in the notebook to load the pre-trained model and perform inference on your own data.

## Requirements

1. To run the Jupyter notebook, you need the following dependencies:

- Python 3
- Jupyter Notebook or JupyterLab
- TensorFlow 2.x
- NumPy
- Matplotlib
- Seaborn
- scikit-learn

2. You can install the required packages using pip:

```bash
pip install jupyter tensorflow numpy matplotlib seaborn scikit-learn
```

3. Download the dataset
4. Navigate to the `model/notebook.ipynb`
5. Run all the cells

## Additional Resources

Check out the Kaggle notebook for Persian Alphabet Classification using CNN and LSTM: [Kaggle Notebook](https://www.kaggle.com/code/gowrivinaykamalakars/persian-alphabet-classification-using-cnn-and-lstm)

## Contributor:
<p align="center">
<img src="https://github.com/sgvkamalakar.png" height="200" width="200"/>
</p>
<p align="center">
Kamalakar Satapathi
</p>


Connect with me on [![LinkedIn](https://img.shields.io/badge/-Kamalakar_Satapathi-0077B5?style=flat-square&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/sgvkamalakar)

Explore my magical codes [![GitHub](https://img.shields.io/badge/-Sgvkamalakar-181717?style=flat-square&logo=github)](https://github.com/sgvkamalakar)

34 changes: 34 additions & 0 deletions Persian Alphabets Classification/dataset/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Persian Alphabets Dataset

## Overview

This dataset contains a collection of 51.7K images of Persian alphabets and numbers. The image files are named from 0 to 51.7K and **labels.csv** contains `File_Name` mapped to their corresponding `Label`, making it suitable for use in classification tasks.

## Dataset Contents

The dataset is organized into the following structure:

- **data**
- **/data**: contains images of 77 different persian characters
- **labels.csv**: CSV file containing the mapping of image filenames to their corresponding labels.

## Dataset Source

The dataset was sourced from [Kaggle](https://www.kaggle.com/datasets/mostafamohammadi1/persian-alphabets-and-numbers).

## Usage

You can use this dataset for various purposes, including but not limited to:

- Training and evaluating DL models for Persian alphabet and number classification.
- Research in computer vision, pattern recognition, and deep learning.
- Educational purposes for learning image classification techniques.

## Citation

If you use this dataset in your work, please consider citing the dataset source on Kaggle.

## License

The dataset is provided under the terms specified by the dataset creator on Kaggle. Please refer to the Kaggle dataset page for details about the license.

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 Persian Alphabets Classification/images/loss.png
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 not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Persian Alphabets Classification/models/notebook.ipynb

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions Persian Alphabets Classification/models/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Work flow

1. Data Collection:

- Download the dataset from [Kaggle](https://www.kaggle.com/datasets/mostafamohammadi1/persian-alphabets-and-numbers)
- Curate and organize the dataset into appropriate folders.

2. Data Preprocessing:

- Load the dataset and preprocess the images.
- Resize the images to a uniform size.
- Split the dataset into training and testing sets.
- Convert images to numerical arrays for model input.

3. Model Architecture Design:

- Design a hybrid architecture combining CNN and LSTM layers.
- Define the number of layers, filter sizes, and activation functions.
- Compile the model with appropriate loss function and optimizer.

4. Model Training:

- Feed the preprocessed data into the model for training.
- Iterate over multiple epochs to allow the model to learn the patterns in the data.
- Adjust the model parameters based on training performance.

5. Model Evaluation:

- Evaluate the trained model on the test dataset.
- Calculate performance metrics such as accuracy, loss, and classification reports.
- Visualize the training and validation metrics to assess model performance.

## Evaluation Metrics

<p align="center">

<img src="https://github.com/abhisheks008/DL-Simplified/assets/103712713/5ab41544-11bc-4439-80ea-c146901dc553" />
</p>

## Findings

1. Standalone CNN Model: The standalone CNN model achieved a classification accuracy of 95.1% on the test dataset. This indicates that the CNN model was effective in extracting relevant features from the input images of Persian alphabet characters and making accurate predictions.

2. Standalone LSTM Model: The standalone LSTM model reported a classification accuracy of 94.9% on the test dataset. This suggests that the LSTM model was successful in capturing sequential patterns in the input data and performing well in classifying Persian alphabet characters.

3. Hybrid Model: Surprisingly, the hybrid CNN-LSTM model yielded a slightly lower classification accuracy of 94.2% compared to the standalone models. This suggests that the combination of CNN and LSTM layers did not provide significant improvement over using either model alone for Persian alphabet classification.
5 changes: 5 additions & 0 deletions Persian Alphabets Classification/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tensorflow
numpy
matplotlib
seaborn
scikit-learn