This program implements a linear classifier algorithm that can differentiate between circles and rectangles. The algorithm is based on the Perceptron model, which is a type of neural network that learns by adjusting weights to classify input data.
The only dependency required to run this program is PIL (Pillow). We believe in keeping dependencies to a minimum to reduce unnecessary complexity.
- Clone the repository by running the following command:
git clone https://github.com/tusharhero/perceptron.git
- Navigate to the project directory:
cd perceptron
- Train the model by running the following command:
python train.py
This will train the model using the default dataset and save the trained weights to disk.
- Test the model by running the following command:
python test.py /path/to/weights /path/to/image
Replace /path/to/weights
with the location of the trained weights file( ./weight
by default), and /path/to/image
with the location of the test image(The image has to be in 8 bits). This will run the model on the test image and display the results.
To train the algorithm, we need to generate two types of images: circles and rectangles. For circles, we use the PIL library to create 100px * 100px images with varying configurations of radius and center coordinates. The circle is defined by the equation:
(x-a)^2 + (y-b)^2 <= r^2
For rectangles, we generate images with a random size and position. The rectangle is defined by the equation:
|x-a| <= q and |y-b| <= p
To test the algorithm, we randomly select an image with a shape (either circle or rectangle) and run it through the algorithm. The algorithm then adjusts its weights based on whether the classification was correct or not. We continue this process until the algorithm can accurately classify all images.
We would like to thank Techlord210 for testing the code and submitting several pull requests. Their contributions have helped to improve the quality and functionality of the program.
For more information on the Perceptron algorithm, please refer to the Wikipedia article.