qualia2.nn.modules package¶
Submodules¶
qualia2.nn.modules.activation module¶
qualia2.nn.modules.conv module¶
-
class
qualia2.nn.modules.conv.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.Module‘Applies a 1D convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (int): Size of the convolving kernel stride (int): Stride of the convolution. Default: 1 padding (int): Zero-padding added to both sides of the input. Default: 0 dilation (int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, W]
Output: [N, out_channels, W_out]
-
class
qualia2.nn.modules.conv.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (tuple of int): Size of the convolving kernel stride (tuple of int): Stride of the convolution. Default: 1 padding (tuple of int): Zero-padding added to both sides of the input. Default: 0 dilation (tuple of int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, H, W]
Output: [N, out_channels, H_out, W_out]
H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0]+1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1]+1
-
class
qualia2.nn.modules.conv.Conv3d(in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (tuple of int): Size of the convolving kernel stride (tuple of int): Stride of the convolution. Default: 1 padding (tuple of int): Zero-padding added to both sides of the input. Default: 0 dilation (tuple of int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, D, H, W]
Output: [N, out_channels, D_out, H_out, W_out]
-
class
qualia2.nn.modules.conv.ConvTranspose1d(in_channels, out_channels, kernel_size, stride=1, padding=1, output_padding=0, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 1D transposed convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (tuple of int): Size of the convolving kernel stride (tuple of int): Stride of the convolution. Default: 1 padding (tuple of int): Zero-padding added to both sides of the input. Default: 1 output_padding (tuple of int): Zero-padding added to both sides of the output. Default: 0 dilation (tuple of int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, W]
Output: [N, out_channels, W_out]
-
class
qualia2.nn.modules.conv.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=1, padding=1, output_padding=0, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D transposed convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (tuple of int): Size of the convolving kernel stride (tuple of int): Stride of the convolution. Default: 1 padding (tuple of int): Zero-padding added to both sides of the input. Default: 1 output_padding (tuple of int): Zero-padding added to both sides of the output. Default: 0 dilation (tuple of int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, H, W]
Output: [N, out_channels, H_out, W_out]
H_out = (H-1)*stride[0]-2*padding[0]+dilation[0]*(kernel_size[0]-1)+1+output_padding[0] W_out = (W-1)*stride[1]-2*padding[1]+dilation[1]*(kernel_size[1]-1)+1+output_padding[1]
-
class
qualia2.nn.modules.conv.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=1, padding=1, output_padding=0, dilation=1, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D transposed convolution over an input signal composed of several input planes.
- Args:
in_channels (int): Number of channels in the input image out_channels (int): Number of channels produced by the convolution kernel_size (tuple of int): Size of the convolving kernel stride (tuple of int): Stride of the convolution. Default: 1 padding (tuple of int): Zero-padding added to both sides of the input. Default: 1 output_padding (tuple of int): Zero-padding added to both sides of the output. Default: 0 dilation (tuple of int): Spacing between kernel elements. Default: 1 bias (bool): adds a learnable bias to the output. Default: True
- Shape:
Input: [N, in_channels, D, H, W]
Output: [N, out_channels, D_out, H_out, W_out]
qualia2.nn.modules.dropout module¶
-
class
qualia2.nn.modules.dropout.Dropout(p=0.5)[source]¶ Bases:
qualia2.nn.modules.module.ModuleDuring training, randomly zeroes some of the elements of the input tensor with probability p using samples from a Bernoulli distribution. Each channel will be zeroed out independently on every forward call.
- Args:
p (float): probability of an element to be zeroed. Default: 0.5
- Shape:
Input: Any
Output: same as input
qualia2.nn.modules.linear module¶
-
class
qualia2.nn.modules.linear.Bilinear(in_features1, in_features2, out_features, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a bilinear transformation to the incoming data
- Model:
y = x1*w*x2 + b
- Args:
in_features1 (int): size of each input sample in_features2 (int): size of each second input sample out_features (int): size of each output sample bias (bool): whether to use bias. Default: True
- Shape:
-
class
qualia2.nn.modules.linear.CLinear(in_features, out_features, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a complex linear transformation to the incoming data
- Model:
y = x*w.T + b
- Args:
in_features (int): size of each input sample out_features (int): size of each output sample bias (bool): whether to use bias. Default: True
- Shape:
-
class
qualia2.nn.modules.linear.Linear(in_features, out_features, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a linear transformation to the incoming data
- Model:
y = x*w.T + b
- Args:
in_features (int): size of each input sample out_features (int): size of each output sample bias (bool): whether to use bias. Default: True
- Shape:
-
class
qualia2.nn.modules.linear.NoisyLinear(in_features, out_features, std_init=0.4, factorised_noise=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a linear transformation with parametric noise added to its weights
- Model:
y = (w+sig_w*eps_w)*x+(b+sig_b*eps_b)
- Args:
in_features (int): size of each input sample out_features (int): size of each output sample std_init (float): std for initializing weights factorised_noise (bool):
- Shape:
- Reference:
qualia2.nn.modules.module module¶
-
class
qualia2.nn.modules.module.Module[source]¶ Bases:
objectBase class for all neural network modules in qualia.
Module can incoporate Modules, allowing to nest them in a tree structure. Note that a user-defined model must have super().__init__() in the __init__ of the model.
- Examples::
>>> # define a module >>> class Model(nn.Module): >>> def __init__(self): >>> super().__init__() >>> self.conv1 = nn.Conv2d(1, 10, kernel_size=5) >>> self.conv2 = nn.Conv2d(10, 20, kernel_size=5) >>> self.fc1 = nn.Linear(500, 50) >>> self.fc2 = nn.Linear(50, 10) >>> def forward(self, x): >>> x = F.relu(F.maxpool2d(self.conv1(x), (2,2))) >>> x = F.relu(F.maxpool2d(self.conv2(x), (2,2))) >>> x = F.reshape(x,(-1, 500)) >>> x = F.relu(self.fc1(x)) >>> x = self.fc2(x) >>> return x
-
load(filename, version=0)[source]¶ Loads parameters saved in HDF5 format to the Module.
- Args:
filename (str): specify the filename as well as the path to the file with the file extension. (ex) path/to/filename.qla version (int): version for the way of saving.
-
load_state_dict(state_dict, name='')[source]¶ Copies parameters from the state_dict into this module.
-
load_state_dict_from_url(url, version=1)[source]¶ Downloads and copies parameters from the state_dict at the url into this module.
-
save(filename, dtype='float16', protocol=-1, version=0)[source]¶ Saves internal parameters of the Module.
- Args:
filename (str): specify the filename as well as the saving path without the file extension. (ex) path/to/filename dtype (str): data type to save protocol (int): pickle protocol version (int): version for the way of saving. version 1 takes less disk space.
-
class
qualia2.nn.modules.module.Sequential(*args, **kwargs)[source]¶ Bases:
qualia2.nn.modules.module.ModuleA sequential container.n Modules will be added to it in the order they are passed in the constructor.
- Examples::
>>> # model can be defiened by adding Modules >>> model = Sequential( >>> nn.Conv2d(1,20,5), >>> nn.ReLU(), >>> nn.Conv2d(20,64,5), >>> nn.ReLU() >>> ) >>> # name for each layers can also be specified >>> model = Sequential( >>> conv1 = nn.Conv2d(1,20,5), >>> relu1 = nn.ReLU(), >>> conv2 = nn.Conv2d(20,64,5), >>> relu2 = nn.ReLU() >>> )
qualia2.nn.modules.normalize module¶
-
class
qualia2.nn.modules.normalize.BatchNorm1d(num_features, eps=1e-05, momentum=0.1, track_running_stats=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies Batch Normalization over a 2D or 3D input.
- Args:
num_features (int): C from an expected input of size [N,C] or [N,C,L] eps (float): a value added to the denominator for numerical stability. Default: 1e-5 momentum (float): the value used for the running_mean and running_std computation. Default:0.1 track_running_stats (bool): if True, this module tracks the running mean and std, else this module always uses batch statistics in both training and eval modes.
- Shape:
Input: [N,C] or [N,C,L]
Output: same as input
-
class
qualia2.nn.modules.normalize.BatchNorm2d(num_features, eps=1e-05, momentum=0.1, track_running_stats=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies Batch Normalization over a 4D input
- Args:
num_features (int): C from an expected input of size [N,C,H,W] eps (float): a value added to the denominator for numerical stability. Default: 1e-5 momentum (float): the value used for the running_mean and running_std computation. Default:0.1 track_running_stats (bool): if True, this module tracks the running mean and std, else this module always uses batch statistics in both training and eval modes.
- Shape:
Input: [N,C,H,W]
Output: same as input
-
class
qualia2.nn.modules.normalize.BatchNorm3d(num_features, eps=1e-05, momentum=0.1, track_running_stats=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies Batch Normalization over a 5D input
- Args:
num_features (int): C from an expected input of size [N,C,D,H,W] eps (float): a value added to the denominator for numerical stability. Default: 1e-5 momentum (float): the value used for the running_mean and running_std computation. Default:0.1 track_running_stats (bool): if True, this module tracks the running mean and std, else this module always uses batch statistics in both training and eval modes.
- Shape:
Input: [N,C,D,H,W]
Output: same as input
qualia2.nn.modules.pool module¶
-
class
qualia2.nn.modules.pool.AvgPool1d(kernel_size=2, stride=2, padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 1D average pooling over an input signal composed of several input planes.
- Args:
kernel_size (int): the size of the window to take a max over stride (int): the stride of the window. Default value is kernel_size padding (int): implicit zero padding to be added on all three sides dilation (int): a parameter that controls the stride of elements in the window
- Shape:
Input: [N,C,W]
Output: [N,C,W_out]
W_out = (W+2*padding-dilation*(kernel_size-1)-1)/stride + 1
-
class
qualia2.nn.modules.pool.AvgPool2d(kernel_size=(2, 2), stride=(2, 2), padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D average pooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window
- Shape:
Input: [N,C,H,W]
Output: [N,C,H_out,W_out]
H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1
-
class
qualia2.nn.modules.pool.AvgPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D average pooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window
- Shape:
Input: [N,C,H,W,D]
Output: [N,C,H_out,W_out,D_out]
H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1 D_out = (D+2*padding[2]-dilation[2]*(kernel_size[2]-1)-1)/stride[2] + 1
-
class
qualia2.nn.modules.pool.GlobalAvgPool1d[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 1D globl average pooling over an input signal composed of several input planes.
- Shape:
Input: [N,C,W]
Output: [N,C,1]
-
class
qualia2.nn.modules.pool.GlobalAvgPool2d[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D globl average pooling over an input signal composed of several input planes.
- Shape:
Input: [N,C,H,W]
Output: [N,C,1,1]
-
class
qualia2.nn.modules.pool.GlobalAvgPool3d[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D globl average pooling over an input signal composed of several input planes.
- Shape:
Input: [N,C,H,W,D]
Output: [N,C,1,1,1]
-
class
qualia2.nn.modules.pool.MaxPool1d(kernel_size=2, stride=2, padding=0, dilation=1, return_indices=False)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 1D max pooling over an input signal composed of several input planes.
- Args:
kernel_size (int): the size of the window to take a max over stride (int): the stride of the window. Default value is kernel_size padding (int): implicit zero padding to be added on all three sides dilation (int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.
- Shape:
Input: [N,C,W]
Output: [N,C,W_out]
W_out = (W+2*padding-dilation*(kernel_size-1)-1)/stride + 1
-
class
qualia2.nn.modules.pool.MaxPool2d(kernel_size=(2, 2), stride=(2, 2), padding=0, dilation=1, return_indices=False)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D max pooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.
- Shape:
Input: [N,C,H,W]
Output: [N,C,H_out,W_out]
H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1
-
class
qualia2.nn.modules.pool.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=0, dilation=1, return_indices=False)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D max pooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.
- Shape:
Input: [N,C,H,W,D]
Output: [N,C,H_out,W_out,D_out]
H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1 D_out = (D+2*padding[2]-dilation[2]*(kernel_size[2]-1)-1)/stride[2] + 1
-
class
qualia2.nn.modules.pool.MaxUnpool1d(kernel_size=2, stride=2, padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 1D max unpooling over an input signal composed of several input planes.
- Args:
kernel_size (int): the size of the window to take a max over stride (int): the stride of the window. Default value is kernel_size padding (int): implicit zero padding to be added on all three sides dilation (int): a parameter that controls the stride of elements in the window
- Shape:
Input: [N,C,W]
Output: [N,C,W_out]
W_out = (W-1)*stride+dilation*(kernel_size-1)+1-2*padding
-
class
qualia2.nn.modules.pool.MaxUnpool2d(kernel_size=(2, 2), stride=(2, 2), padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 2D max unpooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window
- Shape:
Input: [N,C,H,W]
Output: [N,C,H_out,W_out]
H_out = (H-1)*stride[0]+dilation[0]*(kernel_size[0]-1)+1-2*padding[0] W_out = (W-1)*stride[1]+dilation[1]*(kernel_size[1]-1)+1-2*padding[1]
-
class
qualia2.nn.modules.pool.MaxUnpool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=0, dilation=1)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a 3D max unpooling over an input signal composed of several input planes.
- Args:
kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window
- Shape:
Input: Input: [N,C,H,W,D]
Output: [N,C,H_out,W_out,D_out]
H_out = (H-1)*stride[0]+dilation[0]*(kernel_size[0]-1)+1-2*padding[0] W_out = (W-1)*stride[1]+dilation[1]*(kernel_size[1]-1)+1-2*padding[1] D_out = (D-1)*stride[2]+dilation[2]*(kernel_size[2]-1)+1-2*padding[2]
qualia2.nn.modules.recurrent module¶
-
class
qualia2.nn.modules.recurrent.GRU(input_size, hidden_size, num_layers, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a multi-layer gated recurrent unit (GRU) RNN to an input sequence. Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state num_layers (int): Number of recurrent layers. bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [seq_len, N, input_size]
Hidden: [num_layers, N, hidden_size]
Output: [seq_len, N, hidden_size]
Hidden: [num_layers, N, hidden_size]
-
class
qualia2.nn.modules.recurrent.GRUCell(input_size, hidden_size, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleA gated recurrent unit
- Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [N, input_size]
Hidden: [N, hidden_size]
Output: [N, hidden_size]
-
class
qualia2.nn.modules.recurrent.LSTM(input_size, hidden_size, num_layers, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleLong Short Term Memoty
- Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state num_layers (int): Number of recurrent layers. bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [seq_len, N, input_size]
Hidden_h: [num_layers, N, hidden_size]
Hidden_c: [num_layers, N, hidden_size]
Output: [seq_len, N, hidden_size]
Hidden_h: [num_layers, N, hidden_size]
Hidden_c: [num_layers, N, hidden_size]
-
class
qualia2.nn.modules.recurrent.LSTMCell(input_size, hidden_size, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleA Long Short Term Memoty cell
- Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [N, input_size]
Hidden_h: [N, hidden_size]
Hidden_c: [N, hidden_size]
Output_h: [N, hidden_size]
Output_c: [N, hidden_size]
-
class
qualia2.nn.modules.recurrent.RNN(input_size, hidden_size, num_layers, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleApplies a multi-layer Elman RNN with tanh Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state num_layers (int): Number of recurrent layers. bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [seq_len, N, input_size]
Hidden: [num_layers, N, hidden_size]
Output: [seq_len, N, hidden_size]
Hidden: [num_layers, N, hidden_size]
-
class
qualia2.nn.modules.recurrent.RNNCell(input_size, hidden_size, bias=True)[source]¶ Bases:
qualia2.nn.modules.module.ModuleAn Elman RNN cell with tanh
- Args:
input_size (int): The number of expected features in the input hidden_size (int): The number of features in the hidden state bias (bool):adds a learnable bias to the output. Default: True
- Shape:
Input: [N, input_size]
Hidden: [N, hidden_size]
Output: [N, hidden_size]
qualia2.nn.modules.sparse module¶
-
class
qualia2.nn.modules.sparse.Embedding(num_embeddings, embedding_dim)[source]¶ Bases:
qualia2.nn.modules.module.ModuleA simple lookup table that stores embeddings of a fixed dictionary and size. Args:
num_embeddings (int): size of the dictionary of embeddings embedding_dim (int): the size of each embedding vector