https://github.com/aliiiw/ai-project
Persian hand writing digit detection using tensorflow
https://github.com/aliiiw/ai-project
cnn handwritten-digit-recognition persian-language random-forest-classifier tensorflow
Last synced: about 2 months ago
JSON representation
Persian hand writing digit detection using tensorflow
- Host: GitHub
- URL: https://github.com/aliiiw/ai-project
- Owner: Aliiiw
- Created: 2024-02-02T18:40:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-02T18:49:36.000Z (over 2 years ago)
- Last Synced: 2025-08-07T00:42:49.534Z (11 months ago)
- Topics: cnn, handwritten-digit-recognition, persian-language, random-forest-classifier, tensorflow
- Language: Python
- Homepage:
- Size: 1.91 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ai-Project
Ai-Project is a Persian handwritten digit recognition project. It loads digit images from a folder-based dataset, preprocesses them into 8x8 grayscale feature vectors, trains a Random Forest classifier, and also includes a simple PyTorch neural network as a bonus model.
## Output Samples
## Features
- Loads custom image datasets from class folders.
- Converts each image to grayscale.
- Resizes images to 8x8 pixels and flattens them into 64-value feature vectors.
- Normalizes pixel values and applies `StandardScaler`.
- Splits the dataset into train/test sets.
- Trains a `RandomForestClassifier` from scikit-learn.
- Evaluates Random Forest accuracy on the test split.
- Defines and trains a simple PyTorch neural network.
- Evaluates neural-network accuracy.
- Visualizes the original image, Random Forest prediction, and neural-network prediction side by side.
## Tech Stack
- Python
- NumPy
- OpenCV
- scikit-learn
- PyTorch
- Matplotlib
## Project Structure
```text
.
├── AliRahimi.py # Main training, evaluation, and visualization script
├── AI-Project-Fall-1402.pdf # Assignment/project document
├── images/ # Output screenshots
└── README.md
```
## Dataset Format
The script expects a local dataset folder named `Train` in the project root. Each subfolder should represent one digit/class label:
```text
Train/
├── 0/
│ ├── image_1.png
│ └── ...
├── 1/
│ └── ...
└── 9/
└── ...
```
Folder names are converted to integer labels, so they should be numeric digit labels.
## How It Works
1. `loadImages()` walks through every class folder and reads the images.
2. `convertTo8Gray()` converts each image to grayscale, resizes it to 8x8, and flattens it.
3. `LoadCustomDataSet()` normalizes, splits, and scales the dataset.
4. A Random Forest model is trained and evaluated.
5. A small PyTorch neural network with one hidden layer is trained for 10 epochs.
6. A test image is visualized with both model predictions.
## Running the Project
Install the required packages:
```bash
pip install numpy opencv-python scikit-learn matplotlib torch
```
Then place the dataset in `./Train` and run:
```bash
python AliRahimi.py
```
## Notes
The dataset itself is not included in this repository. The script depends on the local `Train` folder being present before execution.