Each neuron can be initialized with specific weights. Keras provides a few choices, the most common of which are listed as follows:
random_uniform
: Weights are initialized to uniformly random small values in (-0.05, 0.05). In other words, any value within the given interval is equally likely to be drawn.random_normal
: Weights are initialized according to a Gaussian, with a zero mean and small standard deviation of 0.05. For those of you who are not familiar with a Gaussian, think about a symmetric bell curve shape.zero
: All weights are initialized to zero
A full list is available at https://keras.io/initializations/
Keras supports a number of activation functions, and a full list is available at https://keras.io/activations/.
Once we define the model, we have to compile it so that it can be executed by the Keras backend(either Theano or TensorFlow). Theare are a few choices to be made during compilation:
optimizer
that is the specific algorithm used to update weights while we train our modelobjective function
that is usede by the optimizer to navigate the space of weights (frequently, objective functions are called loss function
, and the process of optimization is defined as a process of loss minimization
)
Once the model is compiled, it can be then trained with the fit()
function, which specifies a few parameters:
epochs
: this is the number of times the model is exposed to the training set. At each iteration, the optimizer tries to adjust the weights so that the objective function is minimized.batch_size
: This is the number of training instances observed before the optimizer performs a weight update.score = model.evaluate(X_test, Y_test, verbose=VERBOSE) print("Test score:", score[0]) print('Test accuracy:', score[1])
When a net is trained, it can be course be used for predictions. In Keras, this is very simple. We can use the following method:
# Ccalculate predictions predictions = model.predict(X)
For a given input, several types of output can be computed, including a method:
tf
for the TensorFlow image ordering or th
for Theano image orderingepsilon
value used druing computationfloat32
or float64
tensorflow
or theano
th
: (depth, width, and height)
tf
: (width, height, and depth)
If you install a GPU-enabled TensorFlow version, then Keras will automatically use your configured GPU when TensorFlow is selected as the backend