Serializers#
- class pai.serializers.SerializerBase#
基类:
ABC
Abstract class for creating a Serializer class for predictor.
- abstract serialize(data) bytes #
Serialize the input data to bytes for transmitting.
- abstract deserialize(data: bytes)#
Deserialize the data from raw bytes to Python object .
- inspect_from_service(service_name: str, *, session: Optional[Session] = None)#
Inspect the online prediction service to complete the serializer instance initialization.
The implementation of the inspect_from_service method is optional. You only need to implement it if your serializer requires additional information from service metadata or if it needs to send a request to the service in order to be initialized.
- class pai.serializers.JsonSerializer#
-
A Serializer object that serialize input data into JSON format and deserialize JSON formatted data into python object.
- serialize(data) bytes #
Serialize the input data to bytes for transmitting.
- deserialize(data)#
Deserialize the data from raw bytes to Python object .
- class pai.serializers.TensorFlowSerializer#
-
A Serializer class that responsible for transforming input/output data for TensorFlow processor service.
TensorflowSerializer initializer.
- inspect_from_service(service_name: str, *, session: Optional[Session] = None)#
Inspect the service to complete serializer instance initialization.
- 参数:
service_name (str) -- Name of the online prediction service.
session (
pai.session.Session
) -- A PAI session instance used for communicating with PAI services.
- classmethod inspect_model_signature_def(service_name: str, *, session: Optional[Session] = None) Dict[str, Any] #
Inspect the TensorFlow serving model signature by sending a request to the service.
TensorFlow processor creates a prediction service and exposes an HTTP API for model signature definition.
Example API returns:
{ "signature_name": "serving_default", "inputs": [ { "name": "flatten_input", "shape": [ -1, 28, 28 ], "type": "DT_FLOAT" } ], "outputs": [ { "name": "dense_1", "shape": [ -1, 10 ], "type": "DT_FLOAT" } ] }
- 返回:
A dictionary that represents the model signature definition.
- serialize(data: Union[Dict[str, Any], PredictRequest]) bytes #
Serialize the input data to bytes for transmitting.
- deserialize(data: bytes)#
Deserialize the data from raw bytes to Python object .
- class pai.serializers.PyTorchSerializer#
-
A serializer responsible for transforming input/output data for PyTorch processor service.
- serialize(data: Union[ndarray, List, Tuple]) bytes #
Serialize the input data to bytes for transmitting.
- deserialize(data: bytes)#
Deserialize the data from raw bytes to Python object .