Deserializers¶
Implements methods for deserializing data returned from an inference endpoint.
-
class
sagemaker.deserializers.BaseDeserializer¶ Bases:
abc.ABCAbstract base class for creation of new deserializers.
Provides a skeleton for customization requiring the overriding of the method deserialize and the class attribute ACCEPT.
-
abstract
deserialize(stream, content_type)¶ Deserialize data received from an inference endpoint.
-
abstract property
ACCEPT¶ The content types that are expected from the inference endpoint.
-
abstract
-
class
sagemaker.deserializers.StringDeserializer(encoding='UTF-8')¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize data from an inference endpoint into a decoded string.
Initialize the string encoding.
- Parameters
encoding (str) – The string encoding to use (default: UTF-8).
-
ACCEPT= ('application/json',)¶
-
class
sagemaker.deserializers.BytesDeserializer¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize a stream of bytes into a bytes object.
-
ACCEPT= ('*/*',)¶
-
-
class
sagemaker.deserializers.CSVDeserializer(encoding='utf-8')¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize a stream of bytes into a list of lists.
Initialize the string encoding.
- Parameters
encoding (str) – The string encoding to use (default: “utf-8”).
-
ACCEPT= ('text/csv',)¶
-
deserialize(stream, content_type)¶ Deserialize data from an inference endpoint into a list of lists.
-
class
sagemaker.deserializers.StreamDeserializer¶ Bases:
sagemaker.deserializers.BaseDeserializerReturns the data and content-type received from an inference endpoint.
It is the user’s responsibility to close the data stream once they’re done reading it.
-
ACCEPT= ('*/*',)¶
-
deserialize(stream, content_type)¶ Returns a stream of the response body and the MIME type of the data.
-
-
class
sagemaker.deserializers.NumpyDeserializer(dtype=None, accept='application/x-npy', allow_pickle=True)¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize a stream of data in the .npy format.
Initialize the dtype and allow_pickle arguments.
- Parameters
-
deserialize(stream, content_type)¶ Deserialize data from an inference endpoint into a NumPy array.
- Parameters
stream (botocore.response.StreamingBody) – Data to be deserialized.
content_type (str) – The MIME type of the data.
- Returns
The data deserialized into a NumPy array.
- Return type
numpy.ndarray
-
property
ACCEPT¶ The content types that are expected from the inference endpoint.
To maintain backwards compatability with legacy images, the NumpyDeserializer supports sending only one content type in the Accept header.
-
class
sagemaker.deserializers.JSONDeserializer¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize JSON data from an inference endpoint into a Python object.
-
ACCEPT= ('application/json',)¶
-
deserialize(stream, content_type)¶ Deserialize JSON data from an inference endpoint into a Python object.
-
-
class
sagemaker.deserializers.PandasDeserializer¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize CSV or JSON data from an inference endpoint into a pandas dataframe.
-
ACCEPT= ('text/csv', 'application/json')¶
-
deserialize(stream, content_type)¶ Deserialize CSV or JSON data from an inference endpoint into a pandas dataframe.
If the data is JSON, the data should be formatted in the ‘columns’ orient. See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_json.html
- Parameters
stream (botocore.response.StreamingBody) – Data to be deserialized.
content_type (str) – The MIME type of the data.
- Returns
The data deserialized into a pandas DataFrame.
- Return type
pandas.DataFrame
-
-
class
sagemaker.deserializers.JSONLinesDeserializer¶ Bases:
sagemaker.deserializers.BaseDeserializerDeserialize JSON lines data from an inference endpoint.
-
ACCEPT= ('application/jsonlines',)¶
-
deserialize(stream, content_type)¶ Deserialize JSON lines data from an inference endpoint.
See https://docs.python.org/3/library/json.html#py-to-json-table to understand how JSON values are converted to Python objects.
-