Serializers¶
Implements methods for serializing data for an inference endpoint.
-
class
sagemaker.serializers.
BaseSerializer
¶ Bases:
abc.ABC
Abstract base class for creation of new serializers.
Provides a skeleton for customization requiring the overriding of the method serialize and the class attribute CONTENT_TYPE.
-
abstract
serialize
(data)¶ Serialize data into the media type specified by CONTENT_TYPE.
-
abstract property
CONTENT_TYPE
¶ The MIME type of the data sent to the inference endpoint.
-
abstract
-
class
sagemaker.serializers.
CSVSerializer
¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data of various formats to a CSV-formatted string.
-
CONTENT_TYPE
= 'text/csv'¶
-
-
class
sagemaker.serializers.
NumpySerializer
(dtype=None)¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data to a buffer using the .npy format.
Initialize the dtype.
- Parameters
dtype (str) – The dtype of the data.
-
CONTENT_TYPE
= 'application/x-npy'¶
-
class
sagemaker.serializers.
JSONSerializer
¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data to a JSON formatted string.
-
CONTENT_TYPE
= 'application/json'¶
-
-
class
sagemaker.serializers.
IdentitySerializer
(content_type='application/octet-stream')¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data by returning data without modification.
Initialize the
content_type
attribute.- Parameters
content_type (str) – The MIME type of the serialized data (default: “application/octet-stream”).
-
serialize
(data)¶ Return data without modification.
-
property
CONTENT_TYPE
¶ The MIME type of the data sent to the inference endpoint.
-
class
sagemaker.serializers.
JSONLinesSerializer
¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data to a JSON Lines formatted string.
-
CONTENT_TYPE
= 'application/jsonlines'¶
-
serialize
(data)¶ Serialize data of various formats to a JSON Lines formatted string.
-
-
class
sagemaker.serializers.
SparseMatrixSerializer
¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize a sparse matrix to a buffer using the .npz format.
-
CONTENT_TYPE
= 'application/x-npz'¶
-
serialize
(data)¶ Serialize a sparse matrix to a buffer using the .npz format.
Sparse matrices can be in the
csc
,csr
,bsr
,dia
orcoo
formats.- Parameters
data (scipy.sparse.spmatrix) – The sparse matrix to serialize.
- Returns
A buffer containing the serialized sparse matrix.
- Return type
-
-
class
sagemaker.serializers.
LibSVMSerializer
¶ Bases:
sagemaker.serializers.BaseSerializer
Serialize data of various formats to a LibSVM-formatted string.
The data must already be in LIBSVM file format: <label> <index1>:<value1> <index2>:<value2> …
It is suitable for sparse datasets since it does not store zero-valued features.
-
CONTENT_TYPE
= 'text/libsvm'¶
-