The goal of this project is to use a cookiecutter format to develop a machine learning development and deployment environment. This project will be dockerized and pushed to github for easy reproduction of the model.
This document outlines the setup of a ML development environment that is customizable for the problem/solution needs and create a skeleton for deployment on AWS using Sagemaker. The container built here will have tensorflow, AWS CLI, and Sagemaker as its main packages, open Jupyter notebook for model development.
Installation Requirements: The following packages are required on the machine to get started:
Git - Version Management - https://git-scm.com/book/en/v2/Getting-Started-Installing-Git * Github Desktop could also be used
Anaconda - Package Manager - https://docs.anaconda.com/anaconda/install * Please note: The steps outlined below do not use Anaconda explicitly: This is to manage your local packages if just using cookie cutter on your local host environment.
Cookie Cutter - https://cookiecutter.readthedocs.io/en/1.7.2/installation.html * Cookiecutter has Sphinx documentation needs built into the format. However, the code in the Jupyter Notebooks in this demo is not written in Object Oriented form, the Sphinx documentation capabilities have not been leveraged.
Docker - Containerized Environment Ecosystem- https://www.docker.com/products/docker-desktop
Getting Started: Git Clone the repository located here: This repository has all the docker components needed to create a base container for development and has sample notebooks for worked out examples.
$ git clone
Change working directory to the cloned project folder directory. A list of file contents would look like so:
'.env',
'.gitignore'
'data',
'docker-compose.yml',
'Dockerfile',
'docs',
'LICENSE',
'Makefile',
'models',
'new_user_credentials.csv',
'notebooks',
'README.md',
'references',
'reports',
'requirements.txt',
'setup.py',
'src',
'startup.sh',
'test_environment.py',
'tox.ini'\
AWS You will need an AWS account to be able complete this tutorial:
1. Go to AWS IAm : https://aws.amazon.com/iam/
2. Sign into the Console and create a new user with full Sagemaker and S3 access.
3. Save the User credential CSV in the project directory with the dockerfile and docker-compose.yml.
1. (If not named new_user_credentials.csv , modify the filename in the startup.sh file to your CSV name)\
4. Create a role with "AmazonSagemakerFullAccess" policy
1. Keep the name of this role handy to use in Jupyter Notebook : The notebook will prompt you for this name
Docker We will now build the docker image needed: For more detailed understanding of Docker, see the Docker 101 Documentation.
Check Documentation-ZD/Documentation Machine Learning.html for changes that may be needed to the files
-To build the docker image:
$docker-compose build
-Note: The building image may take time. Tensorflow installation with dependencies is a large installation.
- Once docker image has been built you may check the image with:
$docker images
- To run the container:
$docker-compose up
-The ml_development image will be instantiated, the startup.sh will print your AWS CLI version, log you into AWS CLI, list your partial credentials and open Jupyter notebook.
- Navigate to localhost:8888 or use one of the links in CMD output in a browser to open Jupyter notebook.
- Copy paste the token from the CMD output if prompted.
In Jupyter Notebooks navigate to the notebooks folder for a two sample notebooks.
1. The online version is to be used if trying to create an online Sagemaker notebook instance. This requires no local installation and all steps to instantiate are outlined in the AWS- SageMaker-Online Notebook documentation.
2. The local version is to be used if trying to create a local notebook but run training/deployment on AWS EC through Sagemaker
1. This notebook outlines
- creating a model, training and deployment through Python SDK
- creating a model, training and deployment through Boto3
- Uploading a custom model into Sagemaker and deployment
*
Note: This shows how a custom Keras model can be used in Sagemaker but the model predictions are invalid as the input is not processed in the same way as the model was initially trained
Resources:
- Sagemaker
- Build, Train and Deploy Machine Learning Models on AWS with Amazon SageMaker - AWS Online Tech Talks - Guide to Using Sagemaker Notebooks Online (Youtube)
- Sagemaker Official Docs:
- Get Started with Amazon SageMaker Notebook Instances and SDKs - MNIST dataset example - See AWS Online Tutorial for written summary of content (Documentation)
- Sagemaker AWS CLI v2 Documentation - APIs for creating and managing Amazon SageMaker resources (Documentation)
- Bring your own pre-trained MXNet or TensorFlow models into Amazon SageMaker - Load a prebuilt cluster on Sagemaker (Documentation + Code)
- Deploy trained Keras or TensorFlow models using Amazon SageMaker - Load a Keras Model on Sagemaker : Demonstrated in Local Notebook (Documentation + Code)
- Automatically Scale Amazon SageMaker Models - How to set instances to autoscale on Sagemaker Models for AWS CLI and in Console (Documentation + Code)
- Model to Cloud Methods
- Simple way to deploy machine learning models to cloud - Create Containerized Flask service and deploy to EC2 (Documentation + Code)
- How to deploy machine learning models into production - Various possibilities and best practices to bring machine learning models into production environments (Youtube)
- Docker
- Docker Tutorial for Beginners - A Full DevOps Course on How to Run Applications in Containers - Full course on Docker - See Docker Document for written summary of content (Youtube)
- Why You Need to Containerize Machine Learning Models - Intro to Docker and how to use for containerized ML (Youtube)
├── LICENSE
├── Makefile <- Makefile with commands like `make data` or `make train`
├── README.md <- The top-level README for developers using this project.
├── data
│ ├── external <- Data from third party sources.
│ ├── interim <- Intermediate data that has been transformed.
│ ├── processed <- The final, canonical data sets for modeling.
│ └── raw <- The original, immutable data dump.
│
├── docs <- A default Sphinx project; see sphinx-doc.org for details
│
├── models <- Trained and serialized models, model predictions, or model summaries
│
├── notebooks <- Jupyter notebooks. Naming convention is a number (for ordering),
│ the creator's initials, and a short `-` delimited description, e.g.
│ `1.0-jqp-initial-data-exploration`.
│
├── references <- Data dictionaries, manuals, and all other explanatory materials.
│
├── reports <- Generated analysis as HTML, PDF, LaTeX, etc.
│ └── figures <- Generated graphics and figures to be used in reporting
│
├── requirements.txt <- The requirements file for reproducing the analysis environment, e.g.
│ generated with `pip freeze > requirements.txt`
│
├── setup.py <- makes project pip installable (pip install -e .) so src can be imported
├── src <- Source code for use in this project.
│ ├── __init__.py <- Makes src a Python module
│ │
│ ├── data <- Scripts to download or generate data
│ │ └── make_dataset.py
│ │
│ ├── features <- Scripts to turn raw data into features for modeling
│ │ └── build_features.py
│ │
│ ├── models <- Scripts to train models and then use trained models to make
│ │ │ predictions
│ │ ├── predict_model.py
│ │ └── train_model.py
│ │
│ └── visualization <- Scripts to create exploratory and results oriented visualizations
│ └── visualize.py
│
└── tox.ini <- tox file with settings for running tox; see tox.readthedocs.io
Project based on the cookiecutter data science project template. #cookiecutterdatascience