Skip to content

Hasnatrasool163/NeuralNetworkFromScratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This code initializes and trains a neural network to recognize and predict ASCII characters. The network uses leaky ReLU activation functions for its hidden layers and softmax for the output layer. It incorporates L2 regularization to prevent overfitting and utilizes backpropagation for training.

Updated README.md

# Deep Neural Network for Character Recognition

This project develops a deep neural network (DNN) capable of recognizing and predicting ASCII characters. The network is trained on a synthetic dataset generated from one-hot encoded ASCII characters, allowing it to learn the representation of each character.

## Features

- **Leaky ReLU Activation:** Utilizes the leaky ReLU activation function for hidden layers to help prevent the dying ReLU problem.
- **Softmax Output Layer:** Employs a softmax activation function in the output layer for multi-class classification.
- **L2 Regularization:** Incorporates L2 regularization to reduce overfitting by penalizing large weights.
- **Backpropagation:** Updates model weights and biases using the backpropagation algorithm.
- **Model Save/Load:** Allows saving and loading the model weights to/from a file.

## Requirements

To run this project, you need Python 3.x and the following packages:

- numpy
- os
- pickle

## Usage

1. **Generate Data:** Synthetic data for training is generated automatically.
2. **Initialize Network:** The network is initialized with predefined layers and parameters.
3. **Train Network:** Train the network using the generated data.
4. **Test Network:** After training, test the network's predictions on ASCII characters.
5. **Save/Load Model:** Optionally, save or load the model weights for future use.

```python
# Initialize the network
nn = DeepNeuralNetwork(layers=[95, 128, 64, 95], learning_rate=0.01, lambda_reg=0.001)

# Train the network
nn.train(X, Y, epochs=5000)

# Test the network
test_all_characters(nn, test_characters)

Customization
Layers and Neurons: You can customize the network architecture by adjusting the number of layers and neurons.
Learning Rate and Regularization: Adjust the learning rate and lambda regularization parameter as needed.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.

License
This project is licensed under the MIT License - see the LICENSE.md file for details.


This README.md provides a comprehensive overview of your project, including how to use.

Project Structure
bash
Copy code
character-recognition-neural-network/
│
├── model_weights95.pkl       # Saved model weights (after training)
├── neural_network.py         # Main neural network implementation
└── README.md                 # This file
Getting Started
To get started with this project, clone the repository and ensure you have the necessary Python packages installed. You can run the neural network model directly from the neural_network.py script, which will train the model and then allow you to test character predictions.

bash
Copy code
git clone https://github.com/yourusername/character-recognition-neural-network.git
cd character-recognition-neural-network
python neural_network.py
Frequently Asked Questions (FAQ)
Q: How do I change the characters set the network can recognize?
A: Modify the test_characters string in the main function to include the characters you wish to recognize.

Q: How long does training take?
A: Training time depends on your system's capabilities and the specified epochs. Typically, a few minutes for 5000 epochs on a modern CPU.

Q: Can I use this model for recognizing characters in images?
A: This model is designed for recognizing and predicting ASCII characters from one-hot encoded inputs. For image-based character recognition, you would need a model that can handle image data, such as a Convolutional Neural Network (CNN).

Q: How can I improve the model's performance?
A: Experiment with adjusting the network's architecture (number of layers and neurons), learning rate, and regularization parameter. More advanced techniques could include implementing dropout or exploring different activation functions.

Contributing
We welcome contributions to this project! If you have suggestions for improvements or new features, please follow these steps:

Fork the repository.
Create a new branch (git checkout -b feature/AmazingFeature).
Make your changes.
Commit your changes (git commit -m 'Add some AmazingFeature').
Push to the branch (git push origin feature/AmazingFeature).
Open a pull request.
Please make sure to update tests as appropriate.

Support
If you need help or have any questions, please open an issue, and we'll do our best to assist you.

License
Distributed under the MIT License. See LICENSE for more information.