You need to enable JavaScript to run this app.
文档中心
AI 数据湖服务

AI 数据湖服务

复制全文
下载 pdf
图片OCR
图像 OCR(EasyOCR)
复制全文
下载 pdf
图像 OCR(EasyOCR)

算子介绍

描述

基于 EasyOCR 的多语言OCR识别组件,支持中英文混合场景下的文本检测与识别。

核心功能

  • 支持 100+ 种语言识别(需配置对应语言模型)
  • 输入格式兼容:
    • TOS URL
    • Base64编码
    • 二进制流
    • Numpy数组
  • 性能优化:
    • GPU 加速推理
    • 模型量化(默认开启)
    • 批量处理优化

多语言支持

  • 简体中文(ch_sim)
  • 英文(en)
  • 日文(ja)
  • 韩文(ko)
  • 法文(fr)
  • 德文(de)

完整语言列表参考官方文档:https://www.jaided.ai/easyocr/

Daft 调用

算子参数

输入

输入列名

说明

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.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… ┆ 不论结局           │
    # │                                ┆ 我己经很感谢相遇…    │
    # ╰────────────────────────────────┴───────────────────╯
最近更新时间:2026.03.30 14:23:37
这个页面对您有帮助吗?
有用
有用
无用
无用