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_segment#

image_segment(*columns, model='FastSAM-x.pt', confidence=0.05, imgsz=1024, iou=0.5, model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#

Create a semantic segmentation UDF (FastSAM-based).

Requires pip install ultralytics. This is a pandas batch UDF that supports GPU acceleration via num_gpus / gpu_type.

Parameters
  • *columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.

  • model – FastSAM model name. Default "FastSAM-x.pt".

  • confidence – Minimum confidence threshold. Default 0.05.

  • imgsz – Input image size for inference. Default 1024.

  • iou – IoU threshold for NMS. Default 0.5.

  • model_sharing – Model sharing mode across parallel subtasks. None uses per-process caching.

  • concurrency – UDF concurrency. None uses the framework default.

  • batch_size – Pandas batch size. None uses the framework default.

  • num_gpus – Fractional GPU count per subtask, e.g. 0.5. None runs on CPU.

  • gpu_type – Required GPU type, e.g. "A10". None accepts any available GPU.

Returns

A UDF that returns an 8-bit PNG indexed segmentation mask. Pixel value 0 is background; values 1..255 are segment indices. Later masks overwrite earlier masks in overlapping pixels. Segment indices above 255 are saturated to 255 because the mask is encoded as uint8.

Example:

>>> # As a reusable variable
>>> segment = image_segment(model="FastSAM-x.pt")
>>> df = df.with_column("mask", segment(col("img")))
>>>
>>> # Inline
>>> df = df.with_column("mask", image_segment(col("img")))

previous

pyflink.multimodal.operators.image_detect_objects

next

pyflink.multimodal.operators.image_ocr

Show Source

Created using Sphinx 4.5.0.