Shortcuts

BCUNet

class torcheeg.models.BCUNet(in_channels=4, hid_channels=64, grid_size=(9, 9), beta_timesteps=256, num_classes=2)[source][source]

The diffusion model consists of two processes, the forward process, and the backward process. The forward process is to gradually add Gaussian noise to an image until it becomes random noise, while the backward process is the de-noising process. We train an attention-based UNet network at the backward process to start with random noise and gradually de-noise it until an image is generated and use the UNet to generate a simulated image from random noises. In particular, in conditional UNet, additional label information is provided to guide the noise reduction results during the noise reduction process.

It is worth noting that this model is not designed for EEG analysis, but shows good performance and can serve as a good research start.

Below is a recommended suite for use in EEG generation:

import torch

from torcheeg.models.ddpm import BCUNet

noise = torch.randn(1, 4, 9, 9)
t = torch.randint(low=1, high=1000, size=(1, ))
y = torch.randint(low=0, high=2, size=(1, ))
unet = BCUNet(num_classes=2)
fake_X = unet(noise, t, y)
Parameters:
  • in_channels (int) – The feature dimension of each electrode. (default: 4)

  • hid_channels (int) – The basic hidden channels in the network blocks. (default: 64)

  • grid_size (tuple) – Spatial dimensions of grid-like EEG representation. (default: (9, 9))

  • beta_timesteps (int) – The variance schedule controlling step sizes. (default: 256)

  • num_classes (int) – The number of classes to predict. (default: 2)

forward(x: Tensor, t: Tensor, y: Tensor)[source][source]
Parameters:
  • x (torch.Tensor) – The random noise to be denoised, which should have the same shape as the simulated EEG expected to be generated, i.e., [n, 4, 9, 9]. Here, n corresponds to the batch size, 4 corresponds to in_channels, and (9, 9) corresponds to grid_size.

  • t (torch.Tensor) – The randomly sampled time steps (int) for denoising a batch of samples. The shape should be [n,]. Here, n corresponds to the batch size.

  • y (torch.Tensor) – Category labels (int) for a batch of samples The shape should be [n,]. Here, n corresponds to the batch size.

Returns:

the denoised results, which should have the same shape as the input noise, i.e., [n, 4, 9, 9]. Here, n corresponds to the batch size, 4 corresponds to in_channels, and (9, 9) corresponds to grid_size.

Return type:

torch.Tensor[n, 4, 9, 9]

Read the Docs v: latest
Versions
latest
stable
v1.1.1
v1.1.0
v1.0.11
v1.0.10
v1.0.9
v1.0.8.post1
v1.0.8
v1.0.7
v1.0.6
v1.0.4
v1.0.3
v1.0.2
v1.0.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

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