Caffe : Example : Brewing ImageNet

Caffe : Example : Brewing ImageNet (翻訳/解説)
翻訳 : (株)クラスキャット セールスインフォメーション
日時 : 04/07/2017

* 本ページは、Caffe の本家サイトの Example – Brewing ImageNet with Caffe を翻訳した上で適宜、補足説明したものです:
    http://caffe.berkeleyvision.org/gathered/examples/imagenet.html
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

 

このガイドは貴方自身のモデルを貴方のデータ上で訓練する準備をしていただくことを意図しています。もし ImageNet 訓練済みネットワークを望むだけならば、訓練は多くのエネルギーを必要とし私たちは地球温暖化 (global warming) を嫌いますので、下で記述されるようにの model zoo の訓練された CaffeNet モデルを提供します。

 

データ準備

このガイドは全てのパスを指定して全てのコマンドは root caffe ディレクトリから実行されることを仮定しています。

ここでは “ImageNet” は ILSVRC12 challenge を意味しますが、同様に ImageNet 全体で簡単に訓練することもできます、よりディスクスペースが必要で訓練時間が少しだけ長くなりますが。

ImageNet 訓練データと検証データが既にダウンロードされて次のようにディスクにストアされていることを仮定します :

/path/to/imagenet/train/n01440764/n01440764_10026.JPEG
/path/to/imagenet/val/ILSVRC2012_val_00000001.JPEG

訓練のためには最初に幾つかの補助的なデータを準備する必要があります。
このデータは以下でダウンロード可能です :

./data/ilsvrc12/get_ilsvrc_aux.sh

訓練と検証入力は ファイルとそのラベルをリスティングするテキストとして train.txt と val.txt に記述されます。ラベルについて ILSVRC devkit とは異なる indexing を使用することに注意してください : synset 名を ASCII 順にソートして 0 から 999 までラベル付けしています。synset/name マッピングについては synset_words.txt を見てください。

画像をあらかじめ 256 x 256 にリサイズすることを望むかもしれません。デフォルトでは明示的にこれを行ないません、何故ならばクラスタ環境では、mapreduce を使用して、並列流儀で画像をリサイズすることから恩恵を受けるからです。例えば、Yangqing は軽量な mincepie パッケージを使いました。\より単純なものが好みならば、次のような shell コマンドを使用することもできます :

for name in /path/to/imagenet/val/*.JPEG; do
    convert -resize 256x256\! $name $name
done

examples/imagenet/create_imagenet.sh を見てみましょう。必要に応じて train と val ディレクトリにパスを設定して、そしてあらかじめ画像をリサイズしていないのであれば全ての画像を 256×256 にリサイズするように “RESIZE=true” を設定します。今 examples/imagenet/create_imagenet.sh で leveldbs を単に作成します。examples/imagenet/ilsvrc12_train_leveldb と examples/imagenet/ilsvrc12_val_leveldb は実行前に存在すべきではないことに注意しましょう。それはスクリプトにより作成されるでしょう。GLOG_logtostderr=1 は単に検査するための更なる情報をダンプするもので、
安全に無視することができます。

 

画像平均 (Image Mean) を計算する

モデルは各画像から画像平均を減算すsることを要求しますので、平均を計算しなければなりません。tools/compute_image_mean.cpp がこれを実装しています – それはまた protocol buffers、leveldbs、そしてロギングのような複数のコンポーネントをどのように操作するかについて慣れるためにも良いサンプルです、もしそれらに精通していないのであれば。いずれにせよ、平均計算は次のように実行されます :

./examples/imagenet/make_imagenet_mean.sh

これは data/ilsvrc12/imagenet_mean.binaryproto を作成します。

 

モデル定義

proposed by Krizhevsky, Sutskever, と Hinton により NIPS 2012 ペーパー で最初に提案されたアプローチに対する参照実装について説明します。

ネットワーク定義は (models/bvlc_reference_caffenet/train_val.prototxt) Krizhevsky et al のものに追随しています。

If you look carefully at models/bvlc_reference_caffenet/train_val.prototxt, you will notice several include sections specifying either phase: TRAIN or phase: TEST.
These sections allow us to define two closely related networks in one file: the network used for training and the network used for testing. These two networks are almost identical, sharing all layers except for those marked with include { phase: TRAIN } or include { phase: TEST }. In this case, only the input layers and one output layer are different.

Input layer differences: The training network’s data input layer draws its data from examples/imagenet/ilsvrc12_train_leveldb and randomly mirrors the input image. The testing network’s data layer takes data from examples/imagenet/ilsvrc12_val_leveldb and does not perform random mirroring.

Output layer differences: Both networks output the softmax_loss layer, which in training is used to compute the loss function and to initialize the backpropagation, while in validation this loss is simply reported. The testing network also has a second output layer, accuracy, which is used to report the accuracy on the test set. In the process of training, the test network will occasionally be instantiated and tested on the test set, producing lines like Test score #0: xxx and Test score #1: xxx. In this case score 0 is the accuracy (which will start around 1/1000 = 0.001 for an untrained network) and score 1 is the loss (which will start around 7 for an untrained network).

We will also lay out a protocol buffer for running the solver. Let’s make a few plans:

 

以上