def create_model(self, role=None, predictor_cls=None, serializer=IdentitySerializer(), deserializer=BytesDeserializer(), vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT, **kwargs): """Create a model to deploy. The serializer and deserializer are only used to define a default Predictor. They are ignored if an explicit predictor class is passed in. Other arguments are passed through to the Model class. Args: role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during transform jobs. If not specified, the role from the Estimator will be used. predictor_cls (Predictor): The predictor class to use when deploying the model. serializer (:class:`~sagemaker.serializers.BaseSerializer`): A serializer object, used to encode data for an inference endpoint (default: :class:`~sagemaker.serializers.IdentitySerializer`). deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A deserializer object, used to decode data from an inference endpoint (default: :class:`~sagemaker.deserializers.BytesDeserializer`). vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on the model. Default: use subnets and security groups from this Estimator. * 'Subnets' (list[str]): List of subnet ids. * 'SecurityGroupIds' (list[str]): List of security group ids. **kwargs: Additional arguments for creating a :class:`~sagemaker.model.ModelPackage`. .. tip:: You can find additional parameters for using this method at :class:`~sagemaker.model.ModelPackage` and :class:`~sagemaker.model.Model`. Returns: a Model ready for deployment. """ removed_kwargs("content_type", kwargs) removed_kwargs("accept", kwargs) if predictor_cls is None: def predict_wrapper(endpoint, session): return Predictor(endpoint, session, serializer, deserializer) predictor_cls = predict_wrapper role = role or self.role return sagemaker.ModelPackage( role, algorithm_arn=self.algorithm_arn, model_data=self.model_data, vpc_config=self.get_vpc_config(vpc_config_override), sagemaker_session=self.sagemaker_session, predictor_cls=predictor_cls, **kwargs)
def create_model(self, role=None, predictor_cls=None, serializer=None, deserializer=None, content_type=None, accept=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT, **kwargs): """Create a model to deploy. The serializer, deserializer, content_type, and accept arguments are only used to define a default RealTimePredictor. They are ignored if an explicit predictor class is passed in. Other arguments are passed through to the Model class. Args: role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during transform jobs. If not specified, the role from the Estimator will be used. predictor_cls (RealTimePredictor): The predictor class to use when deploying the model. serializer (callable): Should accept a single argument, the input data, and return a sequence of bytes. May provide a content_type attribute that defines the endpoint request content type deserializer (callable): Should accept two arguments, the result data and the response content type, and return a sequence of bytes. May provide a content_type attribute that defines the endpoint response Accept content type. content_type (str): The invocation ContentType, overriding any content_type from the serializer accept (str): The invocation Accept, overriding any accept from the deserializer. vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on the model. Default: use subnets and security groups from this Estimator. * 'Subnets' (list[str]): List of subnet ids. * 'SecurityGroupIds' (list[str]): List of security group ids. **kwargs: Returns: a Model ready for deployment. """ if predictor_cls is None: def predict_wrapper(endpoint, session): return RealTimePredictor(endpoint, session, serializer, deserializer, content_type, accept) predictor_cls = predict_wrapper role = role or self.role return sagemaker.ModelPackage( role, algorithm_arn=self.algorithm_arn, model_data=self.model_data, vpc_config=self.get_vpc_config(vpc_config_override), sagemaker_session=self.sagemaker_session, predictor_cls=predictor_cls, **kwargs)
#USE PPE Detector for Laboratory Safety #Initializing a model using AWS SageMaker Python API import sagemaker as sage from sagemaker import get_execution_role sess = sage.Session() role = get_execution_role() # from utils import get_model_package_arn # model_package_arn = get_model_package_arn(sess.boto_region_name) model_package_arn = 'arn:aws:sagemaker:us-east-2:057799348421:model-package/vitechlab-ppe-lab-model-v1-1-480cb3fc5bd97e9bf1e213cca498bbc4' model = sage.ModelPackage( role=role, model_package_arn=model_package_arn) #Generating Prediction using RealTimePredictor #Creating end point #endpoint_name='ppe-lab-model-example-endpoint' endpoint_name='ppe-covid19-endpoint' model.deploy(initial_instance_count=1, instance_type='ml.m4.2xlarge', endpoint_name=endpoint_name) #Generating Prediction predictor = sage.predictor.RealTimePredictor( endpoint_name, sagemaker_session=sess, content_type="image/jpeg" )