• Stars
    star
    319
  • Rank 128,354 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[IJCAI-21] "Time-Series Representation Learning via Temporal and Contextual Contrasting"

Time-Series Representation Learning via Temporal and Contextual Contrasting (TS-TCC) [Paper] [Cite]

by: Emadeldeen Eldele, Mohamed Ragab, Zhenghua Chen, Min Wu, Chee Keong Kwoh, Xiaoli Li and Cuntai Guan

This work is accepted for publication in the International Joint Conferences on Artificial Intelligence (IJCAI-21) (Acceptance Rate: 13.9%).

💥💥 Update: We extended our method to the semi-supervised settings (CA-TCC). Please refer to the manuscript Self-supervised Contrastive Representation Learning for Semi-supervised Time-Series Classification for more details. The code is also publicly available. 💥💥

Abstract

Learning decent representations from unlabeled time-series data with temporal dynamics is a very challenging task. In this paper, we propose an unsupervised Time-Series representation learning framework via Temporal and Contextual Contrasting (TS-TCC), to learn time-series representation from unlabeled data. First, the raw time-series data are transformed into two different yet correlated views by using weak and strong augmentations. Second, we propose a novel temporal contrasting module to learn robust temporal representations by designing a tough cross-view prediction task. Last, to further learn discriminative representations, we propose a contextual contrasting module built upon the contexts from the temporal contrasting module. It attempts to maximize the similarity among different contexts of the same sample while minimizing similarity among contexts of different samples. Experiments have been carried out on three real-world time-series datasets. The results manifest that training a linear classifier on top of the features learned by our proposed TS-TCC performs comparably with the supervised training. Additionally, our proposed TS-TCC shows high efficiency in few-labeled data and transfer learning scenarios.

Requirmenets:

  • Python3.x
  • Pytorch==1.7
  • Numpy
  • Sklearn
  • Pandas
  • openpyxl (for classification reports)
  • mne=='0.20.7' (For Sleep-EDF preprocessing)
  • mat4py (for Fault diagnosis preprocessing)

Datasets

Download datasets

Update: You can now find the preprocessed datasets on this Dataverse

We used four public datasets in this study:

Preparing datasets

The data should be in a separate folder called "data" inside the project folder. Inside that folder, you should have a separate folders; one for each dataset. Each subfolder should have "train.pt", "val.pt" and "test.pt" files. The structure of data files should in dictionary form as follows: train.pt = {"samples": data, "labels: labels}, and similarly val.pt, and test.pt

The details of preprocessing is as follows:

1- Sleep-EDF dataset:

Create a folder named data_files in the path data_preprocessing/sleep-edf/. Download the dataset files and place them in this folder.

Run the script preprocess_sleep_edf.py to generate the numpy files ... you will find the numpy files of each PSG file in another folder named sleepEDF20_fpzcz (you can change these names from args). You will also find the data of each subject in the folder sleepEDF20_fpzcz_subjects (since each subject has two-night data)

Finally run the file generate_train_val_test.py to generate the files and it will automatically place them in the data/sleepEDF folder.

2- UCI HAR dataset

When you dowload the dataset and extract the zip file, you will find the data in a folder named UCI HAR Dataset ... place it in data_preprocessing/uci_har/ folder and run preprocess_har.py file.

3- Epilepsy and Fault diagnosis datasets:

download the data file in data_files folder and run the preprocessing scripts.

Configurations

The configuration files in the config_files folder should have the same name as the dataset folder name. For example, for HAR dataset, the data folder name is HAR and the configuration file is HAR_Configs.py. From these files, you can update the training parameters.

Training TS-TCC

You can select one of several training modes:

  • Random Initialization (random_init)
  • Supervised training (supervised)
  • Self-supervised training (self_supervised)
  • Fine-tuning the self-supervised model (fine_tune)
  • Training a linear classifier (train_linear)

The code allows also setting a name for the experiment, and a name of separate runs in each experiment. It also allows the choice of a random seed value.

To use these options:

python main.py --experiment_description exp1 --run_description run_1 --seed 123 --training_mode random_init --selected_dataset HAR

Note that the name of the dataset should be the same name as inside the "data" folder, and the training modes should be the same as the ones above.

To train the model for the fine_tune and train_linear modes, you have to run self_supervised first.

Results

  • The experiments are saved in "experiments_logs" directory by default (you can change that from args too).
  • Each experiment will have a log file and a final classification report in case of modes other that "self-supervised".

Citation

If you found this work useful for you, please consider citing it.

@inproceedings{ijcai2021-324,
  title     = {Time-Series Representation Learning via Temporal and Contextual Contrasting},
  author    = {Eldele, Emadeldeen and Ragab, Mohamed and Chen, Zhenghua and Wu, Min and Kwoh, Chee Keong and Li, Xiaoli and Guan, Cuntai},
  booktitle = {Proceedings of the Thirtieth International Joint Conference on Artificial Intelligence, {IJCAI-21}},
  pages     = {2352--2359},
  year      = {2021},
}
@article{emadeldeen2022catcc,
  title   = {Self-supervised Contrastive Representation Learning for Semi-supervised Time-Series Classification},
  author  = {Eldele, Emadeldeen and Ragab, Mohamed and Chen, Zhenghua and Wu, Min and Kwoh, Chee Keong and Li, Xiaoli and Guan, Cuntai},
  journal = {arXiv preprint arXiv:2208.06616},
  year    = {2022}
}

Contact

For any issues/questions regarding the paper or reproducing the results, please contact me.
Emadeldeen Eldele
School of Computer Science and Engineering (SCSE),
Nanyang Technological University (NTU), Singapore.
Email: emad0002{at}e.ntu.edu.sg

More Repositories

1

AttnSleep

[TNSRE 2021] "An Attention-based Deep Learning Approach for Sleep Stage Classification with Single-Channel EEG"
Python
163
star
2

AdaTime

[TKDD 2023] AdaTime: A Benchmarking Suite for Domain Adaptation on Time Series Data
Python
156
star
3

CA-TCC

[TPAMI 2023] Self-supervised Contrastive Representation Learning for Semi-supervised Time-Series Classification
Python
100
star
4

sleep-stage-classification-papers

This repo contains a list of papers for sleep stage classification using deep learning based techniques starting from 2017-afterwards. I classified them generally according to the proposed technique.
54
star
5

TSLANet

[ICML 2024] A novel, efficient approach combining convolutional operations with adaptive spectral analysis as a foundation model for different time series tasks
Python
42
star
6

face-anti-spoofing

Pretrained Keras model for face anti-spoofing or face liveness detection problem based on rPPG features
Python
38
star
7

ADAST

[IEEE TETCI] "ADAST: Attentive Cross-domain EEG-based Sleep Staging Framework with Iterative Self-Training"
Python
32
star
8

eval_ssl_ssc

[TNSRE 2023] Self-supervised Learning for Label-Efficient Sleep Stage Classification: A Comprehensive Evaluation
Python
31
star
9

sleep-stages-classification-papers

This repo contains a list of papers for sleep stage classification using deep learning based techniques starting from 2017-afterwards. I classified them generally according to the proposed technique.
25
star
10

CoTMix

[TAI 2023] Contrastive Domain Adaptation for Time-Series via Temporal Mixup
Python
20
star
11

ECGTransForm

[Biomedical Signal Processing and Control] ECGTransForm: Empowering adaptive ECG arrhythmia classification framework with bidirectional transformer
Python
13
star
12

semi-supervised_baselines

Self- and Semi-supervised learning baselines. Used in CA-TCC paper.
Python
2
star