基于 EasyOCR 的多语言OCR识别组件,支持中英文混合场景下的文本检测与识别。
完整语言列表参考官方文档:https://www.jaided.ai/easyocr/
输入列名 | 说明 |
|---|---|
images | 包含图像数据的数组,支持URL/base64/二进制格式 |
包含OCR识别结果的数组,元素类型为字符串
如参数没有默认值,则为必填参数
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
image_src_type | str | image_url | 输入图像的格式类型,支持: - tos/http 地址 (image_url) - base64 编码 (image_base64) - 二进制流 (image_binary) 可选值: ["image_url", "image_base64", "image_binary"] 默认值: "image_url" |
model_path | str | /opt/las/models | 模型存储路径。 默认值: "/opt/las/models" |
model_name | str | EasyOCR | 使用的模型名称,当前仅支持 "EasyOCR"。 默认值: "EasyOCR" |
quantize | bool | True | 是否启用模型量化加速推理。 默认值: True |
lang_list | list | [en, ch_sim] | 支持识别的语言列表,详见 https://www.jaided.ai/easyocr/ 默认值: ["en", "ch_sim"] |
batch_size | int | 16 | GPU 推理批次大小(可根据显存调整)。 默认值: 16 |
下面的代码展示了如何使用 daft 运行算子识别图像中的文字。
from __future__ import annotations import os import daft from daft import col from daft.las.functions.image.image_easyocr import ImageEasyOcr from daft.las.functions.udf import las_udf if __name__ == "__main__": if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.context.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "image": [ f"https://{tos_dir_url}/public/shared_image_dataset/通用场景图片.jpeg" ] } image_src_type = "image_url" model_path = os.getenv("MODEL_PATH", "/opt/las/models") model_name = "EasyOCR" quantize = True lang_list = ["en", "ch_sim"] batch_size = 16 num_gpus = 1 ds = daft.from_pydict(samples) ds = ds.with_column( "ocr_result", las_udf( ImageEasyOcr, construct_args={ "image_src_type": image_src_type, "model_path": model_path, "model_name": model_name, "quantize": quantize, "lang_list": lang_list, "batch_size": batch_size, }, num_gpus=num_gpus, batch_size=1, )(col("image")), ) ds.show() df = ds.to_pandas() # ╭────────────────────────────────┬───────────────────╮ # │ image ┆ ocr_result │ # │ --- ┆ --- │ # │ Utf8 ┆ Utf8 │ # ╞════════════════════════════════╪═══════════════════╡ # │ tos://las-cn-beijing-public-o… ┆ 不论结局 │ # │ ┆ 我己经很感谢相遇… │ # ╰────────────────────────────────┴───────────────────╯