RGNN¶
- class torcheeg.models.pyg.RGNN(adj: Tensor | list, num_electrodes: int = 62, in_channels: int = 5, num_layers: int = 2, hid_channels: int = 32, num_classes: int = 3, dropout: float = 0.7, learn_edge_weights: bool = True)[source][source]¶
Regularized Graph Neural Networks (RGNN). For more details, please refer to the following information.
Paper: Zhong P, Wang D, Miao C. EEG-based emotion recognition using regularized graph neural networks[J]. IEEE Transactions on Affective Computing, 2020.
Related Project: https://github.com/zhongpeixiang/RGNN
Below is a recommended suite for use in emotion recognition tasks:
from torcheeg.datasets import SEEDDataset from torcheeg.models import RGNN from torcheeg.transforms.pyg import ToG from torcheeg.datasets.constants import SEED_STANDARD_ADJACENCY_MATRIX from torch_geometric.data import DataLoader dataset = SEEDDataset(root_path='./Preprocessed_EEG', offline_transform=transforms.BandDifferentialEntropy(), online_transform=ToG(SEED_STANDARD_ADJACENCY_MATRIX), label_transform=transforms.Compose([ transforms.Select('emotion'), transforms.Lambda(lambda x: int(x) + 1), ]), num_worker=8) model = RGNN(adj=torch.Tensor(SEED_STANDARD_ADJACENCY_MATRIX), in_channels=5, num_electrodes=62, hid_channels=32, num_layers=2, num_classes=3, dropout=0.7, learn_edge_weights=True) x, y = next(iter(DataLoader(dataset, batch_size=64))) model(x)
- Parameters:
adj (torch.Tensor) – The adjacency matrix corresponding to the EEG representation, where 1.0 means the node is adjacent and 0.0 means the node is not adjacent. The matrix shape should be [num_electrodes, num_electrodes].
num_electrodes (int) – The number of electrodes. (default:
62
)in_channels (int) – The feature dimension of each electrode. (default:
5
)num_layers (int) – The number of graph convolutional layers. (default:
2
)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:
3
)dropout (float) – Probability of an element to be zeroed in the dropout layers at the output fully-connected layer. (default:
0.7
)learn_edge_weights (bool) – Whether to learn a set of parameters to adjust the adjacency matrix. (default:
True
)
- 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]