Nodes
This module contains the classes to define and create neural network layers.
The abstract class LayerNode
represents a generic NN layer, and its child ConcreteLayerNode
defines
the internal representation of all currently supported layers.
- class pynever.nodes.LayerNode(identifier)[source]
Bases:
ABC
An abstract class used for our internal representation of a generic Layer.
- class pynever.nodes.ConcreteLayerNode(identifier, in_dims, out_dim)[source]
Bases:
LayerNode
An abstract class used for our internal representation of a generic Layer. Its concrete children correspond to real network layers.
- identifier[source]
Identifier of the
ConcreteLayerNode
.- Type:
str
- in_dims[source]
Dimension of the input Tensor as a list of tuples (ndarray.shape like).
- Type:
list[tuple]
- class pynever.nodes.ReLUNode(identifier, in_dim)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a ReLU Layer.
- class pynever.nodes.ELUNode(identifier, in_dim, alpha=1.0)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of an ELU Layer.
- class pynever.nodes.CELUNode(identifier, in_dim, alpha=1.0)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a CELU Layer.
- class pynever.nodes.LeakyReLUNode(identifier, in_dim, negative_slope=0.01)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Leaky ReLU Layer.
- class pynever.nodes.SigmoidNode(identifier, in_dim)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Sigmoid Layer.
- class pynever.nodes.TanhNode(identifier, in_dim)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Tanh Layer.
- class pynever.nodes.FullyConnectedNode(identifier, in_dim, out_features, weight=None, bias=None, has_bias=True)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Fully Connected layer
- weight[source]
Tensor containing the weight parameters of the fully connected layer.
- Type:
torch.Tensor, Optional
- bias[source]
Tensor containing the bias parameters of the fully connected layer.
- Type:
torch.Tensor, Optional
- has_bias[source]
Flag True if the fully connected layer has bias, False otherwise (default: True)
- Type:
bool, Optional
- class pynever.nodes.BatchNormNode(identifier, in_dim, weight=None, bias=None, running_mean=None, running_var=None, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a one dimensional Batch Normalization Layer. N.B. There are some problem for compatibility between pytorch and onnx: pytorch provide 3 different kind of batchnorm layers which supports [(N, C) or (N, C, L)], (N, C, H, W) and (N, C, D, H, W) dimensional inputs respectively (BatchNorm1D, BatchNorm2D and BatchNorm3D). The batchnorm operation is always applied to the C dimension (N is the batch dimension which we do not keep track of). ONNX accepts input in the form of (N, C, D1, … , Dn) where N is the batch dimension and C is the dimension to which the batchnorm is applied. It should also be noted that at present the pytorch constructors do not support the setting of weight and bias explicitly.
- num_features[source]
Number of input and output feature of the Batch Normalization Layer.
- Type:
int
- weight[source]
Tensor containing the weight parameters of the Batch Normalization Layer. (default: None)
- Type:
torch.Tensor, Optional
- bias[source]
Tensor containing the bias parameter of the Batch Normalization Layer. (default: None)
- Type:
torch.Tensor, Optional
- running_mean[source]
Tensor containing the running mean parameter of the Batch Normalization Layer. (default: None)
- Type:
torch.Tensor, Optional
- running_var[source]
Tensor containing the running var parameter of the Batch Normalization Layer. (default: None)
- Type:
torch.Tensor, Optional
- eps[source]
Value added to the denominator for numerical stability (default: 1e-5).
- Type:
float, Optional
- momentum[source]
Value used for the running_mean and running_var computation. Can be set to None for cumulative moving average (default: 0.1)
- Type:
float, Optional
- affine[source]
When set to True, the module has learnable affine parameter (default: True).
- Type:
bool, Optional
- class pynever.nodes.ConvNode(identifier, in_dim, out_channels, kernel_size, stride, padding, dilation, groups, has_bias=False, bias=None, weight=None)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Convolutional layer. Also in this case the pytorch and onnx representation present incompatibilities. As in Batchnorm pytorch provide 3 different class for convolution based on the dimensionality of the input considered. Moreover, the padding is forced to be symmetric. The dimensionality supported for the input are (N, C, L), (N, C, H, W) and (N, C, D, H, W). In ONNX the padding can be asymmetric and the dimensionality supported is (N, C, D1, … , Dn) where D1, … Dn are the dimension on which the convolution is applied
- kernel_size[source]
The size of the kernel. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- stride[source]
Stride along each spatial axis. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- padding[source]
Padding for the beginning and ending along each spatial axis. Padding format should be as follows [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. Should have size equal to two times the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- has_bias[source]
Flag True if the convolutional layer has bias, False otherwise (default: False)
- Type:
bool, Optional
- bias[source]
Tensor containing the bias parameter of the Conv Layer (default: None)
- Type:
torch.Tensor, Optional
- class pynever.nodes.AveragePoolNode(identifier, in_dim, kernel_size, stride, padding, ceil_mode=False, count_include_pad=False)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a AveragePool layer. Also in this case the pytorch and onnx representation present incompatibilities. As in Batchnorm pytorch provide 3 different class for pooling based on the dimensionality of the input considered. Moreover, the padding is forced to be symmetric and the parameter divisor_override is present (it is not clear what is its effect). The dimensionality supported for the input are (N, C, L), (N, C, H, W) and (N, C, D, H, W). In ONNX the padding can be asymmetric and the dimensionality supported is (N, C, D1, … , Dn) where D1, … Dn are the dimension on which the pooling is applied
- kernel_size[source]
The size of the kernel. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- stride[source]
Stride along each spatial axis. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- padding[source]
Padding for the beginning and ending along each spatial axis. Padding format should be as follows [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. Should have size equal to two times the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- class pynever.nodes.MaxPoolNode(identifier, in_dim, kernel_size, stride, padding, dilation, ceil_mode=False, return_indices=False)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a MaxPool layer. Also in this case the pytorch and onnx representation present incompatibilities. As in Batchnorm pytorch provide 3 different class for pooling based on the dimensionality of the input considered. Moreover, the padding is forced to be symmetric. The dimensionality supported for the input are (N, C, L), (N, C, H, W) and (N, C, D, H, W). In ONNX the padding can be asymmetric and the dimensionality supported is (N, C, D1, … , Dn) where D1, … Dn are the dimension on which the pooling is applied
- kernel_size[source]
The size of the kernel. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- stride[source]
Stride along each spatial axis. Should have size equal to the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- padding[source]
Padding for the beginning and ending along each spatial axis. Padding format should be as follows [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. Should have size equal to two times the number of dimension n (we don’t count the channel dimension).
- Type:
tuple
- class pynever.nodes.LRNNode(identifier, in_dim, size, alpha=0.0001, beta=0.75, k=1.0)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a LocalResponseNormalization Layer.
- class pynever.nodes.SoftMaxNode(identifier, in_dim, axis=-1)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a SoftMax Layer.
- class pynever.nodes.UnsqueezeNode(identifier, in_dim, axes)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of an Unsqueeze Layer. We follow the ONNX operator convention for attributes and definitions.
- class pynever.nodes.ReshapeNode(identifier, in_dim, shape, allow_zero=False)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Reshape layer. We follow the ONNX operator convention for attributes and definitions.
- allow_zero[source]
By default, when any value in the ‘shape’ input is equal to zero the corresponding dimension value is copied from the input tensor dynamically. allowzero=1 indicates that if any value in the ‘shape’ input is set to zero, the zero value is honored, similar to NumPy. (default: False)
- Type:
bool, Optional
- class pynever.nodes.FlattenNode(identifier, in_dim, axis=0)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Flatten layer. We follow the ONNX operator convention for attributes and definitions.
- axis[source]
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 … d_n)), where the shape of the input tensor is (d_0, d_1, … d_n). N.B: it works assuming the initial batch dimension. (default: 0)
- Type:
int, Optional
- class pynever.nodes.DropoutNode(identifier, in_dim, p=0.5)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Dropout Layer. The inplace parameter of pytorch and the seed attribute and training_mode of onnx are not supported.
- class pynever.nodes.TransposeNode(identifier, in_dim, perm=None)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Dropout Layer. The inplace parameter of pytorch and the seed attribute and training_mode of onnx are not supported.
- class pynever.nodes.ConcatNode(identifier, in_dims, axis=-1)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Concat Layer. Concatenate two tensors into a single tensor. All input tensors must have the same shape, except for the dimension size of the axis to concatenate on.
- class pynever.nodes.SumNode(identifier, in_dims)[source]
Bases:
ConcreteLayerNode
A class used for our internal representation of a Sum Layer. Element-wise sum of each of the input tensors. All inputs and outputs must have the same data type.