Principle:Kserve Kserve Data Transformation
| Knowledge Sources | |
|---|---|
| Domains | MLOps, Data_Processing, Model_Serving |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
A preprocessing and postprocessing pattern that transforms raw input data into model-compatible tensor formats before prediction, and converts model outputs into application-friendly responses.
Description
Data Transformation enables KServe to handle raw, unstructured, or domain-specific input formats by inserting transformation logic between the client and the predictor. Transformers are deployed as separate containers (either as part of an InferenceService transformer spec or as standalone services in an InferenceGraph) and handle the impedance mismatch between client-supplied data and model-expected tensor formats.
Common transformation patterns include:
- Image preprocessing -- decoding raw images (JPEG, PNG), resizing, normalizing pixel values, and converting to tensor format expected by vision models.
- Event-driven transformation -- consuming messages from event sources (e.g., Kafka topics), transforming payloads, and forwarding to predictors.
- Feature engineering -- extracting features from structured data, encoding categorical variables, or applying domain-specific transformations.
Transformers implement a standard interface with preprocess() and postprocess() methods, allowing the same transformation logic to be reused across different models.
Usage
Use this principle when:
- Models expect preprocessed tensor inputs but clients send raw data (images, text, events)
- Building event-driven inference pipelines with Kafka or other message sources
- Inference inputs require domain-specific feature extraction
- Post-processing is needed to convert raw model outputs into structured responses
Theoretical Basis
# Data transformation pipeline (NOT implementation code)
Transformer interface:
preprocess(raw_input) → model_input
postprocess(model_output) → client_response
Request flow with transformer:
1. Client sends raw data (e.g., base64-encoded image, Kafka event)
2. Transformer.preprocess():
- Decode raw format (base64 → bytes → image)
- Resize/normalize (224x224, mean subtraction, scale to [0,1])
- Convert to tensor format matching model input spec
3. Transformed input forwarded to Predictor
4. Predictor returns raw model output (logits, probabilities)
5. Transformer.postprocess():
- Map indices to class labels
- Apply confidence thresholds
- Format as structured response
6. Final response returned to client
Event-driven variant (Kafka source):
Kafka Topic → CloudEvent → Transformer → Predictor → Response
- Transformer receives CloudEvent with payload
- Extracts and transforms payload
- Calls predictor synchronously
- Optionally publishes result to output topic
Related Pages
Implemented By
- Implementation:Kserve_Kserve_Kafka_ImageTransformer
- Implementation:Kserve_Kserve_Paddle_Image_Preprocess