|
1 | 1 | import time
|
2 |
| -import os |
3 |
| -import numpy as np |
4 | 2 |
|
| 3 | +import numpy as np |
5 | 4 | import torch.optim
|
6 | 5 |
|
7 | 6 | from torchts.nn.models.dcrnn import DCRNN
|
|
11 | 10 | "cl_decay_steps": 2000,
|
12 | 11 | "filter_type": "dual_random_walk",
|
13 | 12 | "horizon": 12,
|
14 |
| - "seq_len":12, |
| 13 | + "seq_len": 12, |
15 | 14 | "input_dim": 2,
|
16 |
| - "max_diffusion_step": 2, |
| 15 | + "max_diffusion_step": 2, |
17 | 16 | "num_layers": 2,
|
18 | 17 | "output_dim": 2,
|
19 | 18 | "use_curriculum_learning": True,
|
20 | 19 | }
|
21 | 20 |
|
22 |
| -optimizer_args = { |
23 |
| - 'lr':0.01 |
24 |
| - } |
| 21 | +optimizer_args = {"lr": 0.01} |
25 | 22 |
|
26 | 23 | # Code to retrieve the graph in the form of an adjacency matrix.
|
27 | 24 | # This corresponds to the distance between 2 traffic sensors in a traffic network.
|
28 | 25 | # For other applications it can mean anything that defines the adjacency between nodes
|
29 | 26 | # eg. distance between airports of different cities when predicting
|
30 | 27 | # covid infection rate.
|
31 | 28 |
|
32 |
| -graph_pkl_filename = "/home/akash/Desktop/multi-gpu/newest_adj_max.pkl" # Absolute path of graph expected. |
| 29 | +graph_pkl_filename = "<Path to graph>" |
33 | 30 |
|
34 |
| -_,_, adj_mx = utils.load_graph_data(graph_pkl_filename) |
| 31 | +_, _, adj_mx = utils.load_graph_data(graph_pkl_filename) |
35 | 32 |
|
36 | 33 | num_units = adj_mx.shape[0]
|
37 | 34 |
|
38 |
| -model_config['num_nodes'] = num_units |
| 35 | +model_config["num_nodes"] = num_units |
| 36 | + |
| 37 | +data = np.load( |
| 38 | + "<Path to training *.npz file>" |
| 39 | +) # Absolute path of train, test, val needed. |
39 | 40 |
|
40 |
| -data = np.load("/home/akash/Desktop/multi-gpu/train.npz") # Absolute path of train, test, val needed. |
41 | 41 |
|
42 | 42 | def run():
|
43 |
| - model = DCRNN(adj_mx,num_units,optimizer = torch.optim.SGD,optimizer_args = optimizer_args,**model_config) |
| 43 | + model = DCRNN( |
| 44 | + adj_mx, |
| 45 | + num_units, |
| 46 | + optimizer=torch.optim.SGD, |
| 47 | + optimizer_args=optimizer_args, |
| 48 | + **model_config |
| 49 | + ) |
44 | 50 | start = time.time()
|
45 |
| - model.fit(torch.from_numpy(data['x'].astype('float32')),torch.from_numpy(data['y'].astype('float32')),max_epochs = 10,batch_size = 8) |
| 51 | + model.fit( |
| 52 | + torch.from_numpy(data["x"].astype("float32")), |
| 53 | + torch.from_numpy(data["y"].astype("float32")), |
| 54 | + max_epochs=10, |
| 55 | + batch_size=8, |
| 56 | + ) |
46 | 57 | end = time.time() - start
|
47 | 58 | print("Training time taken %f" % (end - start))
|
48 | 59 |
|
| 60 | + |
49 | 61 | if __name__ == "__main__":
|
50 | 62 | run()
|
0 commit comments