Smile Innovation
Published in

Smile Innovation

SageMaker : Bring your own Algorithms

With the help of Docker, you will be able to customize training and infering models using other frameworks that those provided by SageMaker

Photo by chuttersnap on Unsplash

And thanks to SageMaker using Docker!

SageMaker train, deploy and use

Create Docker image

├── Dockerfile
├── local_test
│ ├──
│ ├──
│ ├──
│ └── test_dir => /opt/ml in container
│ ├── input
│ │ ├── config
│ │ └── data
│ │ └── training
│ ├── model
│ └── output
└── program
├── (some scripts...)
├── train
└── serve
FROM nvidia/cuda:9.0-base-ubuntu16.04
ENV PATH=/program:${PATH}
ADD program /program
RUN chmod +x /program/train /program/serve
class ScoringService(object):
model = None # Where we keep the model when it's loaded
graph = None
def get_model(cls):
if cls.model is None:
cls.model = load_model(
os.path.join(model_path, 'model.h5'))
cls.graph = K.get_session().graph
return cls.model
def predict(cls, input):
clf = cls.get_model()
with cls.graph.as_default():
return clf.predict(input)
docker build -t sagemaker-test .

Prepare Docker image and test your code on your computer

docker run --rm -v $(pwd)/test_dir:/opt/ml sagemaker-test train

Now that the image is ready, let’s test it locally

docker run --rm -v $(pwd)/test_dir:/opt/ml -p 8080:8080 sagemaker-test serve

And now, make a test!

Now, let’s push it to AWS SageMaker

./ sagemaker-test
predictor = tree.deploy(initial_instance_count=1,
res = predictor.predict(some_data)

Using our API outside the notebook

Burger and Salad recognition

Winding up




A series of articles about innovative technologies we try @ Smile

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Patrice Ferlet

R&D engineer for Innovation Dept. at group. Coding in Golang, Python — Devops, Machine Learning, cloud computing…