deel.lip.model module¶
This module contains equivalents for Model and Sequential. These classes add support for condensation and vanilla exportation.
-
class
deel.lip.model.
Model
(*args, **kwargs)¶ Bases:
tensorflow.python.keras.engine.training.Model
,deel.lip.layers.Condensable
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
()¶ The condense operation allow to overwrite the kernel and ensure that other variables are still consistent.
- Returns
None
-
vanilla_export
()¶ This operation allow to turn this Layer to it’s super type, easing storage and serving.
- Returns
self as super type
-
-
class
deel.lip.model.
Sequential
(*args, **kwargs)¶ Bases:
tensorflow.python.keras.engine.sequential.Sequential
,deel.lip.layers.LipschitzLayer
,deel.lip.layers.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.
- Parameters
layers – list of layers to add to the model.
name – name of the model, can be None
k_coef_lip – the Lipschitz coefficient to ensure globally on the model.
-
build
(input_shape=None)¶ Builds the model based on input shapes received.
This is to be used for subclassed models, which do not know at instantiation time what their inputs look like.
This method only exists for users who want to call model.build() in a standalone way (as a substitute for calling the model on real data to build it). It will never be called by the framework (and thus it will never throw unexpected errors in an unrelated workflow).
- Parameters
input_shape – Single tuple, TensorShape, or list of shapes, where shapes are tuples, integers, or TensorShapes.
- Raises
ValueError –
In case of invalid user-provided data (not of type tuple, list, or TensorShape). 2. If the model requires call arguments that are agnostic to the input shapes (positional or kwarg in call signature). 3. If not all layers were properly built. 4. If float type inputs are not supported within the layers.
In each of these cases, the user should build their model by calling it –
on real tensor data. –
-
condense
()¶ The condense operation allow to overwrite the kernel and ensure that other variables are still consistent.
- Returns
None
-
get_config
()¶ Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
- Returns
Python dictionary.
-
set_klip_factor
(klip_factor)¶ Allow to set the lipschitz factor of a layer.
- Parameters
klip_factor – the Lipschitz factor the user want to ensure.
- Returns
None
-
vanilla_export
()¶ This operation allow to turn this Layer to it’s super type, easing storage and serving.
- Returns
self as super type
-
deel.lip.model.
vanillaModel
(self)¶ This operation allow to turn this Layer to it’s super type, easing storage and serving.
- Returns
self as super type