兼容METR-LA

This commit is contained in:
czzhangheng 2025-11-20 10:48:05 +08:00
parent 8b7e13df30
commit 76acc89499
5 changed files with 87 additions and 6 deletions

8
.vscode/launch.json vendored
View File

@ -36,6 +36,14 @@
"console": "integratedTerminal", "console": "integratedTerminal",
"args": "--config ./config/REPST/PEMS-BAY.yaml" "args": "--config ./config/REPST/PEMS-BAY.yaml"
}, },
{
"name": "REPST-METR",
"type": "debugpy",
"request": "launch",
"program": "run.py",
"console": "integratedTerminal",
"args": "--config ./config/REPST/METR-LA.yaml"
},
{ {
"name": "AEPSA-PEMSBAY", "name": "AEPSA-PEMSBAY",
"type": "debugpy", "type": "debugpy",

60
config/REPST/METR-LA.yaml Executable file
View File

@ -0,0 +1,60 @@
basic:
dataset: "METR-LA"
mode : "train"
device : "cuda:1"
model: "REPST"
seed: 2023
data:
add_day_in_week: true
add_time_in_day: true
column_wise: false
days_per_week: 7
default_graph: true
horizon: 12
lag: 12
normalizer: std
num_nodes: 207
steps_per_day: 288
test_ratio: 0.2
tod: false
val_ratio: 0.2
sample: 1
input_dim: 1
batch_size: 16
model:
pred_len: 12
seq_len: 12
patch_len: 6
stride: 7
dropout: 0.2
gpt_layers: 9
d_ff: 128
gpt_path: ./GPT-2
d_model: 64
n_heads: 1
input_dim: 1
word_num: 1000
train:
batch_size: 16
early_stop: true
early_stop_patience: 15
epochs: 100
grad_norm: false
loss_func: mae
lr_decay: true
lr_decay_rate: 0.3
lr_decay_step: "5,20,40,70"
lr_init: 0.003
max_grad_norm: 5
real_value: true
weight_decay: 0
debug: false
output_dim: 1
log_step: 1000
plot: false
mae_thresh: None
mape_thresh: 0.001

View File

@ -11,11 +11,13 @@ def load_st_dataset(config):
data_path = os.path.join("./data/PEMS-BAY/pems-bay.h5") data_path = os.path.join("./data/PEMS-BAY/pems-bay.h5")
with h5py.File(data_path, 'r') as f: with h5py.File(data_path, 'r') as f:
data = f['speed']['block0_values'][:] data = f['speed']['block0_values'][:]
case "METR-LA":
data_path = os.path.join("./data/METR-LA/METR-LA.h5")
with h5py.File(data_path, 'r') as f:
data = f['df']['block0_values'][:]
case "PEMSD3": case "PEMSD3":
data_path = os.path.join("./data/PEMS03/PEMS03.npz") data_path = os.path.join("./data/PEMS03/PEMS03.npz")
data = np.load(data_path)["data"][ data = np.load(data_path)["data"][:, :, 0]
:, :, 0
]
case "PEMSD4": case "PEMSD4":
data_path = os.path.join("./data/PEMS04/PEMS04.npz") data_path = os.path.join("./data/PEMS04/PEMS04.npz")
data = np.load(data_path)["data"][ data = np.load(data_path)["data"][

2
run.py
View File

@ -14,6 +14,8 @@ def main():
args = parse_args() args = parse_args()
args = init.init_device(args) args = init.init_device(args)
init.init_seed(args["basic"]["seed"]) init.init_seed(args["basic"]["seed"])
model = init.init_model(args) model = init.init_model(args)
# Load dataset # Load dataset

View File

@ -47,6 +47,9 @@ def check_and_download_data():
"adj_mx_bay.pkl", "adj_mx_bay.pkl",
"pems-bay-meta.h5", "pems-bay-meta.h5",
"pems-bay.h5" "pems-bay.h5"
],
"METR-LA": [
"METR-LA.h5"
] ]
} }
@ -92,6 +95,7 @@ def check_and_download_data():
if missing_main_files: if missing_main_files:
download_kaggle_data(current_dir, 'elmahy/pems-dataset') download_kaggle_data(current_dir, 'elmahy/pems-dataset')
download_kaggle_data(current_dir, 'scchuy/pemsbay') download_kaggle_data(current_dir, 'scchuy/pemsbay')
download_kaggle_data(current_dir, "annnnguyen/metr-la-dataset")
rearrange_dir() rearrange_dir()
@ -183,7 +187,6 @@ def rearrange_dir():
shutil.copy2(source_path, destination_path) shutil.copy2(source_path, destination_path)
shutil.rmtree(nested_data_dir) shutil.rmtree(nested_data_dir)
# print(f"已合并 {nested_data_dir} 到 {data_dir},并删除嵌套目录。")
# 将带有 "bay" 的文件移动到 PEMS-BAY 文件夹 # 将带有 "bay" 的文件移动到 PEMS-BAY 文件夹
pems_bay_dir = os.path.join(data_dir, "PEMS-BAY") pems_bay_dir = os.path.join(data_dir, "PEMS-BAY")
@ -195,10 +198,16 @@ def rearrange_dir():
destination_path = os.path.join(pems_bay_dir, item) destination_path = os.path.join(pems_bay_dir, item)
shutil.move(source_path, destination_path) shutil.move(source_path, destination_path)
# print(f"已将带有 'bay' 的文件移动到 {pems_bay_dir}。") # metr-la
metrla_dir = os.path.join(data_dir, "METR-LA")
os.makedirs(metrla_dir, exist_ok=True)
for item in os.listdir(data_dir):
if "metr" in item.lower() and (item.endswith(".pkl") or item.endswith(".h5")):
source_path = os.path.join(data_dir, item)
destination_path = os.path.join(metrla_dir, item)
shutil.move(source_path, destination_path)
# 主程序 # 主程序
if __name__ == "__main__": if __name__ == "__main__":
check_and_download_data() check_and_download_data()
# rearrange_dir()