SleepEDFxDataset¶
- class torcheeg.datasets.SleepEDFxDataset(root_path: str = './sleep-edf-database-expanded-1.0.0/', studies: List = ['cassette', 'telemetry'], channels: List = ['EEG Fpz-Cz', 'EEG Pz-Oz'], l_freq: float = 0.5, h_freq: float = 30, sfreq: int = 100, online_transform: None | Callable = None, offline_transform: None | Callable = None, label_transform: None | Callable = None, io_path: None | str = None, io_size: int = 1048576, io_mode: str = 'lmdb', num_worker: int = 0, verbose: bool = True, **kwargs)[source][source]¶
Sleep-EDF Database Expanded (sleep-edfx), is a widely-used sleep stage detection dataset. This class generates training samples and test samples according to the given parameters, and caches the generated results in a unified input and output format (IO). The relevant information of the dataset is as follows:
Author: Kemp et al.
Year: 2000
Download URL: https://www.physionet.org/content/sleep-edfx/1.0.0/
Reference: Kemp B, Zwinderman A H, Tuk B, et al. Analysis of a sleep-dependent neuronal feedback loop: the slow-wave microcontinuity of the EEG[J]. IEEE Transactions on Biomedical Engineering, 2000, 47(9): 1185-1194.
Signals: 197 whole-night PolySomnoGraphic sleep recordings, containing EEG, EOG, chin EMG, and event markers (‘EEG Fpz-Cz’, ‘EEG Pz-Oz’, ‘EMG submental’, ‘EOG horizontal’, ‘Marker’).
Rating: Sleep stages were annotated in 30 second contiguous intervals (Sleep stage W, Sleep stage N1, Sleep stage N2, Sleep stage N3, Sleep stage R, Lights off@@EEG F4-A1).
In order to use this dataset, the following file structure is required:
sleep-edf-database-expanded-1.0.0/ ├── sleep-telemetry/ │ ├── ST7222JA-Hypnogram.edf │ ├── ST7061J0-PSG.edf │ ├── ST7041JO-Hypnogram.edf │ └── ST7021J0-PSG.edf └── sleep-telemetry/ └── ...An example dataset:
dataset = SleepEDFxDataset(root_path='./sleep-edf-database-expanded-1.0.0/', sfreq=100, channels=['EEG Fpz-Cz', 'EEG Pz-Oz'], label_transform=transforms.Compose([ transforms.Select('label'), transforms.Mapping({'Sleep stage W': 0, 'Sleep stage N1': 1, 'Sleep stage N2': 2, 'Sleep stage N3': 3, 'Sleep stage R': 4, 'Lights off@@EEG F4-A1': 0}) ]), online_transform=transforms.ToTensor(), ) print(dataset[0]) # EEG signal (torch.Tensor[6, 3000]), # label (int)
- Parameters:
root_path (str) – Root path of the Sleep-EDF Database Expanded dataset. (default:
'./sleep-edf-database-expanded-1.0.0/')studies (list) – List of study types to include, can be ‘cassette’ and/or ‘telemetry’. (default:
['cassette', 'telemetry'])channels (list) – List of EEG channels to use. (default:
['EEG Fpz-Cz', 'EEG Pz-Oz'])l_freq (float) – Low cut-off frequency in Hz. (default:
0.5)h_freq (float) – High cut-off frequency in Hz. (default:
30)sfreq (int) – The sampling frequency to resample the signal to in Hz. (default:
100)online_transform (Callable, optional) – The transformation of the EEG signals. The input is a
np.ndarray, and the ouput is used as the first value of each element in the dataset. (default:None)offline_transform (Callable, optional) – The usage is the same as
online_transform, but executed before generating IO intermediate results. (default:None)label_transform (Callable, optional) – The transformation of the label. The input is an information dictionary, and the ouput is used as the second value of each element in the dataset. (default:
None)io_path (str, optional) – The path to generated unified data IO, cached as an intermediate result. If set to None, a random path will be generated. (default:
None)io_size (int) – Maximum size database may grow to; used to size the memory mapping. If database grows larger than
map_size, an exception will be raised and the user must close and reopen. (default:1048576)io_mode (str) – Storage mode of EEG signal. When io_mode is set to
lmdb, TorchEEG provides an efficient database (LMDB) for storing EEG signals. When io_mode is set topickle, pickle-based persistence files are used. When io_mode is set tomemory, memory are used. (default:lmdb)num_worker (int) – Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process. (default:
0)verbose (bool) – Whether to display logs during processing, such as progress bars, etc. (default:
True)