Skip to content

Instantly share code, notes, and snippets.

View mvsusp's full-sized avatar

Marcio Vinicius dos Santos mvsusp

View GitHub Profile
@mvsusp
mvsusp / pulling-image.sh
Last active July 19, 2018 16:17
How to docker pull AWS SageMaker public images
#!/usr/bin/env bash
# All the images are available under the AWS account id bellow
ACCOUNT_ID=520713654638
TAG=1.7.0-gpu-py2
# get aws region
REGION=$(aws configure get region)
@mvsusp
mvsusp / list-images.sh
Last active July 19, 2018 16:16
How to access AWS SageMaker public images
#!/usr/bin/env bash
# All the images are available under the AWS account id bellow
SAGEMAKER_ACCOUNT_ID=520713654638
# The available repositories are: sagemaker-tensorflow, sagemaker-mxnet,
# sagemaker-pytorch, sagemaker-chainer
REPOSITORY_NAME=sagemaker-tensorflow
aws ecr list-images --registry-id ${SAGEMAKER_ACCOUNT_ID} \

predictor.predict should be able to handle a dictionary so tf_estimator.predict({"city":"Paris", "gender":"m", "age":22}) is the correct way to send requests like you mentioned above. The predictor logic defined here needs to handle that case.

The container source code is not open sourced yet, we are planning on releasing it very soon. I will open a bug in the container side as well, to improve the logging when the prediction fails.

I have a temporary solution to unblock you until this issue is fixed. The solution is to create a instance of a RealTimePredictor that takes a tensorflow_serving.apis request as parameter instead of a dictionary:

from sagemaker.tensorflow.predictor import tf_serializer, tf_deserializer
@mvsusp
mvsusp / README.md
Last active September 28, 2018 22:00
How to compile and debug TensorFlow
def to_env_vars(mapping): # type: (dict) -> dict
"""Transform a dictionary in a dictionary of env vars.
Example:
>>>env_vars = mapping.to_env_vars({'model_dir': '/opt/ml/model', 'batch_size': 25})
>>>
>>>print(args)
['MODEL_DIR', '/opt/ml/model', 'BATCH_SIZE', 25]
from PIL import Image
import numpy
image_array = numpy.random.rand(224, 224, 3) * 255
# must of the time you wont need to generate a fake image
image = Image.fromarray(imarray.astype('uint8')).convert('RGBA')
image.save('result_image.png')
class ErrorWrapper(object):
def __init__(self, clazz):
self.clazz = clazz
def __missing__(self, fn):
return getattr(self.clazz, fn, None)
wrap_error = ErrorWrapper
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License'). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the 'license' file accompanying this file. This file is
# distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ChannelConfig = namedtuple_with_defaults('ChannelConfig',
dict(ContentType="application/x-numpy", TrainingInputMode="File",
S3DistributionType="FullyReplicated", RecordWrapperType="None"))
@mvsusp
mvsusp / framework_example.py
Last active April 18, 2018 22:12
transformer.py
from __future__ import absolute_import
from keras import Model
import sagemaker_container_support as scs
from sagemaker_container_support.transformer import Transformer
def default_model_fn(model_dir):
return Model.load_weights(model_dir)