惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

博客园 - 你看起来真的很好吃

linux系统时间管理 安装历史docker版本 测试 深度学习-激活函数 go——make和new的区别 go——GC垃圾回收机制 go——标识符的命名规范 go语言——数据类型 go语言——转义符 go开发环境安装 git使用 项目文档目录总结 鼠标连点器——python版 windows使用YOLOV5训练模型——搭建编译环境 高匿名动态IP代理获取 logging模块进行格式化输出 笔记 Django admin 添加操作记录 facenet + fiass 实现人脸识别
OCR文本提取+NER命名实体识别
你看起来真的很好吃 · 2025-08-28 · via 博客园 - 你看起来真的很好吃

OCR模型: Umi-ocr

  • github地址:https://github.com/hiroi-sora/Umi-OCR
  • 平台:windows、linux
  • docker部署文档:https://github.com/hiroi-sora/Umi-OCR_runtime_linux/blob/main/README-docker.md
  • centos安装docker 当前版本为( 26.1.4)
    要查看yum中可安装的Docker版本,可以按照以下步骤操作:
    
    ‌打开终端或命令行界面‌:
    确保你已经登录到你的Linux服务器,并打开了终端或命令行界面。
    
    ‌使用yum list命令列出所有可用的docker版本‌:
    
    bash
    Copy Code
    yum list docker-ce --showduplicates | sort -r
    这个命令会列出所有可用的Docker CE版本,并按照版本号从高到低排序。--showduplicates选项用于显示所有可用的版本,而sort -r则用于将结果按版本号降序排列。
    
    ‌在输出结果中查找Docker的版本信息‌:
    执行上述命令后,你将看到一系列类似如下的输出:
    plaintext
    Copy Code
    docker-ce.x86_64            3:23.0.0-1.el7                      docker-ce-stable
    docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
    docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
    ...
    每一行代表一个可用的Docker版本,其中docker-ce.x86_64是软件包的名称和架构,3:23.0.0-1.el7是版本号,docker-ce-stable是仓库名称。
    
    ‌安装特定版本的Docker‌(可选):
    如果你决定安装某个特定版本的Docker,可以使用以下命令:
    bash
    Copy Code
    yum install -y docker-ce-<版本号> docker-ce-cli-<版本号> containerd.io
    将<版本号>替换为你想要安装的Docker版本号。
    
    ‌查看已安装的Docker版本‌:
    安装完成后,你可以使用以下命令查看已安装的Docker版本:
    bash
    Copy Code
    docker --version
    这样,你就可以通过yum查看并安装特定版本的Docker了。
    

    Dockerfile内容

    # Umi-OCR Docker
    # https://github.com/hiroi-sora/Umi-OCR
    # https://github.com/hiroi-sora/Umi-OCR_runtime_linux
    
    FROM debian:11-slim
    
    LABEL app="Umi-OCR-Paddle"
    LABEL maintainer="hiroi-sora"
    LABEL version="2.1.5"
    LABEL description="OCR software, free and offline."
    LABEL license="MIT"
    LABEL org.opencontainers.image.source="https://github.com/hiroi-sora/Umi-OCR_runtime_linux"
    
    # 安装所需工具和QT依赖库
    RUN apt-get update && apt-get install -y \
        && wget xz-utils ttf-wqy-microhei xvfb \
        libglib2.0-0 libgssapi-krb5-2 libgl1-mesa-glx libfontconfig1 \
        libfreetype6 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 \
        libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-xkb1 \
        libxcb-xinerama0 libxkbcommon-x11-0 libxkbcommon0 libdbus-1-3 \
        && rm -rf /var/lib/apt/lists/*
    # 工作目录 WORKDIR /app # 可选1:将主机目录中的发行包,复制到容器内 COPY Umi-OCR_Linux_Paddle_2.1.5.tar.xz . # 可选2:在线下载发行包 RUN wget https://github.com/hiroi-sora/Umi-OCR/releases/download/v2.1.5/Umi-OCR_Linux_Paddle_2.1.5.tar.xz # 解压压缩包,移动文件,删除多余的目录和压缩包 RUN tar -v -xf Umi-OCR_Linux_Paddle_2.1.5.tar.xz && \ mv Umi-OCR_Linux_Paddle_2.1.5/* . && \ rmdir Umi-OCR_Linux_Paddle_2.1.5 && \ rm Umi-OCR_Linux_Paddle_2.1.5.tar.xz # 下载最新的启动脚本 # RUN wget -O umi-ocr.sh https://raw.githubusercontent.com/hiroi-sora/Umi-OCR_runtime_linux/main/umi-ocr.sh # 写入 Umi-OCR 预配置项: # 允许外部HTTP请求 # 切换到支持中文的字体 RUN printf "\ [Global]\n\ server.host=0.0.0.0\n\ ui.fontFamily=WenQuanYi Micro Hei\n\ ui.dataFontFamily=WenQuanYi Micro Hei\n\ " > ./UmiOCR-data/.settings # 运行指令 ENTRYPOINT ["/app/umi-ocr.sh"]
  • 由于网络问题可以手动下载源码,并修改dockerfile文件 (可选1:将主机目录中的发行包,复制到容器内)
  • docker设置国内镜像源 
    /etc/docker/daemon.json
  • https://docker.xuanyuan.me源可以下载
    {
      "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.xuanyuan.me"]
    }
    
  • 保存文件,重启docker
    sudo systemctl daemon-reload
    sudo systemctl restart docker
  •  构建镜像
    docker build -t umi-ocr-paddle .
    
  •  启动容器
    docker run -d --name umi-ocr \
        -e HEADLESS=true \
        -p 1224:1224 \
        umi-ocr-paddle
    

NER模型

  • 名称:bert-base-chinese
  • 国内模型下载地址:https://modelscope.cn/
  • docker基础镜像:https://modelscope.cn/docs/intro/environment-setup


  功能:
  判断字符串是否为地址(模型+正则)

  1. 拉取基础镜像
    docker pull modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.29.0
  2. 创建容器
    sudo docker run -it --name=address_recognition modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.29.0 /bin/bash
    
  3. 下载模型
    cd /home
    modelscope download --model tiansz/bert-base-chinese --local_dir bert-base-chinese
  4. docker部署
    创建文件app.py、uwsgi.ini、dockerfile

    创建镜像
    Docker 会缓存每一层(Layer),如果某一层的指令和上下文(如文件内容)与之前完全一致,Docker 会直接复用缓存的层,跳过执行该指令,使用 --no-cache 参数强制 Docker 忽略缓存,从头开始构建
    docker build --no-cache -t bert-base-chinese .

    启动容器
    docker run -d --name address_recognition -p 8090:8090 bert-base-chinese

    app.py代码

    import re
    from modelscope.pipelines import pipeline
    from modelscope.utils.constant import Tasks
    from flask import Flask, request, jsonify
    
    app = Flask(__name__)
    
    
    # 正则匹配(正则匹配容易造成匹配不到)
    def is_address_regex(text):
        pattern = r'.*?(?:省|市|自治区|特别行政区|市辖区|市|路|街|大道|巷|道|村|镇|乡|公司|门|园|口)'
        print("is_address_regex")
        return bool(re.search(pattern, text))
    
    # NER模型判断
    # 加载本地模型(需提前下载)
    ner_pipeline = pipeline(
        task=Tasks.token_classification,
        model='/home/bert-base-chinese/'
    )
    
    def is_address_ner(text):
        entities = ner_pipeline(text)
        address_keywords = {"B-LOC", "I-LOC"}
        print("is_address_ner")
        print(entities)
        return any(e["entity"] in address_keywords for e in entities)
    
    
    # 综合判断
    @app.route('/')
    def is_address():
        try:
            text = request.args.get('text', '')
            text_is_address = is_address_regex(text) or is_address_ner(text)
            if text_is_address:
                return jsonify({"code": "1", "message": "success"})
            else:
                raise Exception("非地址信息")
        except Exception as e:
            return jsonify({"code": "0", "message": str(e)})
    
    
    if __name__ == '__main__':
        app.run()
    


    uwsgi.ini

    [uwsgi]
    # Ubuntu系统下默认用户名
    uid=root
    # Ubuntu系统下默认用户组
    gid=root
    # 项目名
    project=address_recognition
    
    # 项目根目录
    base=/home
    
    # 设置工作目录
    chdir=%(base)
    # wsgi 文件地址
    # module=%(base)/app.py
    wsgi-file=app.py
    callable=app
    
    # 主进程
    master = true
    # 进程数量
    process=1
    # 使用tcp socket与nginx进行通信
    http=0.0.0.0:8090
    
    FROM modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.29.0
    
    LABEL app="bert-base-chinese"
    LABEL version="1"
    LABEL description="NER bert-base-chinese"
    
    # 安装所需工具和QT依赖库
    RUN apt-get update && \
    pip install Flask && \
    pip install uwsgi
    
    
    # 工作目录
    WORKDIR /home
    
    # 下载模型
    RUN modelscope download --model tiansz/bert-base-chinese --local_dir bert-base-chinese
    
    # 可选1:将主机目录中的发行包,复制到容器内
    COPY app.py .
    COPY uwsgi.ini .
    
    
    # 运行指令
    CMD ["uwsgi", "--ini", "uwsgi.ini"]
    
  5. 创建镜像并启动容器
    docker build -t address_recognition .
    docker run -d -p 8090:8090 --name address_recognition address_recognition
    

  后台启动服务:sudo nohup python app.py &