Make real-time predictions against SageMaker endpoints with Python objects
RealTimePredictor(endpoint, sagemaker_session=None, serializer=None, deserializer=None, content_type=None, accept=None)¶
Make prediction requests to an Amazon SageMaker endpoint.
Behavior for serialization of input data and deserialization of result data can be configured through initializer arguments. If not specified, a sequence of bytes is expected and the API sends it in the request body without modifications. In response, the API returns the sequence of bytes from the prediction result without any modifications.
endpoint (str) – Name of the Amazon SageMaker endpoint to which requests are sent.
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.
serializer (callable) – Accepts a single argument, the input data, and returns a sequence of bytes. It may provide a
content_typeattribute that defines the endpoint request content type. If not specified, a sequence of bytes is expected for the data.
deserializer (callable) – Accepts two arguments, the result data and the response content type, and returns a sequence of bytes. It may provide a
content_typeattribute that defines the endpoint response’s “Accept” content type. If not specified, a sequence of bytes is expected for the data.
content_type (str) – The invocation’s “ContentType”, overriding any
content_typefrom the serializer (default: None).
accept (str) – The invocation’s “Accept”, overriding any accept from the deserializer (default: None).
predict(data, initial_args=None, target_model=None, target_variant=None)¶
Return the inference from the specified endpoint.
data (object) – Input data for which you want the model to provide inference. If a serializer was specified when creating the RealTimePredictor, the result of the serializer is sent as input data. Otherwise the data must be sequence of bytes, and the predict method then sends the bytes in the request body as is.
target_model (str) – S3 model artifact path to run an inference request on, in case of a multi model endpoint. Does not apply to endpoints hosting single model (Default: None)
target_variant (str) – The name of the production variant to run an inference
on (Default (request) – None). Note that the ProductionVariant identifies the model
want to host and the resources you want to deploy for hosting it. (you) –
- Inference for the given input. If a deserializer was specified when creating
the RealTimePredictor, the result of the deserializer is returned. Otherwise the response returns the sequence of bytes as is.
- Return type
Delete the Amazon SageMaker endpoint backing this predictor. Also delete the endpoint configuration attached to it if delete_endpoint_config is True.
delete_endpoint_config (bool, optional) – Flag to indicate whether to delete endpoint configuration together with endpoint. Defaults to True. If True, both endpoint and endpoint configuration will be deleted. If False, only endpoint will be deleted.
Deletes the Amazon SageMaker models backing this predictor.
Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint to enable data capture. For a more customized experience, refer to update_data_capture_config, instead.
Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint to disable data capture. For a more customized experience, refer to update_data_capture_config, instead.
Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint with the provided DataCaptureConfig.
data_capture_config (sagemaker.model_monitor.DataCaptureConfig) – The DataCaptureConfig to update the predictor’s endpoint to use.
Generates ModelMonitor objects (or DefaultModelMonitors) based on the schedule(s) associated with the endpoint that this predictor refers to.
- A list of
ModelMonitor (or DefaultModelMonitor) objects.
- Return type