LoginSignup
3
3

More than 5 years have passed since last update.

How to use saku_cnn (a unofficial chainer sample code for beginner)

Last updated at Posted at 2016-01-13

"How I make auto-classification program of pictures !?"
"oh, you have to read some Japanese text. And you change some codes in that examples."
"oh..."

I don't have the heart to say, so I got together "saku_cnn".
Below text is mainly points for using "saku_cnn".

(This is English translation item of that)

Preparation

ubuntu 14.04 (or more later versions)
python
 OpenCV 2.4.10
 chainer 1.3.2 or 1.5.0
GeForce Titan X

Source codes

github

How to use "saku_cnn"

It's very easy 3 steps.

1st step: Prepare of "Picture"

If you want to test anyway, you can pass the step.
(I set default pictures, so you can test without changing)

"Picture" is a default folder in "saku_cnn".
"Picture" has class folders, and every class folder has pictures file in the class.

階層.png

For example, when you want to classification "car" and "bike" pictures.
1st: You delete class folders and pictures in "Picture".
2nd: You make a folder named "car" in "Picture", and you put cars picture in the "car" folder.
3rd: You make a folder named "bike" in "Picture", and you put bikes picture in the "bike" folder, too.

The files' and folders' names are free, but the names have to be complex of alphabets or numbers.
If you use " "(space) or other sign, "saku_cnn" don't work well.

In all pictures in "Pictures", 9/10 pictures use for learning and 1/10 pictures use for testing.

2nd step: Call "callvgg.py"

$ python callvgg.py 0

The argument is for deciding GPU No.
You can check GPU below command.

$ nvidia-smi

gpu.png

In our environment, if you want use GPU No.0, the argument is 3.
(3-[argument No.]=[using GPU No.])
Deep Learning is very heavy computing, so you should use free one.

default setting is epoch 100.
Every epoch use 3/4 pictures of all pictures in "Picture".
100 epoch mean that the program use 100 times every picture of them for learning.

3rd step: Call "callgraph.py"

$ python callgraph.py

After "callvgg.py" stopped, you should call "callgraph.py".
"callgraph.py" makes "graph.png", error rate transition graph in training.

graph.png

In the picture, blue line is training data's error rate, and green line is training data's error rate.

"iteration" mean what times the program update own parameter.
In default, every iteration learn 16 pictures.

What model did "saku_cnn" use?

I set illustration2vec, a model based on OxfordNet ( VGGNet ).

How to use learned model data! ( added 19/02/2016 )

I prepared a sample program "check.py" for classification test.
After calling "callvgg.py", you can call "check.py".

$python check.py testPicture

"testPicture", the argument of "check.py" needs same format folders and pictures as "Picture".
In this example, "testPicture" has same pictures that "Picture" has.
However, you have to prepare different pictures from learning pictures for truly test, actually.

correct.png

If you call it, [ classified picture path ], [ classified class ] and [ classified true class or not ] 1 are displayed in one sentence.
After all sentences, the No. of correct classified pictures and not correct are displayed.

I want to use the example for cross validation test in changing some pattern of epoch parameter! ( added 19/02/2016 )

$ python callvgg.py 0 -E 10

If you want to change epoch parameter, you can use "-E" argument.
In this situation, the learning will finish in 10 epoch ( = use all pictures 10 times ).
Test data is checked in every 10 epoch, so I think you should choose the parameter from multiples of 10

$ python callvgg.py 0 -t 9

If you want to change the pattern of test data and train data, you use "-t" argument, too.

choice2.png

You can use only 10 types No., "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", as the argument of "-t".
The pictures in every class folder are sorted and divided 10 blocks.
If you choose "0" ( default setting ), you choose first 1/10 pictures block as test data in all class folders. ( As the above figure )
Therefore, in other words, you choose a test data block from the 10 blocks in the "0"-"9" argument.

As "callvgg.py" finish, actuary used test data's paths and labels are written in "test.txt", and train data's are written in "train.txt".
If you are uneasy, you can check them.

I think the arguments are useful for the 10 cross validation test.

References

ChainerのNINで自分の画像セットを深層学習させて認識させる
PFN発のディープラーニングフレームワークchainerで画像分類をするよ(chainerでニューラルネット1)
chainer-imagenet-vgg
illustration2vec
OxfordNet(VGGNet)


  1. In this situation, the name of class folder is regarded as true class.  

3
3
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
3
3