Perceptron
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/.
One-hot encoding - OHE
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:
- We need to select the
optimizer
that is the specific algorithm used to update weights while we train our model - We need to select the
objective function
that is usede by the optimizer to navigate the space of weights (frequently, objective functions are calledloss function
, and the process of optimization is defined as a process of lossminimization
) - We need to evaluate the trained model
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.
- snippet.python
score = model.evaluate(X_test, Y_test, verbose=VERBOSE) print("Test score:", score[0]) print('Test accuracy:', score[1])
Predictg output
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:
- snippet.python
# Ccalculate predictions predictions = model.predict(X)
For a given input, several types of output can be computed, including a method:
- model.evaluate(): This is used to compute the loss values
- model.predictclasses(): This is used to compute category outputs
- model.predictproba(): This si used to compute class probabilities
Configuring Keras
- imagedimordering : Can be either
tf
for the TensorFlow image ordering orth
for Theano image ordering - epsilon: The
epsilon
value used druing computation - floatx: Can be either
float32
orfloat64
- backend: Can be either
tensorflow
ortheano
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