Conversion

pyNeVer provides conversion capabilities to import a NN model in the ONNX and pyTorch file formats, as well as to export to these formats trained NNs.

Representation

class pynever.strategies.conversion.representation.AlternativeRepresentation(path, identifier=None)[source]

Bases: ABC

An abstract class used to represent an alternative representation for a neural network.

identifier[source]

identifier for the alternative representation

Type:

str

class pynever.strategies.conversion.representation.ONNXNetwork[source]

Bases: AlternativeRepresentation

A class used to represent a ONNX representation for a neural network.

onnx_network[source]

Real ONNX network.

Type:

onnx.ModelProto

class pynever.strategies.conversion.representation.PyTorchNetwork[source]

Bases: AlternativeRepresentation

A class used to represent a PyTorch representation for a neural network.

pytorch_network[source]

Real PyTorch network.

Type:

torch.nn.Module

class pynever.strategies.conversion.representation.ConversionStrategy[source]

Bases: ABC

An abstract class used to represent a Conversion Strategy.

abstractmethod from_neural_network(network)[source]

Convert the neural network of interest to an alternative representation determined in the concrete children.

Parameters:

network (NeuralNetwork) – The neural network to convert.

Returns:

The alternative representation resulting from the conversion of the original network.

Return type:

AlternativeRepresentation

abstractmethod to_neural_network(alt_rep)[source]

Convert the alternative representation of interest to the internal one.

Parameters:

alt_rep (AlternativeRepresentation) – The Alternative Representation to convert.

Returns:

The Neural Network resulting from the conversion of Alternative Representation.

Return type:

NeuralNetwork

pynever.strategies.conversion.representation.load_network_path(path)[source]

Method to load a network from a path in an Alternative Representation.

Parameters:

path (str) – Path to the network.

Returns:

The AlternativeRepresentation object if the network is supported, None otherwise.

Return type:

Optional[AlternativeRepresentation]

Converters

class pynever.strategies.conversion.converters.onnx.ONNXConverter[source]

Bases: ConversionStrategy

A class used to represent the conversion strategy for ONNX models.

from_neural_network(network)[source]

Convert the neural network of interest to a ONNX representation.

Parameters:

network (NeuralNetwork) – The neural network to convert.

Returns:

The ONNX representation resulting from the conversion of the original network.

Return type:

ONNXNetwork

to_neural_network(alt_rep)[source]

Convert the ONNX representation of interest to the internal one.

Parameters:

alt_rep (ONNXNetwork) – The ONNX Representation to convert.

Returns:

The Neural Network resulting from the conversion of ONNX Representation.

Return type:

NeuralNetwork

class pynever.strategies.conversion.converters.pytorch.PyTorchConverter[source]

Bases: ConversionStrategy

A class used to represent the conversion strategy for PyTorch models.

from_neural_network(network)[source]

Convert the neural network of interest to a PyTorch representation.

Parameters:

network (NeuralNetwork) – The neural network to convert.

Returns:

The PyTorch representation resulting from the conversion of the original network.

Return type:

PyTorchNetwork

to_neural_network(alt_rep)[source]

Convert the PyTorch representation of interest to the internal one.

Parameters:

alt_rep (PyTorchNetwork) – The PyTorch Representation to convert.

Returns:

The Neural Network resulting from the conversion of PyTorch Representation.

Return type:

NeuralNetwork