chainerのexamplesについて
一人アドベントカレンダー1日目です。
adventar.org
昨年に引き続きやっていきますが、
去年よりは忙しいのですべて埋まるかは怪しいです。
今日はChainerのexamplesについて書いていきたいと思います。
github.com
Chainerのexamplesは少しずつ数が増えていて、
昔はmnist, imagenet, ptb, cifar, vae ....と、
そんな感じだったと思うのですが、
現在ではこれだけあります。
実際にそれぞれ見たことある方はわかると思いますが、詳しい説明や実行方法については触れられていないものもあります。
そこで、今回はそれぞれがどういうものなのか、ということを順に説明したいと思います。
- caffe_export
- chainermn
- cifar
- dcgan
- glance
- image_captioning
- imagenet
- memnn
- mnist
- modelzoo
- pix2pix
- pos
- ptb
- reinforcement_learning
- sentiment
- seq2seq
- serialization
- static_graph_optimizations
- text_classification
- vae
- wavenet
- word2vec
- まとめ
caffe_export
This example shows how to export Chainer models into Caffe protobuf format. With this example, you can easily export the following five pre-trained models:
https://github.com/chainer/chainer/tree/master/examples/caffe_export
・GoogLeNet
・ResNet50
・ResNet101
・ResNet152
・VGG16
読んでそのままですが、ChainerのモデルをCaffeのprotobuf形式にexportするもののようです。
この例では、上記の5つの学習済みモデルをexportする例が示されています。
chainermn
特に説明は書かれていませんが、ChainerMNに関するサンプルだと思います。
ChainerMNに関する詳しい話はこちらである程度わかると思います。
Overview — ChainerMN 1.3.1 documentation
複数のGPUを使っている人、複数のノードを用いて学習する人向けの例で、並列処理をしたい人は参考になるかもしれません。ChainerMN自体があまり個人向けではないかも知れませんが。
cifar
https://github.com/chainer/chainer/tree/master/examples/cifarConvolutional neural networks for CIFAR-10 and CIFAR-100 Classification
This is an example of a convolutional neural network (convnet) applied to an image classification task using the CIFAR-10 or CIFAR-100 dataset. The CIFAR datasets can be a good choice for initial experiments with convnets because the size and number of images is small enough to allow typical models to be trained in a reasonable amount of time. However, the classification task is still challenging because natural images are used.
CIFAR-10、CIFAR-100と呼ばれるデータセットがあります。
CIFAR-10は10クラスにラベル付けされた画像のデータセットで、
CIFAR-100は100クラスにラベル付けされたデータセットです。
主に画像分類に用いられるデータセットで、このサンプルでは、CNNを用いて学習を行うようです。
dcgan
https://github.com/chainer/chainer/tree/master/examples/dcganDCGAN
This is an example implementation of DCGAN (https://arxiv.org/abs/1511.06434) using trainer.
This code uses Cifar-10 dataset by default. You can use your own dataset by specifying --dataset argument to the directory consisting of image files for training. The model assumes the resolution of an input image is 32x32. If you want to use another image resolution, you need to change the network architecture in net.py.
DCGANと呼ばれる、画像生成によく使われるネットワークのサンプルですね。この例では、cifar-10データセットを用いて学習を行えるようです。
glance
https://github.com/chainer/chainer/tree/master/examples/glanceMulti-Layer Perceptron for mushroom lethality categorization
This is a minimal example to write a feed-forward net. The code consists of three parts: dataset preparation, network and optimizer definition and learning loop. This is a common routine to write a learning process of networks with dataset that is small enough to fit into memory.
MLPを使って、マッシュルームのデータセットを分類するサンプルです。この例は、フィードフォワードネットワークの参考になると思います。
image_captioning
https://github.com/chainer/chainer/tree/master/examples/image_captioningImage Captioning with Convolutional Neural Networks
This is an example implementation of Show and Tell: A Neural Image Caption Generator (https://arxiv.org/abs/1411.4555) a generative image captioning model using a neural network with convolutional and recurrent layers. Given an image, this model generates a sentence that describes it.
イメージキャプションに関するサンプルです。モデルとしては、CNN+RNNを使うようです。
imagenet
https://github.com/chainer/chainer/tree/master/examples/imagenetDescription
This is an experimental example of learning from the ILSVRC2012 classification dataset. It requires the training and validation dataset of following format:
・Each line contains one training example.
・Each line consists of two elements separated by space(s).
・The first element is a path to 256x256 RGB image.
・The second element is its ground truth label from 0 to 999.
ILSVRC2012の分類データセットのサンプルです。デフォルトalexnetやgooglenet、resnetなどのモデルを使うことができます。
memnn
https://github.com/chainer/chainer/tree/master/examples/memnnEnd-to-end memory networks example
This is an example of end-to-end memory networks[1].
[1] Sainbayar Sukhbaatar, Arthur szlam, Jason Weston and Rob Fergus. End-To-End Memory Networks. https://papers.nips.cc/paper/5846-end-to-end-memory-networks
メモリーネットワークに関するサンプルです。
独特なモデルをしてると思うので、見てみると面白いかもしれません。
mnist
https://github.com/chainer/chainer/tree/master/examples/mnistMulti-Layer Perceptron for MNIST Classification
This is a minimal example to write a feed-forward net. The code consists of three parts: dataset preparation, network and optimizer definition and learning loop. This is a common routine to write a learning process of networks with dataset that is small enough to fit into memory.
シンプルなMLPを使ったMNISTの分類のサンプルです。
MNISTは0~9までの数字の画像のデータセットで、一番基礎となるサンプルだと思います。
modelzoo
https://github.com/chainer/chainer/tree/master/examples/modelzooEvaluate a Caffe reference model
This is an example of evaluating a Caffe reference model using ILSVRC2012 classification dataset. It requires the validation dataset in the same format as that for the imagenet example.
Model files can be downloaded by download_model.py. AlexNet and reference CaffeNet requires a mean file, which can be downloaded by download_mean_file.py.
先ほど出てきたILSVRC2012のデータセットを使って、caffeのモデルを評価するサンプルだと思います。
pix2pix
https://github.com/chainer/chainer/tree/master/examples/pix2pixchainer-pix2pix
chainer implementation of pix2pix https://phillipi.github.io/pix2pix/
pix2pixを実装したサンプルになります。生成系によく使われるモデルで、上記のURLから実際にデモを動かすことができるので、それを触ってみることでpix2pix自体のイメージはつかめるかもしれません。
pos
https://github.com/chainer/chainer/tree/master/examples/posPOS-tagging
This is an example of a POS-tagging problem for natural language processing. Part of speech (POS) is a category of word, such as noun and verb. POS-tagging problem is the task of assigning part of speech to each word in a sentence. This problem can be formulated as a sequential labeling problem. So, you can apply this example to another problems such as named entity recognition.
This example uses traditional linear-chain CRF model. And of course you can extends this model with RNN, LSTM, Bi-LSTM and CNN.
自然言語処理のPOSタグ付けに関するサンプルです。
モデル自体はlinear-chain CRFを使っているようです。
ptb
https://github.com/chainer/chainer/tree/master/examples/ptbRecurrent Net Language Model
This is an example of a recurrent net for language modeling. The network is trained to predict the word given the preceding word sequence.
This example is based on the following RNNLM implementation written in Torch7. https://github.com/tomsercu/lstm
次の単語を予想していくRNNのサンプルです。
ちなみにptbはPenn Tree Bankの略で、使用するデータセットの名前です。
reinforcement_learning
https://github.com/chainer/chainer/tree/master/examples/reinforcement_learningReinforcement Learning Examples
These are minimal examples of writing reinforcement learning agents. You need to install gym before running the examples.
・dqn_cartpole.py implements DQN and DoubleDQN and supports discrete-action tasks.
・ddpg_pendulum.py implements DDPG and supports continuous-action tasks.
強化学習に関するサンプルで、cartpole(棒を倒さないように保ゲーム)とpendulum(振り子のゲーム)を動かすサンプルです。
ネットワークにはDQNとDoubleDQNなどが使われているようです。
chainerrlは使われていないみたいです。
sentiment
https://github.com/chainer/chainer/tree/master/examples/sentimentRecursive Nets for Sentiment Analysis
This example implements the simple recursive model by Richard Socher. It requires the preprocessed dataset which is available by running download.py.
感情分析に関するサンプルです。
RecursiveNetと呼ばれるネットワークが使われています。
seq2seq
https://github.com/chainer/chainer/tree/master/examples/seq2seqSequence-to-sequnce learning example for machine translation
This is a minimal example of sequence-to-sequence learning. Sequence-to-sequence is a learning model that converts an input sequence into an output sequence. You can regard many tasks in the natural language processing field as this type of task, such as machine translation, dialogue and summarization.
自然言語処理によく使われるseq2seqのサンプルです。
ネットワークには、NStepLSTMが使用されているので、そちらの参考にもなるかもしれません。
serialization
https://github.com/chainer/chainer/tree/master/examples/serializationSerialization
This example intends to show how to use serializers with minimal code. These scripts show two ways to save/load snapshots using NumPy and H5Py, so please ensure that you have installed h5py package besides NumPy preliminary.
モデルの保存や読み込みなどのサンプルです。
この例では、H5Pyを使う方法とserializersを使う方法が示されています。
static_graph_optimizations
https://github.com/chainer/chainer/tree/master/examples/static_graph_optimizationsDemonstration of "static subgraph optimizations" feature
The subfolders in this directory contain versions of the following Chainer examples that were modified to support this feature. Since the static graph optimizations feature is experimental, these examples might be unstable.
静的グラフ最適化に関するサンプルとのことで、まだ実験的な機能のようです。
text_classification
https://github.com/chainer/chainer/tree/master/examples/text_classificationNeural Networks for Text Classification
This is an example of text classification using typical neural networks. This code can switch choices below:
・LSTM
・CNN + MLP
・BoW + MLP
・Character-based variant models of those
文書分類に関するサンプルです。
LSTM、CNN+MLP、BoW+MLPなどのネットワークを使って学習をすることができます。
vae
https://github.com/chainer/chainer/tree/master/examples/vaeVariational AutoEncoder
This is a sample implementation of variational autoencoder.
This method is proposed by Kingma and Welling, Auto-Encoding Variational Bayes, 2014.
Variational AutoEncoder(VAE)に関するサンプルです。
mnistのデータセットを使い、画像を生成するようです。
wavenet
https://github.com/chainer/chainer/tree/master/examples/wavenetWaveNet
A Chainer implementation of mel-spectrogram vocoder using WaveNet.
一時期話題になったWaveNetのChainer実装です。
音声処理に興味がある人はいいかも知れません。
word2vec
https://github.com/chainer/chainer/tree/master/examples/word2vecWord Embedding
This is an example of word embedding. We implemented Mikolov's Skip-gram model and Continuous-BoW model with Hierarchical softmax and Negative sampling.
word embeddingに関するサンプルです。
word2vec自体は知ってる人も多いと思います。
まとめ
今回はChainerのexamplesを軽く紹介しました。
以前よりもかなり種類が増えていて説明も少し細かくなっています。
みなさんも画像や自然言語、いろんなサンプルを試してみてくださいね。