项目作者: simongeek

项目描述 :
Keras VGG implementation for CIFAR-10 classification Tutorial
高级语言: Python
项目地址: git://github.com/simongeek/KerasVGGcifar10.git
创建时间: 2017-07-18T21:10:39Z
项目社区:https://github.com/simongeek/KerasVGGcifar10

开源协议:

下载


Keras VGG implementation for cifar-10 classification

What is Keras?

“Keras is an open source neural network library written in Python and capable of running on top of either TensorFlow, CNTK or Theano.

Use Keras if you need a deep learning libraty that:

  • Allows for easy and fast prototyping
  • Supports both convolutional networks and recurrent networks, as well as combinations of the two
  • Runs seamlessly on CPU and GPU

Keras is compatible with Python 2.7-3.5”[1].

Since Semptember 2016, Keras is the second-fastest growing Deep Learning framework after Google’s Tensorflow, and the third largest after Tensorflow and Caffe[2].

What is Deep Learning?

“Deep Learning is the application to learning tasks of artificial neural networks(ANNs) that contain more than one hidden layer. Deep learning is part of Machine Learning methods based on learning data representations.
Learning can be supervised, parially supervised or unsupervised[3].”

What will you learn?

You will learn:

  • What is Keras library and how to use it
  • What is Deep Learning
  • How to use ready datasets
  • What is Convolutional Neural Networks(CNN)
  • How to build step by step Convolutional Neural Networks(CNN)
  • What are differences in model results
  • What is supervised and unsupervised learning
  • Basics of Machine Learning
  • Introduction to Artificial Intelligence(AI)

Project structure

  • vgg.py - simple example of VGG16 neural net
  • README.md - description of this project

Convolutional Neural Network

VGG-16 neural network

Network Architecture

  1. OPERATION DATA DIMENSIONS WEIGHTS(N) WEIGHTS(%)
  2. Input ##### 3 32 32
  3. ZeroPadding2D \|||/ ------------------- 0 0.0%
  4. ##### 3 34 34
  5. Conv2D \|/ ------------------- 1792 0.0%
  6. relu ##### 64 32 32
  7. ZeroPadding2D \|||/ ------------------- 0 0.0%
  8. ##### 64 34 34
  9. Conv2D \|/ ------------------- 36928 0.1%
  10. relu ##### 64 32 32
  11. MaxPooling2D Y max ------------------- 0 0.0%
  12. ##### 64 16 16
  13. ZeroPadding2D \|||/ ------------------- 0 0.0%
  14. ##### 64 18 18
  15. Conv2D \|/ ------------------- 73856 0.2%
  16. relu ##### 128 16 16
  17. ZeroPadding2D \|||/ ------------------- 0 0.0%
  18. ##### 128 18 18
  19. Conv2D \|/ ------------------- 147584 0.4%
  20. relu ##### 128 16 16
  21. MaxPooling2D Y max ------------------- 0 0.0%
  22. ##### 128 8 8
  23. ZeroPadding2D \|||/ ------------------- 0 0.0%
  24. ##### 128 10 10
  25. Conv2D \|/ ------------------- 295168 0.9%
  26. relu ##### 256 8 8
  27. ZeroPadding2D \|||/ ------------------- 0 0.0%
  28. ##### 256 10 10
  29. Conv2D \|/ ------------------- 590080 1.8%
  30. relu ##### 256 8 8
  31. ZeroPadding2D \|||/ ------------------- 0 0.0%
  32. ##### 256 10 10
  33. Conv2D \|/ ------------------- 590080 1.8%
  34. relu ##### 256 8 8
  35. MaxPooling2D Y max ------------------- 0 0.0%
  36. ##### 256 4 4
  37. ZeroPadding2D \|||/ ------------------- 0 0.0%
  38. ##### 256 6 6
  39. Conv2D \|/ ------------------- 1180160 3.5%
  40. relu ##### 512 4 4
  41. ZeroPadding2D \|||/ ------------------- 0 0.0%
  42. ##### 512 6 6
  43. Conv2D \|/ ------------------- 2359808 7.0%
  44. relu ##### 512 4 4
  45. ZeroPadding2D \|||/ ------------------- 0 0.0%
  46. ##### 512 6 6
  47. Conv2D \|/ ------------------- 2359808 7.0%
  48. relu ##### 512 4 4
  49. MaxPooling2D Y max ------------------- 0 0.0%
  50. ##### 512 2 2
  51. ZeroPadding2D \|||/ ------------------- 0 0.0%
  52. ##### 512 4 4
  53. Conv2D \|/ ------------------- 2359808 7.0%
  54. relu ##### 512 2 2
  55. ZeroPadding2D \|||/ ------------------- 0 0.0%
  56. ##### 512 4 4
  57. Conv2D \|/ ------------------- 2359808 7.0%
  58. relu ##### 512 2 2
  59. ZeroPadding2D \|||/ ------------------- 0 0.0%
  60. ##### 512 4 4
  61. Conv2D \|/ ------------------- 2359808 7.0%
  62. relu ##### 512 2 2
  63. MaxPooling2D Y max ------------------- 0 0.0%
  64. ##### 512 1 1
  65. Flatten ||||| ------------------- 0 0.0%
  66. ##### 512
  67. Dense XXXXX ------------------- 2101248 6.2%
  68. relu ##### 4096
  69. Dropout | || ------------------- 0 0.0%
  70. ##### 4096
  71. Dense XXXXX ------------------- 16781312 49.9%
  72. relu ##### 4096
  73. Dropout | || ------------------- 0 0.0%
  74. ##### 4096
  75. Dense XXXXX ------------------- 40970 0.1%
  76. softmax ##### 10

Model

  1. model = Sequential()
  2. model.add(ZeroPadding2D((1, 1), input_shape=x_train.shape[1:]))
  3. model.add(Conv2D(64, (3, 3)))
  4. model.add(Activation('relu'))
  5. model.add(ZeroPadding2D((1, 1)))
  6. model.add(Conv2D(64, (3, 3)))
  7. model.add(Activation('relu'))
  8. model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  9. model.add(ZeroPadding2D((1, 1)))
  10. model.add(Conv2D(128, (3, 3)))
  11. model.add(Activation('relu'))
  12. model.add(ZeroPadding2D((1, 1)))
  13. model.add(Conv2D(128, (3, 3)))
  14. model.add(Activation('relu'))
  15. model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  16. model.add(ZeroPadding2D((1, 1)))
  17. model.add(Conv2D(256, (3, 3)))
  18. model.add(Activation('relu'))
  19. model.add(ZeroPadding2D((1, 1)))
  20. model.add(Conv2D(256, (3, 3)))
  21. model.add(Activation('relu'))
  22. model.add(ZeroPadding2D((1, 1)))
  23. model.add(Conv2D(256, (3, 3)))
  24. model.add(Activation('relu'))
  25. model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  26. model.add(ZeroPadding2D((1, 1)))
  27. model.add(Conv2D(512, (3, 3)))
  28. model.add(Activation('relu'))
  29. model.add(ZeroPadding2D((1, 1)))
  30. model.add(Conv2D(512, (3, 3)))
  31. model.add(Activation('relu'))
  32. model.add(ZeroPadding2D((1, 1)))
  33. model.add(Conv2D(512, (3, 3)))
  34. model.add(Activation('relu'))
  35. model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  36. model.add(ZeroPadding2D((1, 1)))
  37. model.add(Conv2D(512, (3, 3)))
  38. model.add(Activation('relu'))
  39. model.add(ZeroPadding2D((1, 1)))
  40. model.add(Conv2D(512, (3, 3)))
  41. model.add(Activation('relu'))
  42. model.add(ZeroPadding2D((1, 1)))
  43. model.add(Conv2D(512, (3, 3)))
  44. model.add(Activation('relu'))
  45. model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  46. model.add(Flatten())
  47. model.add(Dense(4096))
  48. model.add(Activation('relu'))
  49. model.add(Dropout(0.5))
  50. model.add(Dense(4096))
  51. model.add(Activation('relu'))
  52. model.add(Dropout(0.5))
  53. model.add(Dense(num_classes))
  54. model.add(Activation('softmax'))
  55. sgd = SGD(lr=0.1, decay=1e-6, nesterov=True)

Train model:

  1. model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
  2. return model
  3. cnn_n = base_model()
  4. cnn_n.summary()

Fit model:

  1. cnn = cnn_n.fit(x_train,y_train, batch_size=batch_size, epochs=epochs,validation_data=(x_test,y_test),shuffle=True)

Results:

All results are for 50k iteration, learning rate=0.01. Neural networks have benn trained at 16 cores and 16GB RAM on plon.io.

  • epochs = 10 accuracy=10.0%

x
y

Confusion matrix result:

  1. [[ 0 0 0 0 0 0 0 0 0 1000]
  2. [ 0 0 0 0 0 0 0 0 0 1000]
  3. [ 0 0 0 0 0 0 0 0 0 1000]
  4. [ 0 0 0 0 0 0 0 0 0 1000]
  5. [ 0 0 0 0 0 0 0 0 0 1000]
  6. [ 0 0 0 0 0 0 0 0 0 1000]
  7. [ 0 0 0 0 0 0 0 0 0 1000]
  8. [ 0 0 0 0 0 0 0 0 0 1000]
  9. [ 0 0 0 0 0 0 0 0 0 1000]
  10. [ 0 0 0 0 0 0 0 0 0 1000]]

Confusion matrix vizualizing

Time of learning process: xxx

  • epochs = 20 accuracy=%

Confusion matrix result:

Confusion matrix vizualizing

Time of learning process: xxx

  • epochs = 50 accuracy=%

Confusion matrix result:

Confusion matrix vizualizing

Time of learning process: xxx

  • epochs = 100 accuracy=%

Confusion matrix result:

Confusion matrix vizualizing

Time of learning process: xxx

.

Resources

Grab the code or run project in online IDE

You can also check here my other Keras Cifar-10 classification using 4,6-layer neural nets.