class sagemaker.model.Model(model_data, image, role, predictor_cls=None, env=None, name=None, sagemaker_session=None)

Bases: object

A SageMaker Model that can be deployed to an Endpoint.

Initialize an SageMaker Model.

  • model_data (str) – The S3 location of a SageMaker model data .tar.gz file.
  • image (str) – A Docker image URI.
  • role (str) – An AWS IAM role (either name or full ARN). The Amazon SageMaker training jobs and APIs that create Amazon SageMaker endpoints use this role to access training data and model artifacts. After the endpoint is created, the inference code might use the IAM role, if it needs to access an AWS resource.
  • predictor_cls (callable[string, sagemaker.session.Session]) – A function to call to create a predictor (default: None). If not None, deploy will return the result of invoking this function on the created endpoint name.
  • env (dict[str, str]) – Environment variables to run with image when hosted in SageMaker (default: None).
  • name (str) – The model name. If None, a default model name will be selected on each deploy.
  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

Return a dict created by sagemaker.container_def() for deploying this model to a specified instance type.

Subclasses can override this to provide custom container definitions for deployment to a specific instance type. Called by deploy().

Parameters:instance_type (str) – The EC2 instance type to deploy this Model to. For example, ‘ml.p2.xlarge’.
Returns:A container definition object usable with the CreateModel API.
Return type:dict
deploy(initial_instance_count, instance_type, endpoint_name=None, tags=None)

Deploy this Model to an Endpoint and optionally return a Predictor.

Create a SageMaker Model and EndpointConfig, and deploy an Endpoint from this Model. If self.predictor_cls is not None, this method returns a the result of invoking self.predictor_cls on the created endpoint name.

The name of the created endpoint is accessible in the endpoint_name field of this Model after deploy returns.

  • instance_type (str) – The EC2 instance type to deploy this Model to. For example, ‘ml.p2.xlarge’.
  • initial_instance_count (int) – The initial number of instances to run in the Endpoint created from this Model.
  • endpoint_name (str) – The name of the endpoint to create (default: None). If not specified, a unique endpoint name will be created.
  • tags (list[dict[str, str]]) – A list of key-value pairs for tagging the endpoint (default: None).

Invocation of self.predictor_cls on

the created endpoint name, if self.predictor_cls is not None. Otherwise, return None.

Return type:

callable[string, sagemaker.session.Session] or None