Git Product home page Git Product logo

alessandroptsn / faces_emotions Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 50.87 MB

This project consists of building a convolutional neural network model that classifies the emotion that a face shows in a given photo. Once the model is created, save it to W&B and create an API hosted on Heroku that makes the created model available for production.

License: GNU General Public License v3.0

Python 31.95% Procfile 0.01% Jupyter Notebook 68.04%

faces_emotions's Introduction

Faces_Emotions

Introduction

This project consists of building a convolutional neural network model that classifies the emotion that a face shows in a given photo. Once the model is created, save it to W&B and create an API hosted on Heroku that makes the created model available for production.

Medium: Link
API: Link

ezgif-1-19553b9037

The convolutional neural network consists of multiple layers: convolucional, dense(ReLU), Batch Normalization, Max Pooling, Dropout, Flatten and a Dense(Softmax) layer to classify the emotion.

The data consists of 48x48 pixels grayscale images of faces. The faces have been automatically registered. The task is to categorize each face based on the emotion shown in the facial expression into one of six categories (0=Angry, 1=Fear, 2=Happy, 3=Sad, 4=Surprise, 5=Neutral). The training set consists of 35,342 examples

Model Card

The model was deployed to the web using the FastAPI package and API tests were created. The API tests will be embedded in a CI/CD framework using GitHub Actions. After we built our API locally and tested it, we deployed it to Heroku and tested it again live. Weights and Biases were used to manage the model.

Model_card

So, in general, the notebook used is divided into 7 parts:

  1. Import library
  2. Loggin in W&B
  3. Import data
  4. Splitting the data between training and testing
  5. Create model
  6. Training
  7. Test

Anaconda Environment

Create a conda environment with environment.yml:

conda env create --file environment.yml

To remove an environment in your terminal window run:

conda remove --name myenv --all

To list all available environments run:

conda env list

To activate the environment, use

conda activate myenv

Fast API

The API is implemented in the source/api/main.py whereas tests are on source/api/test_main.py.

For the sake of understanding and during the development, the API was constanly tested using:

uvicorn source.api.main:app --reload

and using these addresses:

http://127.0.0.1:8000/
http://127.0.0.1:8000/docs

The screenshot below show a view of the API docs.

image

For test the API, please run:

pytest source/api -vv -s

Heroku

  1. Sign up for free and experience Heroku.
  2. Now, it's time to create a new app. It is very important to connect the APP to our Github repository and enable the automatic deploys.
  3. Install the Heroku CLI following the instructions.
  4. Sign in to heroku using terminal
heroku login
  1. In the root folder of the project check the heroku projects already created.
heroku apps
  1. Check buildpack is correct:
heroku buildpacks --app faces-emotions
  1. Update the buildpack if necessary:
heroku buildpacks:set heroku/python --app faces-emotions
  1. When you're running a script in an automated environment, you can control Wandb with environment variables set before the script runs or within the script. Set up access to Wandb on Heroku, if using the CLI:
heroku config:set WANDB_API_KEY=xxx --app faces-emotions
  1. The instructions for launching an app are contained in a Procfile file that resides in the highest level of your project directory. Create the Procfile file with:
web: uvicorn source.api.main:app --host=0.0.0.0 --port=${PORT:-5000}
  1. Configure the remote repository for Heroku:
heroku git:remote --app faces-emotions
  1. Push all files to remote repository in Heroku. The command below will install all packages indicated in requirements.txt to Heroku VM.
git push heroku main
  1. Check the remote files run:
heroku run bash --app faces-emotions
  1. If all previous steps were done with successful you will see the message below after open: https://faces-emotions.herokuapp.com/.
  2. For debug purposes whenever you can fetch your app’s most recent logs, use the heroku logs command:
heroku logs

References

Main reference - Ivanovitch's git repo

Kaggle

faces_emotions's People

Contributors

alessandroptsn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.