Skip to content

Instantly share code, notes, and snippets.

View mvsusp's full-sized avatar

Marcio Vinicius dos Santos mvsusp

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mvsusp
mvsusp / predict.java
Last active January 27, 2022 22:09
How to make predictions against a SageMaker endpoint
package org.example.basicapp;
import com.amazonaws.services.sagemakerruntime.AmazonSageMakerRuntime;
import com.amazonaws.services.sagemakerruntime.AmazonSageMakerRuntimeClientBuilder;
import com.amazonaws.services.sagemakerruntime.model.InvokeEndpointRequest;
import com.amazonaws.services.sagemakerruntime.model.InvokeEndpointResult;
import java.nio.ByteBuffer;
public class App
@mvsusp
mvsusp / create-endpoint.sh
Last active July 22, 2018 19:39
How to create an AWS SageMaker endpoint for predictions - creating the endpoint
#!/usr/bin/env bash
MODEL_NAME=half-plus-three-v1
ENDPOINT_CONFIG_NAME=half-plus-three-config-v1
ENDPOINT_NAME=half-plus-three
PRODUCTION_VARIANTS="VariantName=Default,ModelName=${MODEL_NAME},"\
"InitialInstanceCount=1,InstanceType=ml.c4.large"
@mvsusp
mvsusp / create-model.sh
Last active July 22, 2018 19:30
How to create an AWS SageMaker endpoint for predictions - creating a model
#!/usr/bin/env bash
MODEL_NAME=half-plus-three-v1
# the role named created with
# https://gist.github.com/mvsusp/599311cb9f4ee1091065f8206c026962
ROLE_NAME=SageMakerRole
# the name of the image created with
# https://gist.github.com/mvsusp/07610f9cfecbec13fb2b7c77a2e843c4
@mvsusp
mvsusp / create-role.sh
Last active July 22, 2018 18:41
How to create a SageMaker Execution role
#!/usr/bin/env bash
# This script creates a role named SageMakerRole
# that can be used by SageMaker and has Full access to S3.
ROLE_NAME=SageMakerRole
# WARNING: this policy gives full S3 access to container that
# is running in SageMaker. You can change this policy to a more
# restrictive one, or create your own policy.
@mvsusp
mvsusp / push.sh
Last active July 25, 2018 04:08
How to push a Docker image to AWS ECS
#!/usr/bin/env bash
IMAGE_NAME=sagemaker-tf-serving
REGION=$(aws configure get region)
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
# If the ECS repository doesn't exist, creates it.
aws ecr create-repository --repository-name ${IMAGE_NAME} > /dev/null 2>&1
# ECR requires the image name to be in this format:
@mvsusp
mvsusp / build.sh
Last active July 21, 2018 22:02
How to host a TensorFlow or Keras model in AWS SageMaker - Building the image and testing the container
#!/usr/bin/env bash
docker build -t sagemaker-byoc-tf-serving .
@mvsusp
mvsusp / nginx.conf
Last active July 21, 2018 21:55
How to host a TensorFlow or Keras model in AWS SageMaker - nginx.conf
events {
# determines how many requests can simultaneously be served
# https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
# for more information
worker_connections 2048;
}
http {
server {
# configures the server to listen to the port 8080
@mvsusp
mvsusp / Dockerfile
Created July 21, 2018 20:58
Creating the Docker container
# Using the official tensorflow serving image from docker hub as base image
FROM tensorflow/serving
# Installing NGINX, used to rever proxy the predictions from SageMaker to TF Serving
RUN apt-get update && apt-get install -y --no-install-recommends nginx git
# Copy our model folder to the container
COPY saved_model_half_plus_three /saved_model_half_plus_three
# Copy NGINX configuration to the container
@mvsusp
mvsusp / download_saved_model_half_plus_three.sh
Last active July 21, 2018 22:12
Downloading saved_model_half_plus_three
git clone --single-branch -b r1.9 https://github.com/tensorflow/serving.git /tmp/serving
cp -r \
/tmp/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three \
saved_model_half_plus_three