Skip to content
 
 

Latest commit

 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Time-RCD

Towards Foundation Models for Zero-Shot Time Series Anomaly Detection: Leveraging Synthetic Data and Relative Context Discrepancy

arXiv Hugging Face 时空探索之旅

🔍 About | 🚀 Quick Start | 📊 Evaluation | 📁 Project Structure | 🔗 Citation

🔍 About

This repository contains the implementation of Time-RCD for time series anomaly detection, integrated with the TSB-AD (Time Series Benchmark for Anomaly Detection) datasets.

🌟Update (2026.04): With a new dataset and new checkpoints, Time-RCD achieves better results. The univariate setting improves VUS-PR by an absolute 6.7 points, and the multivariate setting improves VUS-PR by an absolute 4.5 points.

🌟 Live Demo on Hugging Face Spaces - Experience Time-RCD in action with our interactive demo!

🚀 Quick Start

Prerequisites

  • Python 3.10
  • conda (recommended for environment management)
  • Git

Installation

1. Create and Activate Conda Environment

conda create -n Time-RCD python=3.10
conda activate Time-RCD

2. Download the Repository

git clone https://github.com/thu-sail-lab/Time-RCD.git
cd Time-RCD

3. Download TSB-AD Datasets

Create the datasets directory and download the TSB-AD-U (univariate) and TSB-AD-M (multivariate) datasets:

mkdir -p "datasets" \
  && wget -O "datasets/TSB-AD-U.zip" "https://www.thedatum.org/datasets/TSB-AD-U.zip" \
  && wget -O "datasets/TSB-AD-M.zip" "https://www.thedatum.org/datasets/TSB-AD-M.zip" \
  && cd datasets \
  && unzip TSB-AD-U.zip && rm TSB-AD-U.zip \
  && unzip TSB-AD-M.zip && rm TSB-AD-M.zip \
  && cd ..

4. Install Python Dependencies

Option A: Fast Install (using uv)

pip install uv
uv pip install jaxtyping einops pandas numpy scikit-learn transformers torch torchvision statsmodels matplotlib seaborn -U "huggingface_hub[cli]"

Option B: Normal Install

pip install jaxtyping einops pandas numpy scikit-learn transformers torch torchvision statsmodels matplotlib seaborn -U "huggingface_hub[cli]"

5. Download Pre-trained Checkpoints

Download the pre-trained model checkpoints from Hugging Face:

huggingface-cli download thu-sail-lab/Time-RCD --include "best_model/pretrain_checkpoint_best_uni.pth" --local-dir .
huggingface-cli download thu-sail-lab/Time-RCD --include "best_model/pretrain_checkpoint_best_multi.pth" --local-dir .

For servers in China, use the mirror endpoint:

HF_ENDPOINT=https://hf-mirror.com \
hf download thu-sail-lab/Time-RCD --include "best_model/pretrain_checkpoint_best_uni.pth" --local-dir .
hf download thu-sail-lab/Time-RCD --include "best_model/pretrain_checkpoint_best_multi.pth" --local-dir 

🏋️ Training

Run pretraining with default single-dataset mode:

python training.py --mode single --gpus 0 --num-workers 0

Run multi-dataset pretraining:

python training.py --mode multi --gpus 0 --num-workers 0

Resume from latest checkpoint:

python training.py --mode single --gpus 0 --num-workers 0 --resume auto

📊 Evaluation

Single Variable Time Series

To run anomaly detection on univariate time series:

python main.py

Multi-Variable Time Series

To run anomaly detection on multivariate time series:

python main.py --mode multi

📁 Project Structure

.
├── checkpoints/          # Pre-trained model checkpoints
├── datasets/            # TSB-AD datasets (univariate and multivariate)
├── evaluation/          # Evaluation metrics and visualization tools
├── models/              # Model implementations
│   └── time_rcd/       # Time-RCD model components
├── utils/               # Utility functions
├── main.py              # Main entry point
├── model_wrapper.py     # Model wrapper for different algorithms
└── README.md            # This file

🔗 Citation

If you find this work useful, please cite our paper:

@misc{lan2025foundationmodelszeroshottime,
      title={Towards Foundation Models for Zero-Shot Time Series Anomaly Detection: Leveraging Synthetic Data and Relative Context Discrepancy}, 
      author={Tian Lan and Hao Duong Le and Jinbo Li and Wenjun He and Meng Wang and Chenghao Liu and Chen Zhang},
      year={2025},
      eprint={2509.21190},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2509.21190}, 
}

About

The implementation of Time-RCD for zero-shot time series anomaly detection

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages