SleepEDFxDataset¶
- class torcheeg.datasets.SleepEDFxDataset(root_path: str = './sleep-edf-database-expanded-1.0.0', chunk_size: int = 3000, overlap: int = 0, num_channel: int = 2, version: str = 'cassette', remove_unclear_example: bool = True, online_transform: None | Callable = None, offline_transform: None | Callable = None, label_transform: None | Callable = None, before_trial: None | Callable = None, after_trial: None | Callable = None, after_session: None | Callable = None, after_subject: None | Callable = None, io_path: None | str = None, io_size: int = 1048576, io_mode: str = 'lmdb', num_worker: int = 0, verbose: bool = True)[source][source]¶
A dataset for studying human sleep stages (expanded version), of which a small subset was previously contributed in 2002, is now available in PhysioNet. The database now includes 61 full-night polysomnograms of healthy subjects and of subjects with mild difficulty falling asleep, with accompanying expert annotations of sleep stages. 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:B Kemp.
Year: 2002
Download URL: https://www.physionet.org/content/sleep-edfx/1.0.0/
Reference: B Kemp, AH Zwinderman, B Tuk, HAC Kamphuisen, JJL Oberyé. Analysis of a sleep-dependent neuronal feedback loop: the slow-wave microcontinuity of the EEG. IEEE-BME 47(9):1185-1194 (2000)
Signals: 197 whole-night PolySomnoGraphic sleep recordings, containing EEG, EOG, chin EMG, and event markers. Corresponding hypnograms (sleep patterns) were manually scored by well-trained technicians according to the Rechtschaffen and Kales manual, and are also available.
Sleep stages: W, R, 1, 2, 3, 4, M (Movement time) and ? (not scored).
In order to use this dataset, the download folder
sleep-edf-database-expanded-1.0.0
is required, containing the following files and directories:sleep-cassette (dir)
sleep-telemetry (dir)
SC-subjects.xls (file)
ST-subjects.xls (file)
…
An example dataset for CNN-based methods:
from torcheeg.datasets import SleepEDFxDataset from torcheeg import transforms dataset = SleepEDFxDataset(root_path="./sleep-edf-database-expanded-1.0.0", num_channels=4, chunk_size=3000, remove_unclear_example=True, online_transform=transforms.ToTensor(), label_transform=transforms.Compose([ transforms.Select(key="stage"), transforms.Mapping(map_dict={ "W": 0, "1": 1, "2": 2, "3": 3, "4": 4, "R": 5 }) ])) print(dataset[0]) # EEG signal (torch.Tensor[2, 3000]), # label (int)
- Parameters:
root_path (str) – Downloaded data folder (unzipped sleep-edf-database-expanded-1.0.0.zip) (default:
'./sleep-edf-database-expanded-1.0.0'
)chunk_size (int) – Number of data points included in each EEG chunk as training or test samples. (default:
3000
)overlap (int) – Number of overlapping data points between different chunks when dividing EEG chunks. (default:
0
)num_channel (int) – Number of channels used, of which the first 4 channels are EEG signals. (default:
2
)version (str) – There are two studies corresponding to two different dataset called “cassette” and “Telemetry” in the downloaded data folder. Available options are [‘cassette’,’Telemetry’] (default:
"cattesse"
)remove_unclear_example (bool) – Whether to remove the examples which are labels as “?”. (default:
True
)online_transform (Callable, optional) – The transformation of the EEG signals and baseline EEG signals. The input is a
np.ndarray
, and the ouput is used as the first and second 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 third value of each element in the dataset. (default:
None
)before_trial (Callable, optional) – The hook performed on the trial to which the sample belongs. It is performed before the offline transformation and thus typically used to implement context-dependent sample transformations, such as moving averages, etc. The input of this hook function is a 2D EEG signal with shape (number of electrodes, number of data points), whose ideal output shape is also (number of electrodes, number of data points).
after_trial (Callable, optional) – The hook performed on the trial to which the sample belongs. It is performed after the offline transformation and thus typically used to implement context-dependent sample transformations, such as moving averages, etc. The input and output of this hook function should be a sequence of dictionaries representing a sequence of EEG samples. Each dictionary contains two key-value pairs, indexed by
eeg
(the EEG signal matrix) andkey
(the index in the database) respectively.io_path (str) – 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. LMDB may not perform well on limited operating systems, where a file system based EEG signal storage is also provided. 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
)