pyflink.multimodal.operators.image_to_tensor#
- image_to_tensor(*columns, width, height, mode='RGB', layout='CHW', concurrency=None)[source]#
Convert an image to a fixed-shape float32 tensor.
Pure conversion boundary — no resize or mode conversion is performed. The output type is a fixed-shape
TensorType. Pixel values are converted tofloat32and scaled to[0, 1]for uint8/uint16 inputs. Inputs whose dimensions or channel count do not match the declared shape returnNone.- Parameters
*columns – Optional image columns. When provided, the UDF is applied directly instead of returning a factory.
width – Expected input width in pixels. The input image must already be this width (use
image_resizeupstream if needed).height – Expected input height in pixels.
mode – Expected input image mode, e.g.
"RGB"(3 channels) or"L"(1 channel). Determines the channel dimension of the output tensor. Default"RGB".layout – Tensor axis layout.
"CHW"(default) produces shape(channels, height, width);"HWC"produces(height, width, channels). Accepted case-insensitively and normalized to uppercase.concurrency – UDF concurrency.
Noneuses the framework default.
- Returns
A UDF producing a fixed-shape
float32tensor.
- Example::
>>> df = df.with_columns("img", image_decode(col("raw_bytes"))) >>> df = df.with_columns("img", image_convert_mode(col("img"), mode="RGB")) >>> df = df.with_columns("img", image_resize(col("img"), width=224, height=224)) >>> df = df.with_columns("t", image_to_tensor(col("img"), width=224, height=224))