Predictors

Make real-time predictions against SageMaker endpoints with Python objects

class sagemaker.predictor.RealTimePredictor(endpoint, sagemaker_session=None, serializer=None, deserializer=None, content_type=None, accept=None)

Bases: object

Make prediction requests to an Amazon SageMaker endpoint.

Initialize a RealTimePredictor.

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.

Parameters:
  • 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_type attribute 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_type attribute 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_type from the serializer (default: None).
  • accept (str) – The invocation’s “Accept”, overriding any accept from the deserializer (default: None).
predict(data)

Return the inference from the specified endpoint.

Parameters: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.
Returns:
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:object
delete_endpoint()

Delete the Amazon SageMaker endpoint backing this predictor.