深度学习(Deep Learning) 3.Example
1 Introduction
- Keras:easy to learn,作者 Francois Chollet现在google工作,keras已成为Tensorflow的官方API。
- Keras means horn(角)in Greek
2 MNIST
- 手写数字识别:deep learning中的hello world
model = Sequential()
model.add(Dense( input_dim = 28*28, output_dim = 500))
model.add(Activation('sigmoid'))
model.add(Dense( output_dim = 500))
model.add(Activation('sigmoid'))
model.add(Dense( output_dim = 10))
model.add(Activation('softmax'))
model.compile(loss = 'categorical crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.fit(x_train, y_train, batch_size = 100, nb_epoch = 20)
score = model.evaluate(x_test, y_test)
print('Total loss on Testing Set:', score[0])
print('Accuracy of Testing Set:', score[1])
- optimizer中:SGD、RMSprop、Adagrad、Adadelta、Adam、Adamax、Nadam
- SGD中batch_size = 1
- batch_size更大时运算速度更快,因为过程中实现了并行运算(GPU加速)