Skip to content

Trying to deploy pretrained MXNet model for inference only  #216

Closed
@hubenjm

Description

@hubenjm

I have a model that I've trained in MXNet to classify images, and I already have the model assets saved as
model.tar.gz in an s3 bucket.

from sagemaker.mxnet.model import MXNetModel
import sagemaker
import sys
from sagemaker import get_execution_role
role = get_execution_role()
sagemaker_model = MXNetModel(model_data = 's3://bucket-name/model.tar.gz', 
entry_point='entry_point.py', #entry_point.py is an empty .py file since we aren't using for training
role = role)
predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge')

I just want to be able to deploy this within a sagemaker notebook to a host and then call the predictor.predict function on an input image. However, the above sagemaker_model.deploy call fails and yields following error message:

ValueErrorTraceback (most recent call last)
in ()
----> 1 predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge')

/home/ec2-user/anaconda3/envs/mxnet_p27/lib/python2.7/site-packages/sagemaker/model.pyc in deploy(self, initial_instance_count, instance_type, endpoint_name)
90 production_variant = sagemaker.production_variant(model_name, instance_type, initial_instance_count)
91 self.endpoint_name = endpoint_name or model_name
---> 92 self.sagemaker_session.endpoint_from_production_variants(self.endpoint_name, [production_variant])
93 if self.predictor_cls:
94 return self.predictor_cls(self.endpoint_name, self.sagemaker_session)

/home/ec2-user/anaconda3/envs/mxnet_p27/lib/python2.7/site-packages/sagemaker/session.pyc in endpoint_from_production_variants(self, name, production_variants, wait)
512 self.sagemaker_client.create_endpoint_config(
513 EndpointConfigName=name, ProductionVariants=production_variants)
--> 514 return self.create_endpoint(endpoint_name=name, config_name=name, wait=wait)
515
516 def expand_role(self, role):

/home/ec2-user/anaconda3/envs/mxnet_p27/lib/python2.7/site-packages/sagemaker/session.pyc in create_endpoint(self, endpoint_name, config_name, wait)
344 self.sagemaker_client.create_endpoint(EndpointName=endpoint_name, EndpointConfigName=config_name)
345 if wait:
--> 346 self.wait_for_endpoint(endpoint_name)
347 return endpoint_name
348

/home/ec2-user/anaconda3/envs/mxnet_p27/lib/python2.7/site-packages/sagemaker/session.pyc in wait_for_endpoint(self, endpoint, poll)
405 if status != 'InService':
406 reason = desc.get('FailureReason', None)
--> 407 raise ValueError('Error hosting endpoint {}: {} Reason: {}'.format(endpoint, status, reason))
408 return desc
409

ValueError: Error hosting endpoint sagemaker-mxnet-py2-cpu-2018-03-22-20-10-57-938: Failed Reason: The primary container for production variant AllTraffic did not pass the ping health check.

I believe my attempt at using an empty file for the entry_point.py script is the reason this happened. But the problem in that case is that nowhere in the documentation was it clear to me what exactly should be in the entry_point.py script in the case that I just want to perform inference and no training with this model.

My other question is related to what the predictor.predict function actually expects. Do I need to pass it a numpy array? Is there a way to pass a string for the image_url instead and then write some simple image preprocessing script that loads the image, resizes, etc on the host before calling the mxnet model.predict function? I'm concerned that opencv is not part of the endpoint environment by default.

Any help with this would be much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions