Shortcuts

after_hook_normalize

class torcheeg.transforms.after_hook_normalize(data: List[ndarray | Tensor], eps: float = 1e-06)[source][source]

A common hook function used to normalize the signal of the whole trial/session/subject after dividing it into chunks and transforming the divided chunks.

It is used as follows:

from torcheeg.datasets import DEAPDataset
from torcheeg.transforms import after_hook_normalize

dataset = DEAPDataset(root_path='./data_preprocessed_python',
                      offline_transform=transforms.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      after_trial=after_hook_normalize,
                      num_worker=4,
                      label_transform=transforms.Compose([
                          transforms.Select('valence'),
                          transforms.Binary(5.0),
                      ]))

If you want to pass in parameters, use partial to generate a new function:

from functools import partial
from torcheeg.datasets import DEAPDataset
from torcheeg.transforms import after_hook_normalize

DEAPDataset(root_path='./data_preprocessed_python',
                      offline_transform=transforms.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      after_trial=partial(after_hook_normalize, eps=1e-5),
                      num_worker=4,
                      label_transform=transforms.Compose([
                          transforms.Select('valence'),
                          transforms.Binary(5.0),
                      ]))
Parameters:
  • data (list) – A list of np.ndarray or torch.Tensor, one of which corresponds to an EEG signal in trial.

  • eps (float) – The term added to the denominator to improve numerical stability (default: 1e-6)

Returns:

The normalized results of a trial. It is a list of np.ndarray or torch.Tensor, one of which corresponds to an EEG signal in trial.

Return type:

list

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources