Commit 8bae56a4 by xlwang

Correct an error for metric calculation

parent b617e1a2
...@@ -49,15 +49,15 @@ def main(config): ...@@ -49,15 +49,15 @@ def main(config):
for i, (x, y) in tqdm(enumerate(test_data_loader.get_iterator()), total=num_test_iteration): for i, (x, y) in tqdm(enumerate(test_data_loader.get_iterator()), total=num_test_iteration):
x = torch.FloatTensor(x).cuda() x = torch.FloatTensor(x).cuda()
y = torch.FloatTensor(y).cuda() y = torch.FloatTensor(y).cuda()
outputs = model(x, y, 0) # (seq_length+1, batch_size, num_nodes*output_dim) (13, 50, 207*1) outputs = model(x, y, 0) # (seq_length, batch_size, num_nodes*output_dim) (12, 50, 207*1)
y_preds = torch.cat([y_preds, outputs], dim=1) y_preds = torch.cat([y_preds, outputs], dim=1)
y_preds = torch.transpose(y_preds, 0, 1) y_preds = torch.transpose(y_preds, 0, 1) # (6850, 12, 207)
y_preds = y_preds.detach().numpy() # cast to numpy array y_preds = y_preds.detach().numpy() # cast to numpy array
print("--------test results--------") print("--------test results--------")
for horizon_i in range(y_truths.shape[1]): for horizon_i in range(y_truths.shape[1]):
y_truth = np.squeeze(y_truths[:, horizon_i, :, 0]) y_truth = np.squeeze(y_truths[:, horizon_i, :, 0]) # should be (6850, 207)
y_pred = scaler.inverse_transform(y_preds[:y_truth.shape[0], horizon_i, :]) y_pred = scaler.inverse_transform(y_preds[:y_truth.shape[0], horizon_i, :]) # should be (6850, 207)
predictions.append(y_pred) predictions.append(y_pred)
mae = metrics.masked_mae_np(y_pred, y_truth, null_val=0) mae = metrics.masked_mae_np(y_pred, y_truth, null_val=0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment