GIN¶
- class torcheeg.models.pyg.GIN(in_channels: int = 4, hid_channels: int = 64, num_classes: int = 3)[source][source]¶
A simple but effective graph isomorphism network (GIN) structure from the book of Zhang et al. For more details, please refer to the following information.
Book: Zhang X, Yao L. Deep Learning for EEG-Based Brain-Computer Interfaces: Representations, Algorithms and Applications[M]. 2021.
URL: https://www.worldscientific.com/worldscibooks/10.1142/q0282#t=aboutBook
Related Project: https://github.com/xiangzhang1015/Deep-Learning-for-BCI/blob/master/pythonscripts/4-3_GIN.py
Below is a recommended suite for use in emotion recognition tasks:
from torcheeg.datasets import DEAPDataset from torcheeg import transforms from torcheeg.transforms.pyg import ToG from torcheeg.datasets.constants import SEED_STANDARD_ADJACENCY_MATRIX from torcheeg.models import GIN from torch_geometric.data import DataLoader dataset = DEAPDataset(root_path='./data_preprocessed_python', offline_transform=transforms.BandDifferentialEntropy(), online_transform=ToG(SEED_STANDARD_ADJACENCY_MATRIX), label_transform=transforms.Compose([ transforms.Select('valence'), transforms.Binary(5.0), ])) model = GIN(in_channels=4, hid_channels=64, num_classes=2) x, y = next(iter(DataLoader(dataset, batch_size=64))) model(x)
- Parameters:
in_channels (int) – The feature dimension of each electrode. (default:
4
)hid_channels (int) – The number of hidden nodes in the GRU layers and the fully connected layer. (default:
64
)num_classes (int) – The number of classes to predict. (default:
2
)
- forward(data: Batch) Tensor [source][source]¶
- Parameters:
data (torch_geometric.data.Batch) – EEG signal representation, the ideal input shape of data.x is
[n, 62, 4]
. Here,n
corresponds to the batch size,62
corresponds to the number of electrodes, and4
corresponds toin_channels
.- Returns:
the predicted probability that the samples belong to the classes.
- Return type:
torch.Tensor[number of sample, number of classes]