barus's diary

とても真面目なblogですにゃ

深層畳み込みニューラルネットワーク(その④)Pythonで動かす。~network3_test3.py

今回は、深層畳み込みニューラルネットワークの実行例③

 

① network3_test1.py

② network3_test2.py

③ network3_test3.py

 

①,②については過去記事参照。

theanoのバージョンと、DeepLearningPython35-master.zipのコミットバージョンは以下を用意する。

 

theanoバージョン0.9

DeepLearningPython35-master.zip(Latest commit a8da42f on 28 Aug)

 

PythonのAnaconda3をインストール(インストール方法)し、こちらのサイトの「Clone or Download」をクリックしてDeepLearningPython35-master.zipを取得し解凍する。以下のソースコードを「network3_test3.py」名で、「network3.py」がある同じフォルダに作成する。 MNISTの訓練データを解凍して、フォルダdataをDeepLearningPython35-master.zipを解凍した同じディレクトリに配置する。

フォルダ構成は以下のような感じになります。

 

f:id:hatakeka:20171106165913p:plain

 

 network3_test3.py

import network3
from network3 import Network
from network3 import ConvPoolLayer, FullyConnectedLayer, SoftmaxLayer
from network3 import ReLU

def main():
    training_data, validation_data, test_data = network3.load_data_shared()
    mini_batch_size = 10
    print ("network3\n");

    net = Network([
          ConvPoolLayer(image_shape=(mini_batch_size, 1, 28, 28),
                        filter_shape=(20, 1, 5, 5),
                        poolsize=(2, 2)),
          ConvPoolLayer(image_shape=(mini_batch_size, 20, 12, 12),
                        filter_shape=(40, 20, 5, 5),
                        poolsize=(2, 2)),
          FullyConnectedLayer(n_in=40*4*4, n_out=100),
          SoftmaxLayer(n_in=100, n_out=10)], mini_batch_size)
    net.SGD(training_data, 3, mini_batch_size, 0.1,
              validation_data, test_data)
  
    return 0


if __name__ == "__main__":
    main()

 

 

実行結果

 

s:\plog\Python\python3\DeepLearningPython35-master>python network3_test3.py
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
Trying to run under a GPU. If this is not desired, then modify network3.py
to set the GPU flag to False.
network3

Training mini-batch number 0
Training mini-batch number 1000
Training mini-batch number 2000
Training mini-batch number 3000
Training mini-batch number 4000
Epoch 0: validation accuracy 95.96%
This is the best validation accuracy to date.
The corresponding test accuracy is 95.71%
Training mini-batch number 5000
Training mini-batch number 6000
Training mini-batch number 7000
Training mini-batch number 8000
Training mini-batch number 9000
Epoch 1: validation accuracy 97.48%
This is the best validation accuracy to date.
The corresponding test accuracy is 97.31%
Training mini-batch number 10000
Training mini-batch number 11000
Training mini-batch number 12000
Training mini-batch number 13000
Training mini-batch number 14000
Epoch 2: validation accuracy 97.97%
This is the best validation accuracy to date.
The corresponding test accuracy is 97.85%
Finished training network.
Best validation accuracy of 97.97% obtained at iteration 14999
Corresponding test accuracy of 97.85%

s:\plog\Python\python3\DeepLearningPython35-master>

 

 

と、なった。

 

以上