Coder Social home page Coder Social logo

ndl-lab / ndltsr Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.62 MB

NDLTSRのソースコードを公開するリポジトリ

License: Creative Commons Attribution 4.0 International

Dockerfile 0.19% Shell 0.07% Python 61.03% C++ 19.20% C 3.23% Cuda 16.28%

ndltsr's Introduction

NDLTSR (NDL Table Structure Recognition)

資料画像に含まれる表の構造を認識するプログラムを公開しています。

座標付きのOCRテキストデータと組み合わせることで表中に含まれるテキストデータを構造化する用途に利用できます。

参考(外部リンク):次世代デジタルライブラリーへの新機能(表の構造化)の追加及び新機能のソースコード及びデータセットの公開について

本プログラムにより、国立国会図書館が公開しているNDLTableSetを学習した機械学習モデルによる表構造の推論を行えるほか、LORE-TSR(外部リンク)と同様の方法により別途利用者が用意したデータセットによる再学習を行うことが可能です。

注意

本プログラムが推論できるのは、表の構造情報(各セルの矩形座標及びセル間の関係性を表す数値情報)であるので、プログラム単体でOCR処理プログラムとして利用することはできません。

次世代デジタルライブラリーの機能と同様の処理を行うためには、別途座標付きテキストデータを出力するOCR処理プログラムが必要です。

環境構築

1. リポジトリのクローン

git clone https://github.com/ndl-lab/ndltsr

2. ホストマシンのNVIDIA Driverのアップデート

コンテナ内でCUDA 11.8を利用します。

ホストマシンのNVIDIA Driverが

Linuxの場合: 450.80.02以上

Windowsの場合:452.39以上

のバージョンを満たさない場合は、ご利用のGPUに対応するドライバの更新を行ってください。

(参考情報)

以下のホストマシン環境(AWS g5g.xlargeインスタンス)上で動作確認を行っています。

OS: 20.04.3 LTS

GPU: NVIDIA T4G

NVIDIA Driver: 470.82.01

Docker version: 20.10.11

3. dockerのインストール

https://docs.docker.com/engine/install/ に従って、OS及びディストリビューションにあった方法でdockerをインストールしてください。

4. dockerコンテナのビルドと起動

ndltsrディレクトリ下で次のように実行するとコンテナが起動します。

sh docker/dockerbuild.sh
sh docker/run_docker.sh

利用方法

コンテナ起動後、http://127.0.0.1:8080/invocations に次のように画像をPOSTすることで推定された表構造の情報を得ることができます。

import urllib.request
import msgpack

data = {}
with open("tableimg.jpg", "rb") as fp:
    data["img"] = fp.read()
payload = msgpack.packb(data, use_bin_type=True)
headers = {
    "Content-Type": "application/x-msgpack",
}
req = urllib.request.Request(
        "http://127.0.0.1:8080/invocations",
    payload, headers
)

with urllib.request.urlopen(req) as res:
    print(res.read())

返戻の形式

次のjson形式です。

{ "logi":logi_list,
  "center":center_list}
  • center_list:セル毎に推定した矩形座標を記述した4つの要素(x座標の最小値, y座標の最小値, x座標の最大値, y座標の最大値)を検出したセル数分持つリスト
  • logi_list:セル毎に推定したセル間の関係情報を記述した4つの要素(列の開始位置, 列の終了位置, 行の開始位置, 行の終了位置)を検出したセル数分持つリスト

画像をPOSTして得た返戻と座標付きOCRテキストデータを組み合わせてHTMLやTSVのテーブルを得るサンプルコードについてはmerge_sample.pyをご覧ください。

ライセンス情報

国立国会図書館が新規に追加したソースコードについてはCC BY 4.0ライセンスとします。

なお、本プログラムはApache 2.0ライセンスで公開されているLORE-TSR(外部リンク)を部分的に利用します。

src/lib以下のディレクトリ、src/_init_paths.py及びsrc/main.pyについて、原則的にLORE-TSRのオリジナルのソースコードを複製していますが、 src/lib/detectors/base_detector.py及びsrc/lib/opts.pyについては、一部ソースコードの修正を行いました。

オリジナルのLORE-TSRのライセンス等の情報はLICENSE_original.mdNOTICE_original及びREADME_original.mdを参照してください。

ndltsr's People

Contributors

ndl-lab-staff avatar

Stargazers

Babibubebon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.