LoginSignup
0
0

More than 1 year has passed since last update.

Google ColabでOctopiiを使ってみる

Last updated at Posted at 2022-12-24

Octopiiとは

https://github.com/redhuntlabs/Octopii
AIを使って画像から個人情報(パスポート、政府のID、署名)を抽出するツールです。
元から入っているモデルデータは最小限のものなので精度が悪いのですが、新しく追加するのもめんd...今回の趣旨とは少し違うのでそのままでいきます。

使おう

GPU付きのColabに接続する

実はOctopiiの動作はそんなに重くないのでCPUでも問題ありません。
そもそもColabに個人情報を含む画像をアップロードするなという話になりますが、今回は気にしません。
とりあえずGPUを使います。
そしてこんな感じに設定します。
image.png

ipynb(長いので折り畳み)
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "gpuClass": "standard"
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HnAEM8_bspud"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/redhuntlabs/Octopii"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!mv Octopii/* ./ & rm -r Octopii"
      ],
      "metadata": {
        "id": "GppZUjKds1MY"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install -r requirements.txt"
      ],
      "metadata": {
        "id": "R8JnhsKOtrWI"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!sudo apt update &sudo apt install tesseract-ocr -y"
      ],
      "metadata": {
        "id": "U4TjSn97t3yg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!mkdir test &wget -P test https://smartdetax.com/wp-content/uploads/2020/11/taxfree-passport-sample.png"
      ],
      "metadata": {
        "id": "bvOE4nkFuODg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!python3 octopii.py test"
      ],
      "metadata": {
        "id": "eKaBK2nZutTf"
      },
      "execution_count": 6,
      "outputs": []
    }
  ]
}

pipするときにランタイムを再起動しろと言われるので、ボタンを押して従います。
image.png
再起動してもデータは消えないので安心してください。

実行

image.png
適当に拾ってきたパスポートのサンプルで試しました。
WARNINGが出ていますが一応うまくいっています。

これほんとにGPUいる? Colabでする必要ある?

知りません。

完走用アドベントカレンダーの反省点として、一日分のカレンダーを水増しするのは良くないと思ったので書きました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0