Datatype-independent Transforms

transforms.Compose

class torcheeg.transforms.Compose(transforms: List[Callable])[source]

Bases: object

Composes several transforms together. Consistent with torchvision.transforms.Compose’s behavior.

transform = Composes([
    ToTensor(),
    Resize(size=(64, 64)),
    RandomNoise(p=0.1),
    RandomMask(p=0.1)
])
transform(torch.randn(128, 9, 9)).shape
>>> (128, 64, 64)

:obj`Composes` supports transformers with different data dependencies. The above example combines multiple torch-based transformers, the following example shows a sequence of numpy-based transformer.

transform = Composes([
    BandDifferentialEntropy(),
    MeanStdNormalize(),
    ToGrid(DEAP_CHANNEL_LOCATION_DICT)
])
transform(np.random.randn(32, 128)).shape
>>> (128, 9, 9)
Parameters

transforms (list) – The list of transforms to compose.

__call__(eeg: any) any[source]
Parameters

x (any) – The input.

Returns

The transformed output.

Return type

any

transforms.Lambda

class torcheeg.transforms.Lambda(lambd: Callable)[source]

Bases: object

Apply a user-defined lambda as a transform.

transform = Lambda(lambda x: x + 1)
transform(1)
>>> 2
Parameters

lambd (Callable) – Lambda/function to be used for transform.

__call__(eeg: any) any[source]
Parameters

x (any) – The input.

Returns

The transformed output.

Return type

any