deel.lip.model
This module contains equivalents for Model and Sequential. These classes add support for condensation and vanilla exportation.
Model ¶
Bases: Model
Equivalent of keras.Model but support condensation and vanilla exportation.
Warning
As lipschitz constant are multiplicative along layer, the Model class cannot set a global Lipschitz constant (problem with branching inside a model).
condense ¶
condense()
The condense operation allows to overwrite the kernel with constrained kernel and ensure that other variables are still consistent.
Source code in deel/lip/model.py
126 127 128 129 130 131 132 133 |
|
vanilla_export ¶
vanilla_export()
Export this model to a "Vanilla" model, i.e. a model without Condensable layers.
RETURNS | DESCRIPTION |
---|---|
Model
|
A Keras model, identical to this model, but where condensable layers have been replaced with their vanilla equivalent (e.g. SpectralConv2D with Conv2D). |
Source code in deel/lip/model.py
135 136 137 138 139 140 141 142 143 144 145 |
|
Sequential ¶
Sequential(layers=None, name=None, k_coef_lip=1.0)
Bases: Sequential
, LipschitzLayer
, Condensable
Equivalent of keras.Sequential but allow to set k-lip factor globally. Also support condensation and vanilla exportation. For now constant repartition is implemented (each layer get n_sqrt(k_lip_factor), where n is the number of layers) But in the future other repartition function may be implemented.
PARAMETER | DESCRIPTION |
---|---|
layers |
list of layers to add to the model.
TYPE:
|
name |
name of the model, can be None
TYPE:
|
k_coef_lip |
the Lipschitz coefficient to ensure globally on the model.
TYPE:
|
Source code in deel/lip/model.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
vanillaModel ¶
vanillaModel(model)
Transform a model to its equivalent "vanilla" model, i.e. a model where
Condensable
layers are replaced with their vanilla equivalent. For example,
SpectralConv2D
layers are converted to tf.keras Conv2D
layers.
The input model can be a tf.keras Sequential/Model or a deel.lip Sequential/Model.
PARAMETER | DESCRIPTION |
---|---|
model |
a tf.keras or deel.lip model with Condensable layers.
|
RETURNS | DESCRIPTION |
---|---|
A Keras model, identical to the input model where |
Source code in deel/lip/model.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|