All Projects → floleuerer → fastai-docker-deploy

floleuerer / fastai-docker-deploy

Licence: MIT license
Deploy fastai models with Docker

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to fastai-docker-deploy

DeploymentReadinessChecker
Pester-based tool to validate that a (potentially large) number of machines meet the prerequisites for a software deployment/upgrade.
Stars: ✭ 31 (+63.16%)
Mutual labels:  deployment
django-boilerplate-3.6.1
Django served by Gunicorn running behind Nginx reverse proxy. Deploy to AWS Elastic Beanstalk with Fabric3!
Stars: ✭ 13 (-31.58%)
Mutual labels:  deployment
feater
Tool for rapid deployment of selected features of your web application to isolated testing or demo environments.
Stars: ✭ 27 (+42.11%)
Mutual labels:  deployment
mina-hanami
🌸 Mina plugin for Hanami
Stars: ✭ 13 (-31.58%)
Mutual labels:  deployment
phoenix example
An example Phoenix app with one-click deployments to different cloud services.
Stars: ✭ 62 (+226.32%)
Mutual labels:  deployment
laravel-env-security
Securely manage Laravel .env files for different deployment environments
Stars: ✭ 67 (+252.63%)
Mutual labels:  deployment
aws-syndicate
Syndicate deployment framework
Stars: ✭ 48 (+152.63%)
Mutual labels:  deployment
github-env-vars-action
🚀 GitHub Action for Environment Variables
Stars: ✭ 129 (+578.95%)
Mutual labels:  deployment
corebot
A bot to trigger Rundeck and Jenkins jobs from Slack.
Stars: ✭ 69 (+263.16%)
Mutual labels:  deployment
sclblpy
Python package for Scailable uploads
Stars: ✭ 18 (-5.26%)
Mutual labels:  deployment
capistrano-uberspace
Deploy your rails app on an uberspace with Capistrano 3
Stars: ✭ 14 (-26.32%)
Mutual labels:  deployment
daisykit
Daisykit is an easy AI toolkit for software engineers to integrate pretrained AI models and pipelines into their projects. - with NCNN, OpenCV, Python wrappers
Stars: ✭ 22 (+15.79%)
Mutual labels:  deployment
volkscv
A Python toolbox for computer vision research and project
Stars: ✭ 58 (+205.26%)
Mutual labels:  deployment
django-projesini-yayina-alma
Django uygulamasını yayına almak için Türkçe dökümantasyon
Stars: ✭ 98 (+415.79%)
Mutual labels:  deployment
tiller-circleci-orb
Deploy Trellis, Bedrock and Sage(optional) via CircleCI
Stars: ✭ 13 (-31.58%)
Mutual labels:  deployment
docker-deployer
Docker image for PHP Deployer.
Stars: ✭ 24 (+26.32%)
Mutual labels:  deployment
Installomator
Installation script to deploy standard software on Macs
Stars: ✭ 472 (+2384.21%)
Mutual labels:  deployment
drupal-pi
Drupal on Docker on a Raspberry Pi. Pi Dramble's little brother.
Stars: ✭ 92 (+384.21%)
Mutual labels:  deployment
envoyer-npm-deployment
Compile assets that depend on node packages using Laravel Envoyer deployment hooks
Stars: ✭ 43 (+126.32%)
Mutual labels:  deployment
ploi-deploy-action
Deploy your application to Ploi with Github actions
Stars: ✭ 25 (+31.58%)
Mutual labels:  deployment

fastai-docker-deploy

Building DeepLearning models is really easy with fast.ai - deploying models unfortunatley is not! So i tried to find a cheap and easy way, to deploy models with Docker as a REST-API (folder fastai-rest). Besides that, i also to develop a "frontend" component using nginx to secure the API calls by enabling SSL with letsencrypt. I added a small Website so you can interact with the model :).

All of this is running on a 5 $ DigitalOcean Droplet. See my website Dog or HotDog?.

If you are just intrested in deploying a model as a REST-API see fastai-rest and the README there and my blogpost.

Architecutre

Here's an overview of the architecture.

                DigitalOcean Droplet
     +-------------------------------------+
     |               Docker                |
     |                                     |
     |                      /api calls     |
     |    +-----------+  interal redirect  |
     |    |           |     http 8080      |
     |    |  fastai   | <------------+     |
     |    |           |              |     |
     |    |           |              |     |
     |    +-----------+              |     |   dog-or-hotdog.meansqua.red/api   +------------+
     |      Container      +-----------+   |          http(s) 80/443            |            |
     |                     |           |   |        redirect to fastai          |            |
     |                     |           | <--------------------------------------+            |
     |                     |   nginx   |   |                                    |   client   |
     |                     |           | <--------------------------------------+            |
     |                     |           |   |    dog-or-hotdog.meansqua.red      |            |
     |                     +-----------+   |         http(s) 80/443             |            |
     |                       Container     |       Website nginx/html           +------------+
     |                                     |
     +-------------------------------------+

Prerequisites

Create Droplet + Domain

  • Create Docker Droplet on DigitalOcean (see my blogpost - make sure to follow the instructions and create a swap-file!)
  • Create (sub-)domain (e.g. dog-or-hotdog.meansqua.red) and assign Droplet IP

Setup

The nginx-frontend/config and nginx-frontend/html folders are mounted into the Docker container. So it's curcial to use the same the paths (so make sure to clone the repo in /docker)!

Hostname

The hostname dog-or-hotdog.meansqua.red has to be replaced with your hostname in the following files:

nginx-frontend/config/default.config
nginx-html/classify.js

Letsencrypt

Install certbot and create letsencrypt certificates

# add repositories
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update

# install certbot
sudo apt-get install certbot

# open firewall port 80 temporarily
sudo ufw allow 80/tcp

# create letscrypt certificate
sudo certbot certonly --standalone

# close firewall again
sudo ufw delete allow 80/tcp

The certificates are stored in /etc/letsencrypt/live/<domainname>.

Cronjob for letsencrypt certificate renewal

To renew the letsencrypt certificates automatically add the following command to the root users crontab. This will renew your certificate at the first day of each month at 00:00.

crontab -e

# add the following line
0 0 1 * * /usr/bin/certbot renew --pre-hook "docker-compose -f /docker/fastai2-docker-deploy/docker-compose.yml down" --post-hook "docker-compose -f /docker/fastai2-docker-deploy/docker-compose.yml up -d"

Clone repository

Clone this repository on your Droplet

mkdir /docker && cd /docker
git clone https://github.com/floleuerer/fastai-docker-deploy.git

Download fastai-model

The fastai model is not part of the repository. The Dog or HotDog model can be downloaded here and has to be copied to fastai-rest/app/model.pkl.

cd /docker/fastai-docker-deploy/fastai-rest/app/
wget https://www.meansqua.red/files/model.pkl

Build docker images

cd /docker/fastai-docker-deploy
docker-compose build

Run the App

After successfully building the docker images you can start / stop the app:

cd /docker/fastai-docker-deploy
# start
docker-compose up -d

# stop
docker-compose down

Adopt project

To use this App with your own fastai image classification model, you have to make some adjustments.

Hostname

The hostname "dog-or-hotdog.meansqua.red" has to be replaced with your hostname in the following files:

nginx-frontend/config/default.config

server {
    listen       80;
    server_name dog-or-hotdog.meansqua.red;


server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name dog-or-hotdog.meansqua.red;

    ssl_certificate /etc/letsencrypt/live/dog-or-hotdog.meansqua.red/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dog-or-hotdog.meansqua.red/privkey.pem;

nginx-html/classify.js

let url = "https://dog-or-hotdog.meansqua.red/api/analyze:predict";

fastai-Model

Copy your exported model (learn.export()) to fastai-rest/app/model.pkl.

The model labels are replaced with a human friendlier text (dog -> Dog and hot_dog -> Hot Dog). Please replace and add all your class labels in nginx-frontend/classes.json.

{
    "dog": "Dog", 
    "hot_dog": "Hot Dog"
}

Add example images for random image classification

Use the python scripts in nginx-frontend/html/examples/ to create an examples.json that is used for the random image classificaiton (click on drop area). Move examples.json to ngnix-frontend/html/examples.json.

Rebuild the docker containers

See "Build docker images" above.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].
OSZAR »