Encoded Image Inputs via KServe API#
OVMS can accept encoded image files, such as JPEG or PNG, directly as KServe inputs to a single model or a DAG pipeline. The client sends the file bytes instead of decoding them into a numeric array. OVMS decodes each image and prepares a tensor for the model, including resizing and precision conversion when applicable. This can reduce client preprocessing and network traffic.

This guide covers encoded images, not raw numeric tensor buffers. For the latter, see the KServe REST binary data extension. See also the KServe gRPC API reference and REST API reference.
Model Requirements#
The model’s effective input must have four dimensions and an NHWC-compatible layout. The decoded image is in NHWC layout with BGR or BGRA channel order for color images. Eight-bit image values are in the 0-255 range. The model must accept the resulting channel count and value range. The request uses BYTES and shape [N], where N is the number of encoded images, even though model metadata describes a four-dimensional numeric input.
For a model with an NCHW input, configure OVMS to expose an NHWC input and convert it to NCHW for the model. For example, a model with shape [1, 3, 224, 224] can be served with --layout NHWC:NCHW or "layout": "NHWC:NCHW" in its model configuration. Its effective input shape becomes [1, 224, 224, 3].
OVMS aligns image size automatically when the input shape has no dynamic (-1) dimensions and the layout is ..., NHWC, or N?HWC. With a bounded dimension, an out-of-range image dimension is resized to the nearest boundary. For example, for [1, 100:200, 200, 3], an image of height 90 is resized to height 100, and one of height 220 to height 200. Images in a batch must satisfy the model’s batch and shape requirements.
Models expecting RGB or normalized values need additional preprocessing configured for that model; decoding alone does not perform those adjustments. OVMS supports color_format, mean, and scale configuration; see server parameters and the model conversion example.
End-to-End ResNet Example#
Download the model, a sample image, and its label mapping:
mkdir -p "${HOME}/models"
curl -L https://huggingface.co/OpenVINO/resnet50-int8-ov/resolve/main/resnet50.bin -o "${HOME}/models/resnet50.bin"
curl -L https://huggingface.co/OpenVINO/resnet50-int8-ov/resolve/main/resnet50.xml -o "${HOME}/models/resnet50.xml"
curl -L https://raw.githubusercontent.com/openvinotoolkit/model_server/main/demos/common/static/images/zebra.jpeg -o zebra.jpeg
curl -L https://raw.githubusercontent.com/openvinotoolkit/model_server/main/demos/common/python/classes.py -o classes.py
Start OVMS with gRPC and REST endpoints, an NHWC-facing input, and model-specific normalization:
docker pull openvino/model_server:latest
docker run --rm -d -u "$(id -u)" -v "${HOME}/models:/models" -p 9000:9000 -p 8000:8000 \
openvino/model_server:latest \
--model_name resnet --model_path /models/resnet50.xml --batch_size 1 \
--mean "[123.675,116.28,103.53]" --scale "[58.395,57.12,57.375]" --layout "NHWC:NCHW" \
--port 9000 --rest_port 8000
Install tritonclient[grpc] and numpy, then run this Python client from the directory containing zebra.jpeg and classes.py:
import numpy as np
import tritonclient.grpc as grpcclient
from classes import imagenet_classes
client = grpcclient.InferenceServerClient("localhost:9000")
metadata = client.get_model_metadata("resnet")
with open("zebra.jpeg", "rb") as image_file:
image = image_file.read()
input_tensor = grpcclient.InferInput(metadata.inputs[0].name, [1], "BYTES")
input_tensor.set_data_from_numpy(np.array([image], dtype=np.object_))
result = client.infer("resnet", [input_tensor])
output = result.as_numpy(metadata.outputs[0].name)
print(imagenet_classes[np.argmax(output[0])])
Send an Encoded Image#
The following examples use the Triton client to send the downloaded zebra.jpeg image to a model named resnet with input image. Replace these names and the server address with your own. The model must be configured as described above.
gRPC#
Install tritonclient[grpc] and numpy, then run:
import numpy as np
import tritonclient.grpc as grpcclient
with open("zebra.jpeg", "rb") as image_file:
image = image_file.read()
client = grpcclient.InferenceServerClient("localhost:9000")
input_tensor = grpcclient.InferInput("image", [1], "BYTES")
input_tensor.set_data_from_numpy(np.array([image], dtype=np.object_))
result = client.infer("resnet", [input_tensor])
print(result.get_response())
For multiple images, pass an array of image bytes and set the input shape to [N]. The request may use InferTensorContents.bytes_contents, with one byte string per image, or raw_input_contents, with one buffer per input. In the raw buffer, each image is preceded by its length as an unsigned four-byte little-endian integer. Do not mix contents and raw_input_contents in the same request. See the gRPC API reference.
REST#
Install tritonclient[http] and numpy, then run:
import numpy as np
import tritonclient.http as httpclient
with open("zebra.jpeg", "rb") as image_file:
image = image_file.read()
client = httpclient.InferenceServerClient("localhost:8000")
input_tensor = httpclient.InferInput("image", [1], "BYTES")
input_tensor.set_data_from_numpy(np.array([image], dtype=np.object_), binary_data=True)
result = client.infer("resnet", [input_tensor])
print(result.get_response())
The client serializes the input using the binary data extension. The HTTP body contains the JSON inference request followed immediately by the binary input buffers, in input order. Inference-Header-Content-Length is the JSON length in bytes; Content-Length is the length of the entire body. For each binary BYTES input, parameters.binary_data_size is the buffer length including the four-byte little-endian length prefix for each image. It can be omitted for a single input with shape [1], but the image still needs its length prefix. For example, images of 370, 480, and 500 bytes occupy 4 + 370 + 4 + 480 + 4 + 500 = 1362 bytes:
[0x72 0x01 0x00 0x00][370 image bytes]
[0xe0 0x01 0x00 0x00][480 image bytes]
[0xf4 0x01 0x00 0x00][500 image bytes]
For example, the same single-image request can be sent with requests without the Triton client:
import json
import struct
import requests
with open("zebra.jpeg", "rb") as image_file:
image = image_file.read()
data = struct.pack("<I", len(image)) + image
header = json.dumps({
"inputs": [{
"name": "image",
"shape": [1],
"datatype": "BYTES",
"parameters": {"binary_data_size": len(data)},
}],
}).encode("utf-8")
response = requests.post(
"http://localhost:8000/v2/models/resnet/infer",
data=header + data,
headers={
"Content-Type": "application/octet-stream",
"Inference-Header-Content-Length": str(len(header)),
},
)
response.raise_for_status()
print(response.json())
See the REST API reference for the HTTP request format and raw numeric tensors. Complete clients with batching and output handling are available for gRPC and REST, with instructions in the samples README.
Optional OpenCV decoding#
OVMS uses an optional OpenCV plugin to decode images, or stb_image when the plugin is unavailable. The fallback supports JPEG and PNG, including grayscale, alpha, and 16-bit PNG; other formats may require OpenCV and its codecs. Decoder and resize implementations can produce slightly different pixel values. See OpenCV deployment and image decoding limits.
MediaPipe Graphs#
The automatic model input decoding described above does not apply to a MediaPipe graph’s IMAGE input: that input expects a raw HWC pixel array, not an encoded JPEG or PNG. A graph can accept encoded data and decode it in a calculator or in the Python executor. For example, OpenCvEncodedImageToImageFrameCalculator accepts a string packet containing encoded image bytes and produces an ImageFrame; it requires the OpenCV calculators plugin and a graph that supplies the string packet. See MediaPipe input types and optional OpenCV integration.