Network

BaseNetwork

class BaseNetwork.BaseNetwork(config: namedtuple)[source]
forward(input_data: Any) Any[source]

Compute a forward pass of the Network.

Parameters

input_data – Input tensor.

Returns

Network prediction.

get_parameters() Dict[str, Any][source]

Return the current state of Network parameters.

Returns

Network parameters.

load_parameters(path: str) None[source]

Load network parameter from path.

Parameters

path – Path to Network parameters to load.

nb_parameters() int[source]

Return the number of parameters of the network.

Returns

Number of parameters.

numpy_to_tensor(data: ndarray, grad: bool = True) Any[source]

Transform and cast data from numpy to the desired tensor type.

Parameters
  • data – Array data to convert.

  • grad – If True, gradient will record operations on this tensor.

Returns

Converted tensor.

predict(data_net: Dict[str, Any]) Dict[str, Any][source]

Compute a forward pass of the Network.

Parameters

data_net – Data used by the Network.

Returns

Data produced by the Network.

save_parameters(path: str) None[source]

Saves the network parameters to the path location.

Parameters

path – Path where to save the parameters.

set_device() None[source]

Set computer device on which Network’s parameters will be stored and tensors will be computed.

set_eval() None[source]

Set the Network in prediction mode (does not compute gradient).

set_train() None[source]

Set the Network in training mode (compute gradient).

tensor_to_numpy(data: Any) ndarray[source]

Transform and cast data from tensor type to numpy.

Parameters

data – Tensor to convert.

Returns

Converted array.

BaseNetworkConfig

class BaseNetworkConfig.BaseNetworkConfig(network_class: ~typing.Type[~DeepPhysX.Core.Network.BaseNetwork.BaseNetwork] = <class 'DeepPhysX.Core.Network.BaseNetwork.BaseNetwork'>, optimization_class: ~typing.Type[~DeepPhysX.Core.Network.BaseOptimization.BaseOptimization] = <class 'DeepPhysX.Core.Network.BaseOptimization.BaseOptimization'>, data_transformation_class: ~typing.Type[~DeepPhysX.Core.Network.BaseTransformation.BaseTransformation] = <class 'DeepPhysX.Core.Network.BaseTransformation.BaseTransformation'>, network_dir: ~typing.Optional[str] = None, network_name: str = 'Network', network_type: str = 'BaseNetwork', which_network: int = -1, save_each_epoch: bool = False, data_type: str = 'float32', lr: ~typing.Optional[float] = None, require_training_stuff: bool = True, loss: ~typing.Optional[~typing.Any] = None, optimizer: ~typing.Optional[~typing.Any] = None)[source]
create_data_transformation() BaseTransformation[source]

Create an instance of data_transformation_class with given parameters.

Returns

BaseTransformation object from data_transformation_class and its parameters.

create_network() BaseNetwork[source]

Create an instance of network_class with given parameters.

Returns

BaseNetwork object from network_class and its parameters.

create_optimization() BaseOptimization[source]

Create an instance of optimization_class with given parameters.

Returns

BaseOptimization object from optimization_class and its parameters.

BaseOptimization

class BaseOptimization.BaseOptimization(config: namedtuple)[source]
compute_loss(data_pred: Dict[str, Any], data_opt: Dict[str, Any]) Dict[str, Any][source]

Compute loss from prediction / ground truth.

Parameters
  • data_pred – Tensor produced by the forward pass of the Network.

  • data_opt – Ground truth tensor to be compared with prediction.

Returns

Loss value.

optimize() None[source]

Run an optimization step.

set_loss() None[source]

Initialize the loss function.

set_optimizer(net: BaseNetwork) None[source]

Define an optimization process.

Parameters

net – Network whose parameters will be optimized.

transform_loss(data_opt: Dict[str, Any]) Dict[str, float][source]

Apply a transformation on the loss value using the potential additional data.

Parameters

data_opt – Additional data sent as dict to compute loss value

Returns

Transformed loss value.

DataTransformation

class BaseTransformation.BaseTransformation(config: namedtuple)[source]
transform_before_apply(data_pred: Dict[str, Any]) Dict[str, Any][source]

Apply data operations between loss computation and prediction apply in environment.

Parameters

data_pred – Data produced by the Network.

Returns

Transformed data_pred.

transform_before_loss(data_pred: Dict[str, Any], data_opt: Optional[Dict[str, Any]] = None) Tuple[Dict[str, Any], Optional[Dict[str, Any]]][source]

Apply data operations between network’s prediction and loss computation.

Parameters
  • data_pred – Data produced by the Network.

  • data_opt – Data used by the Optimizer.

Returns

Transformed data_pred, data_opt.

transform_before_prediction(data_net: Dict[str, Any]) Dict[str, Any][source]

Apply data operations before network’s prediction.

Parameters

data_net – Data used by the Network.

Returns

Transformed data_net.