"OpenCity: Open Spatio-Temporal Foundation Models for Traffic Prediction"
A pytorch implementation for the paper: OpenCity: Open Spatio-Temporal Foundation Models for Traffic Prediction
Zhonghang Li, Long Xia, Lei Shi, Yong Xu, Dawei Yin, Chao Huang* (*Correspondence)
undefinedData Intelligence Lab@University of Hong Kong, South China University of Technology, Baidu Inc
This repository hosts the code, data, and model weights of OpenCity.
๐ฏ๐ฏ๐ข๐ข We upload the models and data used in our OpenCity on ๐ค Huggingface. We highly recommend referring to the table below for further details:
| ๐ค Huggingface Address | ๐ฏ Description |
|---|---|
| https://huggingface.co/hkuds/OpenCity-Plus | Itโs the model weights of our OpenCity-Plus. |
| https://huggingface.co/datasets/hkuds/OpenCity-dataset/tree/main | We released the datasets used in OpenCity. |
โฆ
In this work, we aim to unlock new possibilities for building versatile, resilient and adaptive spatio-temporal foundation models for traffic prediction. To achieve this goal, we introduce a novel foundation model, named OpenCity, that can effectively capture and normalize the underlying spatio-temporal patterns from diverse data characteristics, facilitating zero-shot generalization across diverse urban environments. OpenCity integrates the Transformer architecture with graph neural networks to model the complex spatio-temporal dependencies in traffic data. By pre-training OpenCity on large-scale, heterogeneous traffic datasets, we enable the model to learn rich, generalizable representations that can be seamlessly applied to a wide range of traffic forecasting scenarios. Experimental results demonstrate that OpenCity exhibits exceptional zero-shot predictive performance in various traffic prediction tasks.

undefinedOutstanding Zero-shot Prediction Performance. OpenCity achieves significant zero-shot learning breakthroughs, outperforming most baselines even without fine-tuning. This highlights the approachโs robustness and effectiveness at learning complex spatio-temporal patterns in large-scale traffic data, extracting universal insights applicable across downstream tasks.

https://github.com/user-attachments/assets/39265dc5-0126-483b-951e-518c6cb210e0
โโโ conf/
โ โโโ AGCRN/
โ โ โโโ AGCRN.conf
โ โโโ ASTGCN/
โ โ โโโ ASTGCN.conf
โ โโโ general_conf/
โ โ โโโ global_baselines.conf
โ โ โโโ pretrain.conf
โ โโโ GWN/
โ โ โโโ GWN.conf
โ โโโ MSDR/
โ โ โโโ MSDR.conf
โ โโโ MTGNN/
โ โ โโโ MTGNN.conf
โ โโโ OpenCity/
โ โ โโโ OpenCity.conf
โ โโโ PDFormer/
โ โ โโโ PDFormer.conf
โ โโโ STGCN/
โ โ โโโ STGCN.conf
โ โโโ STSGCN/
โ โ โโโ STSGCN.conf
โ โโโ STWA/
โ โ โโโ STWA.conf
โ โโโ TGCN/
โ โโโ TGCN.conf
โโโ data/
โ โโโ generate_ca_data.py
โ โโโ README.md
โโโ lib/
โ โโโ data_process.py
โ โโโ logger.py
โ โโโ metrics.py
โ โโโ Params_predictor.py
โ โโโ Params_pretrain.py
โ โโโ predifineGraph.py
โ โโโ TrainInits.py
โโโ model/
โ โโโ AGCRN/
โ โ โโโ AGCN.py
โ โ โโโ AGCRN.py
โ โ โโโ AGCRNCell.py
โ โ โโโ args.py
โ โโโ ASTGCN/
โ โ โโโ args.py
โ โ โโโ ASTGCN.py
โ โโโ GWN/
โ โ โโโ args.py
โ โ โโโ GWN.py
โ โโโ MSDR/
โ โ โโโ args.py
โ โ โโโ gmsdr_cell.py
โ โ โโโ gmsdr_model.py
โ โโโ MTGNN/
โ โ โโโ args.py
โ โ โโโ MTGNN.py
โ โโโ OpenCity/
โ โ โโโ args.py
โ โ โโโ OpenCity.py
โ โโโ PDFormer/
โ โ โโโ args.py
โ โ โโโ PDFormer.py
โ โโโ ST_WA/
โ โ โโโ args.py
โ โ โโโ attention.py
โ โ โโโ ST_WA.py
โ โโโ STGCN/
โ โ โโโ args.py
โ โ โโโ stgcn.py
โ โโโ STSGCN/
โ โ โโโ args.py
โ โ โโโ STSGCN.py
โ โโโ TGCN/
โ โโโ args.py
โ โโโ TGCN.py
โ โโโ Model.py
โ โโโ BasicTrainer.py
โ โโโ Run.py
โโโ model_weights/
โโโ OpenCity/
โโโ README.md
Please first clone the repo and install the required environment, which can be done by running the following commands:
conda create -n opencity python=3.9.13
conda activate opencity
# Torch (other versions are also ok)
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
# Clone our OpenCity or download it
git clone https://github.com/HKUDS/OpenCity.git
cd OpenCity-main
# Install required libraries
pip install -r requirements.txt
# OpenCity-plus
python Run.py -mode pretrain -model OpenCity -save_pretrain_path OpenCity-plus2.0.pth -batch_size 4 --embed_dim 512 --skip_dim 512 --enc_depth 6
# OpenCity-base
python Run.py -mode pretrain -model OpenCity -save_pretrain_path OpenCity-base2.0.pth -batch_size 8 --embed_dim 256 --skip_dim 256 --enc_depth 3
# OpenCity-mini
python Run.py -mode pretrain -model OpenCity -save_pretrain_path OpenCity-mini2.0.pth -batch_size 16 --embed_dim 128 --skip_dim 128 --enc_depth 3
undefinedPreparing Checkpoints of OpenCity. You can download our model using the following link: OpenCity-Plus, OpenCity-Base, OpenCity-Mini
undefinedRunning Evaluation of OpenCity. You can use our release model weights to evaluate, There is an example as below:
# Use OpenCity-plus to evaluate, please use only one dataset to test (e.g. dataset_use = ['PEMS07M'] in pretrain.config).
python Run.py -mode test -model OpenCity -load_pretrain_path OpenCity-plus.pth -batch_size 2 --embed_dim 512 --skip_dim 512 --enc_depth 6
# Run STGCN in ori mode
python Run.py -mode ori -model STGCN -batch_size 64 --real_value False
If you find OpenCity useful in your research or applications, please kindly cite:
@misc{li2024opencity,
title={OpenCity: Open Spatio-Temporal Foundation Models for Traffic Prediction},
author={Zhonghang Li and Long Xia and Lei Shi and Yong Xu and Dawei Yin and Chao Huang},
year={2024},
eprint={2408.10269},
archivePrefix={arXiv}
}