Usage of constraints
Functions from the constraints
module allow setting constraints (eg. non-negativity) on network parameters during optimization.
The penalties are applied on a per-layer basis. The exact API will depend on the layer, but the layers Dense
, Convolution1D
, Convolution2D
and Convolution3D
have a unified API.
These layers expose 2 keyword arguments:
kernel_constraint
for the main weights matrixbias_constraint
for the bias.
from keras.constraints import maxnorm
model.add(Dense(64, kernel_constraint=max_norm(2.)))
Available constraints
- max_norm(max_value=2, axis=0): maximum-norm constraint
- non_neg(): non-negativity constraint
- unit_norm(): unit-norm constraint, enforces the matrix to have unit norm along the last axis