一、快速入门
0、安装Pytorch
LibCity的代码是基于Python 3.7版本和Pytorch 1.7.1版本。
1、安装LibCity
①从仓库中clone代码到本地
# 需要提前安装Git(https://git-scm.com/)
git clone https://github.com/LibCity/Bigscity-LibCity
# 进入LibCity根目录
cd Bigscity-LibCity
# 安装LibCity所有依赖
pip install -r requirements.txt
②在Bigscity-LibCity目录下创建raw_data目录,并放入数据集文件
以METR_LA数据集为例,下载后METR_LA
目录内有METR LA.rel、METRLA.geo、METRR_LA.dyna、config.json
四个文件。将METR_LA文件夹放入raw_data
目录内。METR LA.rel
等文件所在的目录结构为Bigscity-LibCity/raw_data/METR_LA/METR LA.rel
。
③查看帮助
(LibCity-env) PS D:\Workspace\Bigscity-LibCity> python .\run_model.py -h
usage: run_model.py [-h] [--task TASK] [--model MODEL] [--dataset DATASET]
[--config_file CONFIG_FILE] [--saved_model SAVED_MODEL]
[--train TRAIN] [--exp_id EXP_ID] [--seed SEED]
[--gpu GPU] [--gpu_id GPU_ID] [--train_rate TRAIN_RATE]
[--eval_rate EVAL_RATE] [--batch_size BATCH_SIZE]
[--learning_rate LEARNING_RATE] [--max_epoch MAX_EPOCH]
[--dataset_class DATASET_CLASS] [--executor EXECUTOR]
[--evaluator EVALUATOR]
optional arguments:
-h, --help show this help message and exit
--task TASK the name of task
--model MODEL the name of model
--dataset DATASET the name of dataset
--config_file CONFIG_FILE
the file name of config file
--saved_model SAVED_MODEL
whether save the trained model
--train TRAIN whether re-train model if the model is trained before
--exp_id EXP_ID id of experiment
--seed SEED random seed
--gpu GPU whether use gpu
--gpu_id GPU_ID the gpu id to use
--train_rate TRAIN_RATE
the train set rate
--eval_rate EVAL_RATE
the validation set rate
--batch_size BATCH_SIZE
the batch size
--learning_rate LEARNING_RATE
learning rate
--max_epoch MAX_EPOCH
the maximum epoch
--dataset_class DATASET_CLASS
the dataset class name
--executor EXECUTOR the executor class name
--evaluator EVALUATOR
the evaluator class name
若出现protobuf相关错误,可以使用以下命令升级/降级protobuf
pip install protobuf==3.19.6
3、运行基线模型
# python run_model.py --task [task_name] --model [model_name] --dataset [dataset_name]
(LibCity-env) PS D:\Workspace\Bigscity-LibCity> python .\run_model.py --task traffic_state_pred --model GRU --dataset METR_LA --max_epoch 5
2024-01-17 20:57:25,740 - INFO - Log directory: ./libcity/log
2024-01-17 20:57:25,740 - INFO - Begin pipeline, task=traffic_state_pred, model_name=GRU, dataset_name=METR_LA, exp_id=72973
2024-01-17 20:57:25,740 - INFO - {'task': 'traffic_state_pred', 'model': 'RNN', 'dataset': 'METR_LA', 'saved_model': True, 'train': True, 'seed': 0, 'max_epoch': 5, 'dataset_class': 'TrafficStatePointDataset', 'executor': 'TrafficStateExecutor', 'evaluator': 'TrafficStateEvaluator', 'rnn_type': 'GRU', 'hidden_size': 64, 'num_layers': 1, 'dropout': 0, 'bidirectional': False, 'teacher_forcing_ratio': 0, 'scaler': 'standard', 'load_external': True, 'normal_external': False, 'ext_scaler': 'none', 'add_time_in_day': True, 'add_day_in_week': False, 'learner': 'adam', 'learning_rate': 0.01, 'lr_decay': True, 'lr_scheduler': 'multisteplr', 'lr_decay_ratio': 0.1, 'steps': [5, 20, 40, 70], 'clip_grad_norm': True, 'max_grad_norm': 5, 'use_early_stop': True, 'patience': 50, 'batch_size': 64, 'cache_dataset': True, 'num_workers': 0, 'pad_with_last_sample': True, 'train_rate': 0.7, 'eval_rate': 0.1, 'input_window': 12, 'output_window': 12, 'gpu': True, 'gpu_id': 0, 'train_loss': 'none', 'epoch': 0, 'weight_decay': 0, 'lr_epsilon': 1e-08, 'lr_beta1': 0.9, 'lr_beta2': 0.999, 'lr_alpha': 0.99, 'lr_momentum': 0, 'step_size': 10, 'lr_T_max': 30, 'lr_eta_min': 0, 'lr_patience': 10, 'lr_threshold': 0.0001, 'log_level': 'INFO', 'log_every': 1, 'load_best_epoch': True, 'hyper_tune': False, 'metrics': ['MAE', 'MAPE', 'MSE', 'RMSE', 'masked_MAE', 'masked_MAPE', 'masked_MSE', 'masked_RMSE', 'R2', 'EVAR'], 'evaluator_mode': 'single', 'save_mode': ['csv'], 'geo': {'including_types': ['Point'], 'Point': {}}, 'rel': {'including_types': ['geo'], 'geo': {'cost': 'num'}}, 'dyna': {'including_types': ['state'], 'state': {'entity_id': 'geo_id', 'traffic_speed': 'num'}}, 'data_col': ['traffic_speed'], 'weight_col': 'cost', 'data_files': ['METR_LA'], 'geo_file': 'METR_LA', 'rel_file': 'METR_LA', 'output_dim': 1, 'time_intervals': 300, 'init_weight_inf_or_zero': 'inf', 'set_weight_link_or_dist': 'dist', 'calculate_weight_adj': True, 'weight_adj_epsilon': 0.1, 'device': device(type='cuda', index=0), 'exp_id': 72973}
2024-01-17 20:57:25,750 - INFO - Loaded file METR_LA.geo, num_nodes=207
2024-01-17 20:57:25,758 - INFO - set_weight_link_or_dist: dist
2024-01-17 20:57:25,758 - INFO - init_weight_inf_or_zero: inf
2024-01-17 20:57:25,774 - INFO - Loaded file METR_LA.rel, shape=(207, 207)
2024-01-17 20:57:25,775 - INFO - Start Calculate the weight by Gauss kernel!
2024-01-17 20:57:25,776 - INFO - Loading ./libcity/cache/dataset_cache/point_based_METR_LA_12_12_0.7_0.1_standard_64_True_True_False_True.npz
2024-01-17 20:57:30,779 - INFO - train x: (23974, 12, 207, 2), y: (23974, 12, 207, 2)
2024-01-17 20:57:30,779 - INFO - eval x: (3425, 12, 207, 2), y: (3425, 12, 207, 2)
2024-01-17 20:57:30,779 - INFO - test x: (6850, 12, 207, 2), y: (6850, 12, 207, 2)
2024-01-17 20:57:31,038 - INFO - StandardScaler mean: 54.40592829587626, std: 19.493739270573098
2024-01-17 20:57:31,039 - INFO - NoneScaler
Using backend: pytorch
2024-01-17 20:57:33,490 - INFO - You select rnn_type GRU in RNN!
2024-01-17 20:57:36,885 - INFO - RNN(
(rnn): GRU(414, 64)
(fc): Linear(in_features=64, out_features=207, bias=True)
)
2024-01-17 20:57:36,885 - INFO - rnn.weight_ih_l0 torch.Size([192, 414]) cuda:0 True
2024-01-17 20:57:36,885 - INFO - rnn.weight_hh_l0 torch.Size([192, 64]) cuda:0 True
2024-01-17 20:57:36,885 - INFO - rnn.bias_ih_l0 torch.Size([192]) cuda:0 True
2024-01-17 20:57:36,885 - INFO - rnn.bias_hh_l0 torch.Size([192]) cuda:0 True
2024-01-17 20:57:36,886 - INFO - fc.weight torch.Size([207, 64]) cuda:0 True
2024-01-17 20:57:36,886 - INFO - fc.bias torch.Size([207]) cuda:0 True
2024-01-17 20:57:36,886 - INFO - Total parameter numbers: 105615
2024-01-17 20:57:36,886 - INFO - You select `adam` optimizer.
2024-01-17 20:57:36,886 - INFO - You select `multisteplr` lr_scheduler.
2024-01-17 20:57:36,886 - WARNING - Received none train loss func and will use the loss func defined in the model.
2024-01-17 20:57:36,886 - INFO - Start training ...
2024-01-17 20:57:36,886 - INFO - num_batches:375
2024-01-17 20:57:44,869 - INFO - epoch complete!
2024-01-17 20:57:44,869 - INFO - evaluating now!
2024-01-17 20:57:45,314 - INFO - Epoch [0/5] train_loss: 4.3369, val_loss: 3.8623, lr: 0.010000, 8.43s
2024-01-17 20:57:45,319 - INFO - Saved model at 0
2024-01-17 20:57:45,319 - INFO - Val loss decrease from inf to 3.8623, saving to ./libcity/cache/72973/model_cache/RNN_METR_LA_epoch0.tar
2024-01-17 20:57:52,143 - INFO - epoch complete!
2024-01-17 20:57:52,143 - INFO - evaluating now!
2024-01-17 20:57:52,617 - INFO - Epoch [1/5] train_loss: 3.7730, val_loss: 3.7464, lr: 0.010000, 7.30s
2024-01-17 20:57:52,619 - INFO - Saved model at 1
2024-01-17 20:57:52,620 - INFO - Val loss decrease from 3.8623 to 3.7464, saving to ./libcity/cache/72973/model_cache/RNN_METR_LA_epoch1.tar
2024-01-17 20:57:59,230 - INFO - epoch complete!
2024-01-17 20:57:59,231 - INFO - evaluating now!
2024-01-17 20:57:59,683 - INFO - Epoch [2/5] train_loss: 3.6986, val_loss: 3.7742, lr: 0.010000, 7.06s
2024-01-17 20:58:06,295 - INFO - epoch complete!
2024-01-17 20:58:06,295 - INFO - evaluating now!
2024-01-17 20:58:06,755 - INFO - Epoch [3/5] train_loss: 3.6315, val_loss: 3.7448, lr: 0.010000, 7.07s
2024-01-17 20:58:06,758 - INFO - Saved model at 3
2024-01-17 20:58:06,758 - INFO - Val loss decrease from 3.7464 to 3.7448, saving to ./libcity/cache/72973/model_cache/RNN_METR_LA_epoch3.tar
2024-01-17 20:58:13,660 - INFO - epoch complete!
2024-01-17 20:58:13,661 - INFO - evaluating now!
2024-01-17 20:58:14,151 - INFO - Epoch [4/5] train_loss: 3.6138, val_loss: 3.6896, lr: 0.001000, 7.39s
2024-01-17 20:58:14,153 - INFO - Saved model at 4
2024-01-17 20:58:14,153 - INFO - Val loss decrease from 3.7448 to 3.6896, saving to ./libcity/cache/72973/model_cache/RNN_METR_LA_epoch4.tar
2024-01-17 20:58:14,153 - INFO - Trained totally 5 epochs, average train time is 6.986s, average eval time is 0.464s
2024-01-17 20:58:14,156 - INFO - Loaded model at 4
2024-01-17 20:58:14,156 - INFO - Saved model at ./libcity/cache/72973/model_cache/GRU_METR_LA.m
2024-01-17 20:58:14,159 - INFO - Start evaluating ...
2024-01-17 20:58:21,954 - INFO - Note that you select the single mode to evaluate!
2024-01-17 20:58:21,958 - INFO - Evaluate result is saved at ./libcity/cache/72973/evaluate_cache\2024_01_17_20_58_21_RNN_METR_LA.csv
2024-01-17 20:58:21,964 - INFO -
MAE MAPE MSE RMSE masked_MAE masked_MAPE masked_MSE masked_RMSE R2 EVAR
1 10.031220 inf 416.525146 20.408947 3.934600 0.111058 55.707870 7.463770 0.193234 0.281972
2 10.694635 inf 495.239349 22.253973 3.947579 0.112308 57.335602 7.572028 0.040800 0.149547
3 10.734841 inf 498.895111 22.335960 3.968302 0.113311 58.568287 7.652992 0.033669 0.143887
4 10.748886 inf 499.769379 22.355522 3.985501 0.114182 59.538799 7.716139 0.032107 0.142843
5 10.766757 inf 500.671234 22.375685 4.006994 0.115209 60.595554 7.784315 0.030236 0.141791
6 10.797983 inf 501.702454 22.398716 4.043203 0.116535 61.787327 7.860491 0.027974 0.140506
7 10.811552 inf 502.702148 22.421021 4.057178 0.117378 62.751858 7.921607 0.026317 0.139208
8 10.836926 inf 503.923553 22.448242 4.084364 0.118553 63.953320 7.997082 0.023927 0.137658
9 10.865162 inf 505.282074 22.478479 4.114022 0.119828 65.227661 8.076365 0.021383 0.135840
10 10.892298 inf 506.745178 22.511002 4.142046 0.121148 66.596046 8.160640 0.018665 0.133966
11 10.928904 inf 508.425446 22.548292 4.180622 0.122837 68.217293 8.259377 0.015454 0.131663
12 10.971083 inf 510.906616 22.603243 4.219332 0.125011 70.105850 8.372924 0.010663 0.128921
模型评估与训练集结果会保存在
libcity/cache
目录下实验运行日志会保存在
libcity/log
目录下
二、添加新模型
1、创建Model类,继承模型抽象类
对于交通状态预测任务,请继承
AbstractTrafficStateModel
类对于轨迹位置预测任务,请继承
AbstractModel
类
例如,对于交通速度预测任务,请在libcity/model/traffic_speed_prediction
目录下创建一个新的文件NewModel.py
from libcity.model.abstract_traffic_state_model import AbstractTrafficStateModel
class NewModel(AbstractTrafficStateModel):
# __init__()用于根据数据特征和配置信息来定义模型结构,它的输入参数是config和data_feature,其中config包含各种配置信息,包括模型参数等,data_feature包含建立模型的数据集的特征。
def __init__(self, config, data_feature):
pass
# predict()方法,用来获得模型的预测结果。predict()的输入参数是batch,它是一个Batch类的对象。
def predict(self, batch):
pass
# calculate_loss()用于计算预测结果与真实值之间的loss。它的输入参数是batch,它是一个Batch类的对象。该方法返回一个用于反向传播的Torch.Tensor。
def calculate_loss(self, batch):
pass
2、实现__init__()
import torch
import torch.nn as nn
from logging import getLogger
from libcity.model.abstract_traffic_state_model import AbstractTrafficStateModel
class NewModel(AbstractTrafficStateModel):
# 这里我们以一个简单的LSTM交通预测模型为例。你可以像这样定义__init__()。
def __init__(self, config, data_feature):
super().__init__(config, data_feature)
# section 1: data_feature
# 从data_feature中获取必要的参数,包括节点数(num_nodes)、数据输入尺寸(feature_dim)、输出尺寸(output_dim)和数据规范化对象(scaler),并初始化logger。
self._scaler = self.data_feature.get('scaler')
self.num_nodes = self.data_feature.get('num_nodes', 1)
self.feature_dim = self.data_feature.get('feature_dim', 1)
self.output_dim = self.data_feature.get('output_dim', 1)
self._logger = getLogger()
# section 2: model config
# 从配置中获取必要的参数,包括隐藏层尺寸(hidden_size)、网络层数(num_layers)、输入时间长度(input_window)、输出时间长度(output_window),等等。
self.input_window = config.get('input_window', 1)
self.output_window = config.get('output_window', 1)
self.device = config.get('device', torch.device('cpu'))
self.hidden_size = config.get('hidden_size', 64)
self.num_layers = config.get('num_layers', 1)
self.dropout = config.get('dropout', 0)
# section 3: model structure
# 定义了模型结构,包括一个LSTM层和一个全连接层。
self.rnn = nn.LSTM(input_size=self.num_nodes * self.feature_dim, hidden_size=self.hidden_size,
num_layers=self.num_layers, dropout=self.dropout)
self.fc = nn.Linear(self.hidden_size, self.num_nodes * self.output_dim)
3、实现predict()
AbstractModel
和AbstractTrafficStateModel
两个抽象类都继承自torch.nn.Module
类。如果你熟悉Pytorch框架,你会发现这个函数与torch.nn.Module
中的forward()
函数类似。在大多数情况下,你可以在这个函数里面直接调用forward()
函数来获得模型的输出。
predict()
函数可以在forward()
函数计算的模型输出的基础上做一些额外的处理。例如,当forward()
函数计算的是模型的单步预测结果,而你需要的是多步预测的结果时,可以使用predict()
函数来实现。
class NewModel(AbstractTrafficStateModel):
def forward(self, batch):
src = batch['X'].clone()
src = src.permute(1, 0, 2, 3)
batch_size = src.shape[1]
src = src.reshape(self.input_window, batch_size, self.num_nodes * self.feature_dim)
outputs = []
for i in range(self.output_window):
out, _ = self.rnn(src)
out = self.fc(out[-1])
out = out.reshape(batch_size, self.num_nodes, self.output_dim)
outputs.append(out.clone())
src = torch.cat((src[1:, :, :], out.reshape(
batch_size, self.num_nodes * self.feature_dim).unsqueeze(0)), dim=0)
outputs = torch.stack(outputs)
return outputs.permute(1, 0, 2, 3)
def predict(self, batch):
return self.forward(batch)
可以看出,predict
函数直接调用forward
函数,而在forward
函数中,我们定义了模型的计算过程。这个模型使用LSTM进行多次预测,并将每次预测的输出作为下一个输入。这里我们假设输入数据维度和输出数据维度相等,即feature_dim=output_dim
。
4、实现calcualte_loss()
你可以自定义损失函数或者调用我们在libcity/model/loss.py
文件中定义的损失函数。
from libcity.model import loss
class NewModel(AbstractTrafficStateModel):
def calculate_loss(self, batch):
y_true = batch['y']
y_predicted = self.predict(batch)
y_true = self._scaler.inverse_transform(y_true[..., :self.output_dim])
y_predicted = self._scaler.inverse_transform(y_predicted[..., :self.output_dim])
return loss.masked_mae_torch(y_predicted, y_true, 0)
※、完整的NewModel.py
import torch
import torch.nn as nn
from logging import getLogger
from libcity.model import loss
from libcity.model.abstract_traffic_state_model import AbstractTrafficStateModel
class NewModel(AbstractTrafficStateModel):
def __init__(self, config, data_feature):
super().__init__(config, data_feature)
# section 1: data_feature
self._scaler = self.data_feature.get('scaler')
self.num_nodes = self.data_feature.get('num_nodes', 1)
self.feature_dim = self.data_feature.get('feature_dim', 1)
self.output_dim = self.data_feature.get('output_dim', 1)
self._logger = getLogger()
# section 2: model config
self.input_window = config.get('input_window', 1)
self.output_window = config.get('output_window', 1)
self.device = config.get('device', torch.device('cpu'))
self.hidden_size = config.get('hidden_size', 64)
self.num_layers = config.get('num_layers', 1)
self.dropout = config.get('dropout', 0)
# section 3: model structure
self.rnn = nn.LSTM(input_size=self.num_nodes * self.feature_dim, hidden_size=self.hidden_size,
num_layers=self.num_layers, dropout=self.dropout)
self.fc = nn.Linear(self.hidden_size, self.num_nodes * self.output_dim)
def forward(self, batch):
src = batch['X'].clone()
src = src.permute(1, 0, 2, 3)
batch_size = src.shape[1]
src = src.reshape(self.input_window, batch_size, self.num_nodes * self.feature_dim)
outputs = []
for i in range(self.output_window):
out, _ = self.rnn(src)
out = self.fc(out[-1])
out = out.reshape(batch_size, self.num_nodes, self.output_dim)
outputs.append(out.clone())
src = torch.cat((src[1:, :, :], out.reshape(
batch_size, self.num_nodes * self.feature_dim).unsqueeze(0)), dim=0)
outputs = torch.stack(outputs)
return outputs.permute(1, 0, 2, 3)
def predict(self, batch):
return self.forward(batch)
def calculate_loss(self, batch):
y_true = batch['y']
y_predicted = self.predict(batch)
y_true = self._scaler.inverse_transform(y_true[..., :self.output_dim])
y_predicted = self._scaler.inverse_transform(y_predicted[..., :self.output_dim])
return loss.masked_mae_torch(y_predicted, y_true, 0)
5、导入模型
libcity/model/traffic_speed_prediction/__init__.py
# .......
from libcity.model.traffic_speed_prediction.NewModel import NewModel
__all__ = [
# ......,
"NewModel"
]
6、加入模型参数
/libcity/config/task_config.json
{
# ......,
"traffic_state_pred": {
"allowed_model": [
# ......,
"NewModel"
],
# ......,
"NewModel": {
"dataset_class": "TrafficStatePointDataset",
"executor": "TrafficStateExecutor",
"evaluator": "TrafficStateEvaluator"
}
}
}
7、运行模型
(LibCity-env) PS D:\Workspace\Bigscity-LibCity> python run_model.py --task traffic_state_pred --model NewModel --dataset METR_LA --max_epoch 5
2024-01-18 16:28:37,479 - INFO - Log directory: ./libcity/log
2024-01-18 16:28:37,480 - INFO - Begin pipeline, task=traffic_state_pred, model_name=NewModel, dataset_name=METR_LA, exp_id=2154
2024-01-18 16:28:37,480 - INFO - {'task': 'traffic_state_pred', 'model': 'NewModel', 'dataset': 'METR_LA', 'saved_model': True, 'train': True, 'seed': 0, 'max_epoch': 5, 'dataset_class': 'TrafficStatePointDataset', 'executor': 'TrafficStateExecutor', 'evaluator': 'TrafficStateEvaluator', 'hidden_size': 64, 'num_layers': 1, 'dropout': 0, 'learner': 'adam', 'learning_rate': 0.001, 'batch_size': 64, 'cache_dataset': True, 'num_workers': 0, 'pad_with_last_sample': True, 'train_rate': 0.7, 'eval_rate': 0.1, 'scaler': 'none', 'load_external': False, 'normal_external': False, 'ext_scaler': 'none', 'input_window': 12, 'output_window': 12, 'add_time_in_day': False, 'add_day_in_week': False, 'gpu': True, 'gpu_id': 0, 'train_loss': 'none', 'epoch': 0, 'weight_decay': 0, 'lr_epsilon': 1e-08, 'lr_beta1': 0.9, 'lr_beta2': 0.999, 'lr_alpha': 0.99, 'lr_momentum': 0, 'lr_decay': False, 'lr_scheduler': 'multisteplr', 'lr_decay_ratio': 0.1, 'steps': [5, 20, 40, 70], 'step_size': 10, 'lr_T_max': 30, 'lr_eta_min': 0, 'lr_patience': 10, 'lr_threshold': 0.0001, 'clip_grad_norm': False, 'max_grad_norm': 1.0, 'use_early_stop': False, 'patience': 50, 'log_level': 'INFO', 'log_every': 1, 'load_best_epoch': True, 'hyper_tune': False, 'metrics': ['MAE', 'MAPE', 'MSE', 'RMSE', 'masked_MAE', 'masked_MAPE', 'masked_MSE', 'masked_RMSE', 'R2', 'EVAR'], 'evaluator_mode': 'single', 'save_mode': ['csv'], 'geo': {'including_types': ['Point'], 'Point': {}}, 'rel': {'including_types': ['geo'], 'geo': {'cost': 'num'}}, 'dyna': {'including_types': ['state'], 'state': {'entity_id': 'geo_id', 'traffic_speed': 'num'}}, 'data_col': ['traffic_speed'], 'weight_col': 'cost', 'data_files': ['METR_LA'], 'geo_file': 'METR_LA', 'rel_file': 'METR_LA', 'output_dim': 1, 'time_intervals': 300, 'init_weight_inf_or_zero': 'inf', 'set_weight_link_or_dist': 'dist', 'calculate_weight_adj': True, 'weight_adj_epsilon': 0.1, 'device': device(type='cuda', index=0), 'exp_id': 2154}
2024-01-18 16:28:37,491 - INFO - Loaded file METR_LA.geo, num_nodes=207
2024-01-18 16:28:37,496 - INFO - set_weight_link_or_dist: dist
2024-01-18 16:28:37,496 - INFO - init_weight_inf_or_zero: inf
2024-01-18 16:28:37,511 - INFO - Loaded file METR_LA.rel, shape=(207, 207)
2024-01-18 16:28:37,512 - INFO - Start Calculate the weight by Gauss kernel!
2024-01-18 16:28:37,513 - INFO - Loading ./libcity/cache/dataset_cache/point_based_METR_LA_12_12_0.7_0.1_none_64_False_False_False_True.npz
2024-01-18 16:28:38,921 - INFO - train x: (23974, 12, 207, 1), y: (23974, 12, 207, 1)
2024-01-18 16:28:38,921 - INFO - eval x: (3425, 12, 207, 1), y: (3425, 12, 207, 1)
2024-01-18 16:28:38,921 - INFO - test x: (6850, 12, 207, 1), y: (6850, 12, 207, 1)
2024-01-18 16:28:38,921 - INFO - NoneScaler
2024-01-18 16:28:38,921 - INFO - NoneScaler
Using backend: pytorch
2024-01-18 16:28:41,446 - INFO - NewModel(
(rnn): LSTM(207, 64)
(fc): Linear(in_features=64, out_features=207, bias=True)
)
2024-01-18 16:28:41,446 - INFO - rnn.weight_ih_l0 torch.Size([256, 207]) cuda:0 True
2024-01-18 16:28:41,446 - INFO - rnn.weight_hh_l0 torch.Size([256, 64]) cuda:0 True
2024-01-18 16:28:41,446 - INFO - rnn.bias_ih_l0 torch.Size([256]) cuda:0 True
2024-01-18 16:28:41,446 - INFO - rnn.bias_hh_l0 torch.Size([256]) cuda:0 True
2024-01-18 16:28:41,447 - INFO - fc.weight torch.Size([207, 64]) cuda:0 True
2024-01-18 16:28:41,447 - INFO - fc.bias torch.Size([207]) cuda:0 True
2024-01-18 16:28:41,447 - INFO - Total parameter numbers: 83343
2024-01-18 16:28:41,447 - INFO - You select `adam` optimizer.
2024-01-18 16:28:41,447 - WARNING - Received none train loss func and will use the loss func defined in the model.
2024-01-18 16:28:41,447 - INFO - Start training ...
2024-01-18 16:28:41,447 - INFO - num_batches:375
2024-01-18 16:28:48,016 - INFO - epoch complete!
2024-01-18 16:28:48,016 - INFO - evaluating now!
2024-01-18 16:28:48,394 - INFO - Epoch [0/5] train_loss: 45.9325, val_loss: 34.5536, lr: 0.001000, 6.95s
2024-01-18 16:28:48,396 - INFO - Saved model at 0
2024-01-18 16:28:48,396 - INFO - Val loss decrease from inf to 34.5536, saving to ./libcity/cache/2154/model_cache/NewModel_METR_LA_epoch0.tar
2024-01-18 16:28:54,274 - INFO - epoch complete!
2024-01-18 16:28:54,274 - INFO - evaluating now!
2024-01-18 16:28:54,628 - INFO - Epoch [1/5] train_loss: 24.3525, val_loss: 15.8954, lr: 0.001000, 6.23s
2024-01-18 16:28:54,630 - INFO - Saved model at 1
2024-01-18 16:28:54,630 - INFO - Val loss decrease from 34.5536 to 15.8954, saving to ./libcity/cache/2154/model_cache/NewModel_METR_LA_epoch1.tar
2024-01-18 16:29:00,554 - INFO - epoch complete!
2024-01-18 16:29:00,554 - INFO - evaluating now!
2024-01-18 16:29:00,897 - INFO - Epoch [2/5] train_loss: 9.3111, val_loss: 6.4983, lr: 0.001000, 6.27s
2024-01-18 16:29:00,900 - INFO - Saved model at 2
2024-01-18 16:29:00,900 - INFO - Val loss decrease from 15.8954 to 6.4983, saving to ./libcity/cache/2154/model_cache/NewModel_METR_LA_epoch2.tar
2024-01-18 16:29:06,729 - INFO - epoch complete!
2024-01-18 16:29:06,729 - INFO - evaluating now!
2024-01-18 16:29:07,082 - INFO - Epoch [3/5] train_loss: 6.1995, val_loss: 6.3157, lr: 0.001000, 6.18s
2024-01-18 16:29:07,084 - INFO - Saved model at 3
2024-01-18 16:29:07,084 - INFO - Val loss decrease from 6.4983 to 6.3157, saving to ./libcity/cache/2154/model_cache/NewModel_METR_LA_epoch3.tar
2024-01-18 16:29:12,978 - INFO - epoch complete!
2024-01-18 16:29:12,978 - INFO - evaluating now!
2024-01-18 16:29:13,318 - INFO - Epoch [4/5] train_loss: 6.1627, val_loss: 6.3008, lr: 0.001000, 6.23s
2024-01-18 16:29:13,320 - INFO - Saved model at 4
2024-01-18 16:29:13,320 - INFO - Val loss decrease from 6.3157 to 6.3008, saving to ./libcity/cache/2154/model_cache/NewModel_METR_LA_epoch4.tar
2024-01-18 16:29:13,320 - INFO - Trained totally 5 epochs, average train time is 6.018s, average eval time is 0.353s
2024-01-18 16:29:13,322 - INFO - Loaded model at 4
2024-01-18 16:29:13,322 - INFO - Saved model at ./libcity/cache/2154/model_cache/NewModel_METR_LA.m
2024-01-18 16:29:13,323 - INFO - Start evaluating ...
2024-01-18 16:29:18,229 - INFO - Note that you select the single mode to evaluate!
2024-01-18 16:29:18,233 - INFO - Evaluate result is saved at ./libcity/cache/2154/evaluate_cache\2024_01_18_16_29_18_NewModel_METR_LA.csv
2024-01-18 16:29:18,238 - INFO -
MAE MAPE MSE RMSE masked_MAE masked_MAPE masked_MSE masked_RMSE R2 EVAR
1 13.266040 inf 603.920044 24.574785 6.729965 0.255871 170.165543 13.044751 -0.169730 0.065772
2 13.318529 inf 610.564026 24.709595 6.728839 0.255858 170.149841 13.044149 -0.182566 0.055272
3 13.317531 inf 610.582642 24.709970 6.727323 0.255828 170.131927 13.043463 -0.182664 0.055242
4 13.318391 inf 610.589172 24.710102 6.728044 0.255839 170.118225 13.042937 -0.182516 0.055199
5 13.318027 inf 610.612854 24.710583 6.727427 0.255843 170.130798 13.043420 -0.182713 0.055232
6 13.327496 inf 610.704712 24.712440 6.738001 0.256047 170.222977 13.046953 -0.183214 0.055235
7 13.322623 inf 610.684631 24.712034 6.732237 0.255912 170.185852 13.045530 -0.182834 0.055128
8 13.323362 inf 610.705872 24.712463 6.732856 0.255946 170.195969 13.045918 -0.182905 0.055188
9 13.324505 inf 610.710327 24.712555 6.733935 0.255953 170.187286 13.045585 -0.182808 0.055208
10 13.322044 inf 610.710510 24.712557 6.730917 0.255905 170.173950 13.045074 -0.182669 0.055238
11 13.323273 inf 610.740417 24.713163 6.732097 0.255915 170.194336 13.045856 -0.182674 0.055182
12 13.320498 inf 610.728333 24.712919 6.728723 0.255867 170.167007 13.044807 -0.182636 0.055214