CORE - Using a Network
Dedicated code in Core/Network module.
Network Implementation
A Network cannot be directly implemented from BaseNetwork because there is no dependency on any Python AI package. Even if a BaseNetwork is not usable, any DeepPhysX AI package provides the same API.
Note
Before writing code to create a new Network architecture, please check DeepPhysX AI packages if it is not already implemented.
|
Define the Network architecture. |
|
Define the data fields used to compute a prediction. |
|
Define the forward pass of the Network. |
|
Configure the Network to training mode (chain rule for gradient will be calculated). |
|
Configure the Network to prediction mode (no gradient will be calculated). |
|
Define whether tensors computations are done on the CPU or on the GPU. |
|
Load a set of saved parameters from a file. This set of parameters must be compatible with the current Network architecture. |
|
Return the current state of Network parameters. |
|
Save the current set of parameters to a file.. |
|
Return the number of parameters in the architecture. |
|
Convert a Numpy array to a tensor with the compatible type. Received data from Core will always be Numpy arrays. |
|
Convert a tensor to a Numpy array. Data provided to Core must be converted to Numpy arrays. |
self.net_fields
,
self.pred_fields
& self.opt_fields
variables.Optimization Implementation
The purpose of the Optimization component is to compute the loss associated with the prediction of the Network and to optimize its parameters considering the gradient. Same as BaseNetwork, BaseOptimization cannot be used in training sessions as it must depend on a Python AI framework. However, Optimization components still share the same API in every DeepPhysX package. Given a Python AI framework, methods should all be already implemented so that users can use them as it is.
|
Initialize the loss function. |
|
Initialize the Optimizer with the parameters of the Network. |
|
Compute the loss with the defined loss function from prediction and ground truth. |
|
Apply a transformation on the loss value using potential additional data. Additional loss data can be sent from Environment (see dedicated section). |
|
Run an optimization step to adapt the parameters of the Network according to the loss gradient. |
Data Transformation Implementation
DataTransformation objects are dedicated to tensor transformations at different levels when streaming data through Network and Optimization objects. These transformations are automatically called with the pipeline and apply the identity transformation by default. Users are then free to define their own tensor transformations with the following methods.
|
Apply a tensor transformation to the Network data (before a prediction). |
|
Apply a tensor transformation to the ground truth data and / or the prediction data (after the prediction, before the loss computation). |
|
Apply a tensor transformation to the prediction data (before sending it to the Environment). |
Configurations
Using a Network, an Optimizer and a DataTransformation in one of the DeepPhysX Pipeline always requires a
NetworkConfig.
This Configuration object role is both to bring together all the options for configuring this set of objects and to
create them.
Objects are created within the create_network
, create_optimization
and create_data_transformation
methods
respectively.
|
Network class from which an instance will be created. |
|
Path to an existing Network repository with saved parameters. |
|
Name of the Network object. |
|
Type of the Network. |
|
If several sets of parameters are saved in By default, the last save is loaded. |
|
If True, Network parameters will be saved at the end of each training epoch. Otherwise, they are only saved at the end of the training session. |
|
Optimization class from which an instance will be created. |
|
Learning rate value. |
|
Loss class that will be used to compute loss value. |
|
Optimizer class that will be used to optimize the Network parameters. |
|
In the case where a loss class and / or an optimizer class (training stuff) are not used for training, users must set this option to False. |
|
DataTransformation class from which an instance will be created. |
See following example:
# Import NetworkConfig
from DeepPhysX_Core.Dataset.BaseNetworkConfig import BaseNetworkConfig
# Choose classes
MyNetwork = ... # Define a network architecture or take one from an AI package
MyOptimizationClass = ... # Pick the one from an AI package
MyDataTransformation = ... # Define tensor transformations or use default one from an AI package
MyLoss = ... # Choose one from the AI base framework
MyOptimizer = ... # Choose one from the AI base framework
# Create the config
network_config = BaseNetworkConfig(network_class=MyNetwork,
optimization_class=MyOptimizationClass,
data_transformation_class=MyDataTransformation,
lr=1e-5,
loss=
loss=MyLoss,
optimizer=MyOptimizer)