Skip to content

Code Lab

OpenVINO Explained: From an Image Array to Model Inference

By Miles Park·
OpenVINO repository preview

CODE LAB · PROJECT SPOTLIGHT

OpenVINO Python · Apache-2.0

Where an image becomes a model input.

Project preview · openvinotoolkit/openvino

An image can have the correct width and height and still produce a surprising classification. Its channels may sit on the wrong axis, or its pixel values may have the wrong type. OpenVINO’s Python classification sample makes these assumptions visible before the model is compiled for a device.

On November 24, 2026, GitHub Trending showed 183 stars gained today. GitHub Trending

Where an image becomes a model input

OpenVINO documentation illustration showing image preprocessing before a model
OpenVINO documentation illustration showing image preprocessing before a model. Project source

The project’s preprocessing illustration follows image data toward a model. Each boundary raises a question about the array that crosses it, including where its channel dimension sits and which numeric type the pixels use.

Inside hello_classification.py

openvinotoolkit/openvinoPython · source excerpt
PY  samples/python/hello_classification/hello_classification.py
    ppp.input().tensor() \        .set_shape(input_tensor.shape) \        .set_element_type(ov.Type.u8) \        .set_layout(ov.Layout('NHWC'))  # noqa: ECE001, N400    # 2) Adding explicit preprocessing steps:    # - apply linear resize from tensor spatial dims to model spatial dims    ppp.input().preprocess().resize(ov.preprocess.ResizeAlgorithm.RESIZE_LINEAR)
Lines 61–68 · 993f33eView original on GitHub ↗

The sample declares the shape from the actual input tensor. It marks that tensor as unsigned eight-bit data and specifies NHWC, which puts channels last. It then asks the preprocessing pipeline for a linear resize. A few lines later the sample declares the model side as NCHW and builds the preprocessing graph before compiling it. Input layout and model layout describe different ends of the same path.

Source credit · openvinotoolkit/openvino contributors. Apache-2.0 license and notices.

Debug a plausible but incorrect result

Write down the shape of one image before and after adding its batch dimension. An image with shape (480, 640, 3) becomes (1, 480, 640, 3). Passing that array to code that treats the second axis as channels changes its meaning. Also verify channel order and any normalization expected by your model. A layout conversion alone cannot resolve RGB versus BGR.

Start with the linked single-input, single-output sample and a compatible classification model. Compare the top predicted labels for one known image before timing anything. When comparing devices, record compilation time separately from repeated inference. The sample describes a processing path. Performance on your hardware needs a measurement.

Prepare the image used in the official classifier demo

OpenVINO’s Hello World notebook shows its published classification result, “flat-coated retriever,” above the input photograph.
OpenVINO’s Hello World notebook shows its published classification result, “flat-coated retriever,” above the input photograph. View the project original

The classification sample above delegates resizing to its preprocessing graph. Intel’s Hello World notebook takes another concrete route for its MobileNet example: it prepares an RGB array before inference. To reproduce that input step, save the notebook’s original coco.jpg in the working directory and run this snippet with OpenCV and NumPy installed. Apply resizing in one place when adapting either example.

Python · worked example

import cv2
import numpy as np

image = cv2.imread("coco.jpg")
if image is None:
    raise FileNotFoundError("coco.jpg")
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
batch = np.expand_dims(cv2.resize(rgb, (224, 224)), axis=0)
print("Source:", image.shape)
print("Batch:", batch.shape, batch.dtype)
print("BGR:", image[0, 0].tolist(), "RGB:", rgb[0, 0].tolist())

Output from our run

Source: (577, 800, 3)
Batch: (1, 224, 224, 3) uint8
BGR: [105, 89, 82] RGB: [82, 89, 105]

The first dimension of the final array is the batch size. The two 224s are the new spatial dimensions, and the final 3 counts the color channels. Look at the sampled pixel: converting from BGR to RGB swaps the outer values while the green value stays at 89. A shape check alone would miss that difference. We ran these input checks on the linked JPEG. The label in the screenshot comes from the published notebook, which also runs the compiled model and maps the highest-scoring output to a class name.

More source walkthroughs in Code Lab

Join the discussion

Your email address will not be published. Required fields are marked *