From f5ff6fbd5a5aa0801806668ccdc4fae9a1a152d6 Mon Sep 17 00:00:00 2001 From: choukri <ayoub.chess1998@gmail.com> Date: Tue, 8 Nov 2022 18:58:04 +0100 Subject: [PATCH] update README.md --- README.md | 159 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index e8c895a..2db19f9 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,133 @@ -# Image Classification +# description of the project +The objective of this project is to develop a classification model that will be able to recognize the class of given images. To do so, we should: +1. Load a dataset which contains the images and their classes -## Getting started +2. Split the dataset into a training set and test set -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +3. Train our model with training data -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +4. Test the model with the test set -## Add your files +5. Evaluate the model -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +# description of the dataset -``` -cd existing_repo -git remote add origin https://gitlab.ec-lyon.fr/choukria/image-classification.git -git branch -M main -git push -uf origin main -``` +The `CIFAR-10` dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images. +The dataset is divided into five training batches and one test batch, each with 10000 color images of size 32x32 divided into 10 classes(plane, car, bird, cat, ...). + +Here are the classes in the dataset, as well as 10 random images from each: + + -## Integrate with your tools +the dataset can be obtained at this adress: https://www.cs.toronto.edu/~kriz/cifar.html -- [ ] [Set up project integrations](https://gitlab.ec-lyon.fr/choukria/image-classification/-/settings/integrations) +In our project we developed the model using the Knn algorithm and the MLP neural network -## Collaborate with your team +## K-nearest neighbors -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) +This algorithm consists of calculating a Euclidean distance between the training data and the test data and choose the majority class out of K labels that have the smallest distance with the train data -## Test and Deploy +### Usage -Use the built-in continuous integration in GitLab. +To understand the Knn algorithm with a simple example visit the link: https://www.makeareadme.com/ -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) +The precision of our Knn Model can change according to the value of K -*** +The following figure shows the accuracy of our model based on K -# Editing this README + -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +### Multi Layer Perceptron Neural Network -## Name -Choose a self-explaining name for your project. +The objective here is to develop a classifier based on a multilayer perceptron (MLP) neural network. -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +We will focus on the backpropagation of the gradient. -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. +We first initialize the network weights and biases and precise our data and desired output -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. +### Usage of initializing network weights and biases +```python +import numpy as np -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +N = 30 # number of input data +d_in = 3 # input dimension +d_h = 3 # number of neurons in the hidden layer +d_out = 2 # output dimension (number of neurons of the output layer) + +# Random initialization of the network weights and biaises +w1 = 2 * np.random.rand(d_in, d_h) - 1 # first layer weights +b1 = np.zeros((1, d_h)) # first layer biaises +w2 = 2 * np.random.rand(d_h, d_out) - 1 # second layer weights +b2 = np.zeros((1, d_out)) # second layer biaises + +data = np.random.rand(N, d_in) # create a random data +targets = np.random.rand(N, d_out) # create a random targets +``` -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +To develop and train our MLP neural network model we repeat this 4 steps -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. +1. Forward propagation -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +2. Compute the loss that separates the output from the desired target + +3. backpropagation + +4. Gradient descent + +## Forward propagation + +We circulate the data from the input to the output + +### Usage +```python +# Forward propagation +a0 = data # the data are the input of the first layer +z1 = np.matmul(a0, w1) + b1 # input of the hidden layer +a1 = 1 / (1 + np.exp(-z1)) # output of the hidden layer (sigmoid activation function) +z2 = np.matmul(a1, w2) + b2 # input of the output layer +a2 = 1 / (1 + np.exp(-z2)) # output of the output layer (sigmoid activation function) +predictions = a2 # the predicted values are the outputs of the output layer +``` +## Compute the loss -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +We compute the loss that separates the output from the desired target -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. +```python +# Compute loss (MSE) +loss = np.mean(np.square(predictions - targets)) +print(loss) +``` + +## Backpropagation + +we compute the variation of this loss function in each layer starting from the last layer to the first layer + + +## Gradient descent + +We correct the model parameters as the weights and biases + +### Usage + +```python +# updated weights of the network + +w1 = w1 - learning_rate * var_loss_w1 +w2 = w2 - learning_rate * var_loss_w2 + +# updated biaises of the network + +b1 = b1 - learning_rate * var_loss_b1 +b2 = b2 - learning_rate * var_loss_b2 +``` -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +I trained the model 100 times, the following picture shows the variation of the accuracy along the training -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. + -## License -For open source projects, say how it is licensed. +The variation of the loss: -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. + \ No newline at end of file -- GitLab