LoginSignup
0
1

More than 5 years have passed since last update.

ChainerでNDL手書き平仮名を認識(Colaboratory+GPU)

Posted at

NDL

  • NDLラボは、国立国会図書館の実験的なサービスを提供するサイトです
  • 手書き平仮名データが公開されています
  • Chainerで学習するサンプルプログラムが公開されている
    • Chainerが古い、1.9.0向け
    • 学習・検証した結果を利用するサンプルはない
    • CPUのみでGPUを使えない
    • 手書き漢字データも公開されているけどサンプルプログラムはない

GPU対応する

先に結果

  • train.py
    • Chainer4対応
    • GPU対応
  • ndl.ipynb
    • google-drive-ocamlfuse導入
    • /content/driveにGoogle Driveをマウント
    • Chainerとcupyをインストール
    • トレーニング
    • 学習結果を可視化

やったこと

  • Google Colaboratoryで実行前にGoogle Driveの準備
    • NDL記載の手順をローカル端末でダウンロード、解凍、Google Driveにアップロードしておく
NDL記載の手順
$ wget http://lab.ndl.go.jp/dataset/hiragana73.tar.gz
$ tar xfz hiragana73.tar.gz
$ wget http://lab.ndl.go.jp/dataset/example/train_ndlkana.tar.gz
$ tar xfz train_ndlkana.tar.gz
train.py
-                                        help='ratio of test data')
-args = parser.parse_args()
+                                        help='ratio of test data')
+parser.add_argument('--gpu', '-g', type=int, default=-1,
+                    help='GPU ID (negative value indicates CPU)')
+args = parser.parse_args()

-xp = np
+xp = np
+if args.gpu >= 0:
+    # Make a specified GPU current
+    chainer.backends.cuda.get_device_from_id(args.gpu).use()
+    model.to_gpu()  # Copy the model to the GPU
+    xp = chainer.backends.cuda.cupy

-optimizer.setup(model)
+optimizer.setup(model)
+if args.gpu >= 0:
+        optimizer.target.to_gpu(args.gpu)

次の一歩

  • 漢字もやってみてもよい(分類が多いだけで本質は変わらないから楽しくはないか)
  • 複数の文字、というか文字列というか、文書をOCRさせるには?
  • 文字でなく単語を学習する必要が合る?
  • ノートやホワイトボードのように自由な場所に書く場合はbboxが必要?

おわり

0
1
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
1