Ctrl+K
Logo image Logo image

Site Navigation

  • API Reference
  • Examples

Site Navigation

  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
  • PyFlink DataFrame
  • PyFlink Multimodal
    • Image
    • Video
    • Utilities
  • PyFlink DataStream
  • PyFlink Common

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 to float32 and scaled to [0, 1] for uint8/uint16 inputs. Inputs whose dimensions or channel count do not match the declared shape return None.

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_resize upstream 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. None uses the framework default.

Returns

A UDF producing a fixed-shape float32 tensor.

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))

previous

pyflink.multimodal.operators.image_convert_format

next

pyflink.multimodal.operators.image_convert_mode

Show Source

Created using Sphinx 4.5.0.