TSCeption¶
- class torcheeg.models.TSCeption(num_electrodes: int = 28, num_T: int = 15, num_S: int = 15, in_channels: int = 1, hid_channels: int = 32, num_classes: int = 2, sampling_rate: int = 128, dropout: float = 0.5)[source][source]¶
TSCeption. For more details, please refer to the following information.
Paper: Ding Y, Robinson N, Zhang S, et al. Tsception: Capturing temporal dynamics and spatial asymmetry from EEG for emotion recognition[J]. arXiv preprint arXiv:2104.02935, 2021.
Related Project: https://github.com/yi-ding-cs/TSception
Below is a recommended suite for use in emotion recognition tasks:
from torcheeg.datasets import DEAPDataset from torcheeg import transforms from torcheeg.datasets.constants import DEAP_CHANNEL_LIST from torcheeg.models import TSCeption from torch.utils.data import DataLoader dataset = DEAPDataset(root_path='./data_preprocessed_python', chunk_size=512, num_baseline=1, baseline_chunk_size=512, offline_transform=transforms.Compose([ transforms.PickElectrode(PickElectrode.to_index_list( ['FP1', 'AF3', 'F3', 'F7', 'FC5', 'FC1', 'C3', 'T7', 'CP5', 'CP1', 'P3', 'P7', 'PO3','O1', 'FP2', 'AF4', 'F4', 'F8', 'FC6', 'FC2', 'C4', 'T8', 'CP6', 'CP2', 'P4', 'P8', 'PO4', 'O2'], DEAP_CHANNEL_LIST)), transforms.To2d() ]), online_transform=transforms.ToTensor(), label_transform=transforms.Compose([ transforms.Select('valence'), transforms.Binary(5.0), ])) model = TSCeption(num_classes=2, num_electrodes=28, sampling_rate=128, num_T=15, num_S=15, hid_channels=32, dropout=0.5) x, y = next(iter(DataLoader(dataset, batch_size=64))) model(x)
- Parameters:
num_electrodes (int) – The number of electrodes. (default:
28
)num_T (int) – The number of multi-scale 1D temporal kernels in the dynamic temporal layer, i.e., \(T\) kernels in the paper. (default:
15
)num_S (int) – The number of multi-scale 1D spatial kernels in the asymmetric spatial layer. (default:
15
)in_channels (int) – The number of channels of the signal corresponding to each electrode. If the original signal is used as input, in_channels is set to 1; if the original signal is split into multiple sub-bands, in_channels is set to the number of bands. (default:
1
)hid_channels (int) – The number of hidden nodes in the first fully connected layer. (default:
32
)num_classes (int) – The number of classes to predict. (default:
2
)sampling_rate (int) – The sampling rate of the EEG signals, i.e., \(f_s\) in the paper. (default:
128
)dropout (float) – Probability of an element to be zeroed in the dropout layers. (default:
0.5
)
- forward(x: Tensor) Tensor [source][source]¶
- Parameters:
x (torch.Tensor) – EEG signal representation, the ideal input shape is
[n, 1, 28, 512]
. Here,n
corresponds to the batch size,1
corresponds to number of channels for convolution,28
corresponds tonum_electrodes
, and512
corresponds to the input dimension for each electrode.- Returns:
the predicted probability that the samples belong to the classes.
- Return type:
torch.Tensor[number of sample, number of classes]