Corefunctions

Corefunctionality for data preparation of sequential data for pytorch, fastai models

3. Transformations

3.1 Sequence Slicing Transformation


source

SeqSlice

 SeqSlice (l_slc=None, r_slc=None)

Take a slice from an array-like object. Useful for e.g. shifting input and output

l_shift = SeqSlice(r_slc=-1)
arr = np.ones((5))
test_eq(l_shift(arr),arr[:-1])

3.2 Sequence Noise Injection Transformation


source

SeqNoiseInjection

 SeqNoiseInjection (std=0.1, mean=0.0, p=1.0)

A transform that before_call its state at each __call__

x = TensorSequencesInput(tensor([[1,1,1],[-1,-1,-1.0]]))
ns_mean = tensor([0.,10.1,3.1])
ns_std = tensor([1.,1.1,0.1])
x,x.shape
(TensorSequencesInput([[ 1.,  1.,  1.],
                       [-1., -1., -1.]]),
 torch.Size([2, 3]))
seq_noise = SeqNoiseInjection(std=ns_std,mean=ns_mean)
seq_noise(x)
TensorSequencesInput([[ 1.,  1.,  1.],
                      [-1., -1., -1.]])
seq_noise = SeqNoiseInjection(std=ns_std*10)
seq_noise(x)
TensorSequencesInput([[ 1.,  1.,  1.],
                      [-1., -1., -1.]])

source

SeqNoiseInjection_Varying

 SeqNoiseInjection_Varying (std_std=0.1, p=1.0)

A transform that before_call its state at each __call__

x = TensorSequencesInput(tensor([[0,0,0],[0,0,0]]))
ns_std = tensor([1.,1.1,0.1])
x,x.shape
(TensorSequencesInput([[0, 0, 0],
                       [0, 0, 0]]),
 torch.Size([2, 3]))
seq_noise = SeqNoiseInjection_Varying(std_std=ns_std)
seq_noise(x)
TensorSequencesInput([[0, 0, 0],
                      [0, 0, 0]])

source

SeqNoiseInjection_Grouped

 SeqNoiseInjection_Grouped (std_std, std_idx, p=1.0)

A transform that before_call its state at each __call__

x = TensorSequencesInput(tensor([[0,0,0],[0,0,0]]))
ns_std = tensor([1.,1.1,0.1])
x,x.shape
(TensorSequencesInput([[0, 0, 0],
                       [0, 0, 0]]),
 torch.Size([2, 3]))
seq_noise = SeqNoiseInjection_Grouped(std_std=[3.,0],std_idx=[0,0,1])
seq_noise(x)
TensorSequencesInput([[0, 0, 0],
                      [0, 0, 0]])

3.2 Sequence Bias Injection Transformation


source

SeqBiasInjection

 SeqBiasInjection (std=0.1, mean=0.0, p=1.0)

A transform that before_call its state at each __call__

x = TensorSequencesInput(tensor([[[1,1,1],[-1,-1,-1.0]]]))
ns_mean = tensor([0.,10.1,3.1])
ns_std = tensor([1.,1.1,0.1])
seq_bias = SeqBiasInjection(std=ns_std,mean=ns_std)
seq_bias(x)[...,0]
TensorSequencesInput([[ 1., -1.]])
seq_bias.mean
tensor([1.0000, 1.1000, 0.1000])
seq_bias = SeqBiasInjection(std=ns_std*10)
seq_bias(x)
TensorSequencesInput([[[ 1.,  1.,  1.],
                       [-1., -1., -1.]]])

3.3 Normalization

Normalize is programmed for TensorImage as an input tensor. It gets. At init the variable axes need to be chosen correspondingly to the shape of your tensor.


source

decodes

 decodes (x:tsfast.data.core.TensorSequencesInput)

source

encodes

 encodes (x:tsfast.data.core.TensorSequencesInput)
norm = Normalize.from_stats(mean=ns_mean,std=ns_std,dim=1,ndim=2,cuda=False)
x,norm(x)
(TensorSequencesInput([[[ 1.,  1.,  1.],
                        [-1., -1., -1.]]]),
 TensorSequencesInput([[[  1.0000,  -8.2727, -21.0000],
                        [ -1.0000, -10.0909, -41.0000]]]))