I had a chance to write Keras, so I translated something like Keras's simple tutorial into Japanese. Getting started: 30 seconds to Keras Keras defines the data structure in model. The most commonly used of these is Sequential, and if you want to define a layer with a more complex architecture, use the Keras function API. It is necessary to confirm. Use the Sequential model as follows.
from keras.model import Sequential
model = Sequential()
Use .add ()
to stack layers.
from keras.layers.core import Dense, Activation
model.add(Dense(output_dim=64, input_dim=100))
model.add(Activation("relu"))
model.add(Dense(output_dim=10))
model.add(Activation("softmax"))
After creating the model, use .compile ()
to set up the model training process.
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
If you need to describe the optimizer in more detail, you can. Keras believes in dealing with problems reasonably and simply, but on the other hand, user customization is possible in any part.
from keras.optimizers import SGD
model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.01, momentum=0.9, nesterov=True))
After determining the calculation path up to this point, the training data can be turned.
model.fit(X_train, Y_train, nb_epoch=5, batch_size=32)
You can also feed the model you created the batch manually.
model.train_on_batch(X_batch, Y_batch)
You can evaluate the created model in one line.
loss_and_metrics = model.evaluate(X_test, Y_test, batch_size=32)
To make a prediction for new data, do as follows.
classes = model.predict_classes(X_test, batch_size=32)
proba = model.predict_proba(X_test, batch_size=32)
Simple one-way deep learning can be easily described like this. The idea of deep learning is so simple, why should it be painful to implement (no, that's not the case).
For a more detailed tutorial
You can check with. Models such as LSTM are placed on the example page of github.
Getting started with the Keras Sequential model has also been translated into Japanese.
Recommended Posts