Model¶
-
class
sagemaker.model.Model(model_data, image, role, predictor_cls=None, env=None, name=None, sagemaker_session=None)¶ Bases:
objectA SageMaker
Modelthat can be deployed to anEndpoint.Initialize an SageMaker
Model.Parameters: - model_data (str) – The S3 location of a SageMaker model data
.tar.gzfile. - 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,
deploywill return the result of invoking this function on the created endpoint name. - env (dict[str, str]) – Environment variables to run with
imagewhen 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.
-
prepare_container_def(instance_type)¶ 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
Modelto anEndpointand optionally return aPredictor.Create a SageMaker
ModelandEndpointConfig, and deploy anEndpointfrom thisModel. Ifself.predictor_clsis not None, this method returns a the result of invokingself.predictor_clson the created endpoint name.The name of the created endpoint is accessible in the
endpoint_namefield of thisModelafter deploy returns.Parameters: - 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
Endpointcreated from thisModel. - 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).
Returns: - Invocation of
self.predictor_clson the created endpoint name, if
self.predictor_clsis not None. Otherwise, return None.
Return type: callable[string, sagemaker.session.Session] or None
- model_data (str) – The S3 location of a SageMaker model data