Support for Common Data Types
When using Chassis, you must define a predict function that serves as your model inference function. This function may include one or multiple input parameters, depending on your model. This parameter will always be a mapping of str to bytes (i.e., Mapping[str, bytes]), which means the beginning of your process function must account for this and be able to convert it to the expected data type for your model. This guide includes examples of how to decode raw bytes for common data types.
Assume input is the key that represents a single input to your model in the mapping of str to bytes as your predict parameter.
Text
Imagery
OpenCV
import json
from typing import Mapping
def predict(input_data: Mapping[str, bytes]) -> dict(str, bytes):
img = cv2.imdecode(np.frombuffer(input_data['input'], np.uint8), -1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
'''
Perform processing and inference on img
'''
return {"results.json": json.dumps(output).encode()}
Pillow
See also: