Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Tensorflow Serving JSON Response Serialization

From Leeroopedia
Revision as of 17:49, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Tensorflow_Serving_JSON_Response_Serialization.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Data_Serialization, API_Design
Last Updated 2026-02-13 17:00 GMT

Overview

A data conversion process that transforms TensorFlow output tensors into JSON format for REST API responses, preserving type fidelity and matching the request format.

Description

After TensorFlow session execution, output tensors are in TensorProto format (binary protobuf). JSON response serialization converts these back to human-readable JSON. The serialization format mirrors the request format:

  • Row format request{"predictions": [...]} response
  • Columnar format request{"outputs": {...}} response

The serializer handles all TensorFlow data types with special cases:

  • Floats/Doubles: Serialized as JSON numbers with sufficient precision
  • Integers: Serialized as JSON numbers
  • Strings: Serialized as JSON strings; binary strings use {"b64": "..."} encoding
  • Booleans: Serialized as JSON true/false

Error responses follow the format {"error": "<message>"}.

Usage

This serialization is automatically applied to all REST inference responses. The format is determined by the corresponding request format and cannot be overridden independently.

Theoretical Basis

# Abstract response serialization (NOT real implementation)
def serialize_response(tensor_map, request_format):
    if request_format == ROW:
        # {"predictions": [[0.1, 0.9], [0.8, 0.2]]}
        return {"predictions": interleave_tensors(tensor_map)}
    elif request_format == COLUMNAR:
        # {"outputs": {"scores": [[0.1, 0.9], [0.8, 0.2]]}}
        return {"outputs": {name: tensor_to_json(t) for name, t in tensor_map}}

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment