pyflink.multimodal.operators.image_ocr#
- image_ocr(*columns, lang=None, model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#
Create an OCR text extraction UDF (EasyOCR-based).
Requires
pip install easyocr. This is a pandas batch UDF. EasyOCR accepts only a CPU/GPU boolean switch here:num_gpus > 0requests a Flink GPU resource and enables EasyOCR GPU mode, whilegpu_typeis used to validate the assigned Flink GPU label before loading. EasyOCR does not expose explicit CUDA device placement through this operator. Inference currently runs per image so mixed-size batches do not need padding;batch_sizemainly controls Python/Arrow batching overhead.- Parameters
*columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.
lang – List of language codes, e.g.
["en"],["en", "ch_sim"].None(default) uses["en"].model_sharing – Model sharing mode across parallel subtasks.
Noneuses per-process caching.concurrency – UDF concurrency.
Noneuses the framework default.batch_size – Pandas batch size.
Noneuses the framework default.num_gpus – Fractional GPU count per subtask, e.g.
0.5. Values greater than0enable EasyOCR GPU mode;Noneand0run on CPU.gpu_type – Required Flink GPU resource label, e.g.
"A10".Noneaccepts any assigned GPU label. EasyOCR itself receives only the boolean GPU switch.
- Returns
A UDF that returns a list of dicts with
text,confidence,bboxkeys.bboxis a four-point polygon[[x1, y1], ...]in image coordinates, preserving rotated text regions returned by EasyOCR.
Example:
>>> # As a reusable variable >>> ocr = image_ocr(lang=["en", "ch_sim"]) >>> df = df.with_column("text", ocr(col("img"))) >>> >>> # Inline >>> df = df.with_column("text", image_ocr(col("img")))