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.

Implementation:Tensorflow Serving FillPredictRequestFromJson

From Leeroopedia
Revision as of 13:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Tensorflow_Serving_FillPredictRequestFromJson.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

Concrete tool for parsing JSON request bodies into PredictRequest protobufs with typed TensorProto values, provided by the json_tensor module.

Description

FillPredictRequestFromJson() is the primary entry point for JSON-to-tensor conversion. It:

  1. Parses the JSON string using RapidJSON
  2. Extracts the optional signature_name field
  3. Determines input format (row vs columnar) based on top-level key ("instances" or "inputs")
  4. Delegates to FillTensorMapFromInstancesList() (row) or FillTensorMapFromInputsMap() (columnar)
  5. These call FillTensorProto() and AddValueToTensor() for type-specific tensor population

The function uses a get_tensorinfo_map callback to look up tensor type information from the model's SignatureDef, ensuring values are converted to the correct DT_* type.

Usage

Called internally by HttpRestApiHandler::ProcessPredictRequest(). Not called directly by users; invoked automatically when processing REST predict requests.

Code Reference

Source Location

  • Repository: tensorflow/serving
  • File: tensorflow_serving/util/json_tensor.cc
  • Lines: L653-705 (FillPredictRequestFromJson), L519-607 (FillTensorMapFromInstancesList), L609-649 (FillTensorMapFromInputsMap), L392-436 (FillTensorProto), L290-342 (AddValueToTensor)
  • Header: tensorflow_serving/util/json_tensor.h L145-150

Signature

tensorflow::Status FillPredictRequestFromJson(
    const absl::string_view json,
    const std::function<
        tensorflow::Status(
            const string& signature_name,
            ::google::protobuf::Map<string, tensorflow::TensorInfo>* infomap
        )>& get_tensorinfo_map,
    PredictRequest* request,
    JsonPredictRequestFormat* format
);

Import

#include "tensorflow_serving/util/json_tensor.h"

I/O Contract

Inputs

Name Type Required Description
json string_view Yes Raw JSON request body
get_tensorinfo_map function Yes Callback returning tensor type info for a signature
format JsonPredictRequestFormat* Yes Output indicator (kRow or kColumnar)

Outputs

Name Type Description
request PredictRequest* Populated proto with inputs map of TensorProto values
format JsonPredictRequestFormat kRow for "instances" format, kColumnar for "inputs" format

Usage Examples

Row Format Request

curl -d '{"instances": [[1.0, 2.0, 3.0, 4.0]]}' \
    http://localhost:8501/v1/models/mnist:predict

Columnar Format Request

curl -d '{"inputs": {"images": [[1.0, 2.0, 3.0, 4.0]]}}' \
    http://localhost:8501/v1/models/mnist:predict

With Signature Name

curl -d '{
    "signature_name": "predict_images",
    "instances": [[1.0, 2.0, 3.0, 4.0]]
}' http://localhost:8501/v1/models/mnist:predict

Related Pages

Implements Principle

Page Connections

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