This project is a demonstration of what I learned from the first few lessons of the 2019 Fast.ai MOOC. The goal is to train an image classifier that can distinguish between deadly coral snakes (Micrurus tener) and harmless scarlet kingsnakes (Lampropeltis elapsoides). It's a demo project so don't take the results too seriously.
The project is composed of 3 major parts: model training environment, backend API server and frontend webserver.
The model is created using Jupyter notebooks that can run on remote servers with powerful GPUs. The initial model is a convolutional neural network using Resnet34 architecture and pretrained parameters from ImageNet. I trained the model using several hundred images harvested using various search engines. I used techniques from the Fast.ai course to train using a succession of learning rates. The resulting model is 95% accurate according to the validation set composed of 85 images.
Read more here
The backend API is a python-based web server that wraps the trained, exported model created by the training environment. This server provides an API that accepts an image or url, and returns prediction data as JSON. The server runs in a Docker container so it can run on development desktop machines or deploy to remote hosts such as Heroku.
Read more here
The frontend server provides a nicer interface to the backend API. This is implemented in a separate github repository.
View the live demo. The frontend is hosted with Vercel, the backend is hosted on Heroku. The Heroku server is using the free tier. The downside is the server is put to sleep after a period of inactivity, so the initial initial upload will have a noticeable 15 second delay before the progress bar moves beyond 0%.
Prerequisites:
- Docker
- Git clone this repository
In the project root run compose up dev
to build and run the docker image. The API server's barebones home page is now available at http://localhost:8009. Upload a picture of a coral or kingsnake and see what the model guesses.
The project folder is mounted into the container so it's easy to edit files directly and see the results. The python server automatically reloads if changes are made. If you like coding in VScode then check out my setup in the backend docs.
Prerequisites:
- Docker
- Heroku account
- Heroku CLI
- Git clone this repository
Create a new heroku app and connect docker to Heroku's container registry. In your project root run:
heroku container:login
heroku create
heroku auth:token | docker login --username=\_ --password-stdin registry.heroku.com
For each deploy iteration, build, tag, push and release. Take note of the Heroku app name generated by the heroku create
and use that in place of snakes-api
in the commands below. If you get stuck, check out the Heroku docs.
compose build prod
docker tag snakes_prod:latest registry.heroku.com/snakes-api/web
docker push registry.heroku.com/snakes-api/web
heroku container:release web