由于是神经网络小白,在运行demo的时候不懂keras的版本问题,出现了一下的警告:
C:\ProgramData\Anaconda2\python.exe "F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN4.py"
Using Theano backend.
F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN4.py:27: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(30, (5, 5), padding="valid", activation="relu", input_shape=(1, 28, 28...)`
model.add(Convolution2D(30, 5, 5, border_mode='valid', input_shape=(1, 28, 28), activation='relu'))
F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN4.py:30: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(15, (3, 3), activation="relu")`
model.add(Convolution2D(15, 3, 3, activation='relu'))
C:\ProgramData\Anaconda2\lib\site-packages\keras\models.py:826: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
warnings.warn('The `nb_epoch` argument in `fit` '
出现这些警告是由于keras的版本更新的问题,这里是keras2.0的更新文档的链接:
https://github.com/fchollet/keras/wiki/Keras-2.0-release-notes
再说说我出现的警告的解决方式:
1、The nb_epoch argument has been renamed epochs everywhere.所以神经网络的训练次数需要用epochs来定义,不再是nb_epoch 。
model.fit(X_train, y_train, validation_data=(X_test, y_test), nb_epoch=69, batch_size=200, verbose=2)
model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=69, batch_size=200, verbose=2)
2、Convolution* layers are renamed Conv*.所以定义卷积层需要用Conv2D而不再是Convolution2D。
model.add(Convolution2D(32, (5, 5), padding='valid', input_shape=(1, 28, 28), activation='relu'))
model.add(Conv2D(32, (5, 5), padding='valid', input_shape=(1, 28, 28), activation='relu'))
相应的导入的包是:
from keras.layers.convolutional import Conv2D
不再是:
from keras.layers.convolutional import Convolution2D
再次运行demo的话警告全无!
所以作为初学者还是需要注意keras2.0版本的一些写法上的差别。笔者目前只碰到这样俩个问题,如有其他的关于keras2.0版本上的问题,请参考笔者上面给出的链接,自信查阅。
参考网站:
1、https://github.com/fchollet/keras/wiki/Keras-2.0-release-notes 2017.4.5