BUNet¶
- class torcheeg.models.BUNet(in_channels=4, hid_channels=64, grid_size=(9, 9), beta_timesteps=256)[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.
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.
Paper: Ho J, Jain A, Abbeel P. Denoising diffusion probabilistic models[J]. Advances in Neural Information Processing Systems, 2020, 33: 6840-6851.
Related Project: https://github.com/dome272/Diffusion-Models-pytorch
Below is a recommended suite for use in EEG generation:
import torch from torcheeg.models import BUNet noise = torch.randn(1, 4, 9, 9) t = torch.randint(low=1, high=1000, size=(1, )) unet = BUNet() fake_X = unet(noise, t)
- 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
)
- forward(x: Tensor, t: 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 toin_channels
, and(9, 9)
corresponds togrid_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.
- 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 toin_channels
, and(9, 9)
corresponds togrid_size
.- Return type:
torch.Tensor[n, 4, 9, 9]