1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Keras勉強メモ: CIFAR-10画像認識での、ネットワーク構造依存を確認してみた

1
Last updated at Posted at 2017-07-22
  • MNIST手書き文字の次に、いわゆる画像、の認識にトライしよう、とCIFAR-10に。
  • CIFAR-10は、飛行機からトラックまでの、たった10カテゴリーの分類課題。ピクセル数も32x32とコンパクトですが、画像の例を見てみると、実に多様なデータが含まれていると思います。
  • これが、簡単なコードと、8年もののiMacで、ランチを食べている間に、8割方認識できてしまう。あらためて、不思議に感じられてきました。

CIFAR-10データベース

img04.png


トライしたネットワーク構造

Conv1 Conv2 Pool DO Conv3 Conv4 Conv5 Pool DO Dense DO
3x3 3x3 2x2 25% 3x3 3x3 3x3 2x2 25% 128~528 50%
32 32 64 64 64

Convolution層数

img01.png

  • 4層まで、Test認識率が向上。
  • 5層の方が、過学習(Train-Test)も小さそうだが、ステップ毎計算時間も比例して増える。

Dense層ノード数

img02-2.png

  • Denseノード数が多い方が、過学習(Train-Test)が小さく見えるが、

img03.png

  • ノード数が多いと、学習途中の損失関数の低下が遅くなってくる。縦軸が同じ(例 0.5)の時点で比較すると、過学習の度合いはほぼ同じだった。

コメント

  • 次は、フィルターサイズ3x3とPadding、フィルター種数を変えて確認しようかと。フィルターサイズは元画像の分解能、フィルター種数はエッジ角度分解能等、層数は抽出特徴の組み合わせ段数、などと関係するのでは。

今回使用したコード例

import numpy as np

import keras
from keras.datasets import cifar10
from keras.utils import to_categorical
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense

if __name__ == '__main__':
  nb_classes = 10
  batch_size = 128
  epochs = 24

  (X_train, y_train), (X_test, y_test) = cifar10.load_data()
  print(X_train.shape, y_train.shape, X_test.shape, y_test.shape)
  X_train = X_train.astype('float32')/ 255
  X_test = X_test.astype('float32') / 255
  Y_train = to_categorical(y_train, nb_classes)
  Y_test = to_categorical(y_test, nb_classes)
  
  model = Sequential()
  model.add(Conv2D(32, (3, 3), input_shape=X_train.shape[1:], activation='relu', padding='same'))
  model.add(Conv2D(32, (3, 3), activation='relu', padding='same'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))
  
  model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
  model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))

  model.add(Flatten())
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(nb_classes, activation='softmax'))

  model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  model.summary()
  
  model.fit(X_train, Y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_split=0.1)

  loss, acc = model.evaluate(X_test, Y_test, verbose=0)
  print('Test loss:', loss)
  print('Test acc:', acc)
1
1
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?