def test_gconv_lstm_layer(): """ Testing the GConvLSTM Layer. """ number_of_nodes = 100 edge_per_node = 10 in_channels = 64 out_channels = 16 K = 2 X, edge_index = create_mock_data(number_of_nodes, edge_per_node, in_channels) edge_weight = create_mock_edge_weight(edge_index) layer = GConvLSTM(in_channels=in_channels, out_channels=out_channels, K=K) H, C = layer(X, edge_index) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels) H, C = layer(X, edge_index, edge_weight) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels) H, C = layer(X, edge_index, edge_weight, H, C) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels)
def test_gconv_lstm_layer(): """ Testing the GConvLSTM Layer. """ number_of_nodes = 100 edge_per_node = 10 in_channels = 64 out_channels = 16 K = 2 device = torch.device("cuda" if torch.cuda.is_available() else "cpu") X, edge_index = create_mock_data(number_of_nodes, edge_per_node, in_channels) X = X.to(device) edge_index = edge_index.to(device) edge_weight = create_mock_edge_weight(edge_index).to(device) layer = GConvLSTM(in_channels=in_channels, out_channels=out_channels, K=K).to(device) H, C = layer(X, edge_index) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels) H, C = layer(X, edge_index, edge_weight) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels) H, C = layer(X, edge_index, edge_weight, H, C) assert H.shape == (number_of_nodes, out_channels) assert C.shape == (number_of_nodes, out_channels)
def __init__(self, node_features, num_classes): super(RecurrentGCN, self).__init__() self.recurrent_1 = GConvLSTM(node_features, 32, 5) self.recurrent_2 = GConvLSTM(32, 16, 5) self.linear = torch.nn.Linear(16, num_classes)
def __init__(self, node_features): super(RecurrentGCN, self).__init__() self.recurrent = GConvLSTM(node_features, 32, 1) self.linear = torch.nn.Linear(32, 1)
def __init__(self, input_feat=2, Conv_outputs=[5], LSTM_output=[5], K=1, linear_output=3): super(social_stgcn, self).__init__() self.input_feat = input_feat self.Conv_outputs = Conv_outputs self.LSTM_output = LSTM_output self.linear_output = linear_output self.K = K self.gcn1 = GCNConv(in_channels=self.input_feat, out_channels=self.Conv_outputs[0], improved=True) self.gcn2 = GCNConv(in_channels=self.Conv_outputs[0], out_channels=self.Conv_outputs[1], improved=True) self.gclstm1 = GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.Conv_outputs[1], K=K, normalization="sym", bias=True) self.gclstm2 = GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.Conv_outputs[1], K=K, normalization="sym", bias=True) self.gclstm3 = GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.LSTM_output[0], K=K, normalization="sym", bias=True) self.no_lstm = 3 self.linear = nn.Linear(in_features=self.LSTM_output[0], out_features=self.linear_output) self.gcn = Sequential('x, edge_index, h_none', [ (GCNConv(in_channels=self.input_feat, out_channels=self.Conv_outputs[0], improved=True), 'x, edge_index -> x'), (nn.ReLU(), 'x -> x'), (GCNConv(in_channels=self.Conv_outputs[0], out_channels=self.Conv_outputs[1], improved=True), 'x, edge_index -> x'), (nn.ReLU(), 'x -> x'), (GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.Conv_outputs[1], K=K, normalization="sym", bias=True), 'x, edge_index -> h, c'), (GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.Conv_outputs[1], K=K, normalization="sym", bias=True), 'h, edge_index, h_none, c -> h, c'), (GConvLSTM(in_channels=self.Conv_outputs[1], out_channels=self.LSTM_output[0], K=K, normalization="sym", bias=True), 'h, edge_index, h_none, c-> h, c'), # TO BE TESTED LATER # (GCLSTM(in_channels=self.Conv_outputs[1], # out_channels=self.LSTM_output[0], # K=K, normalization="sym", bias=True), 'x, edge_index -> h, c'), # # (GCLSTM(in_channels=self.LSTM_output[0], # out_channels=self.LSTM_output[1], # K=K, normalization="sym", bias=True), 'x, edge_index, h, c -> h, c'), # # (GCLSTM(in_channels=self.LSTM_output[1], # out_channels=self.LSTM_output[2], # K=K, normalization="sym", bias=True), 'h, edge_index, c -> h, _'), (nn.ReLU(), "h -> h"), (nn.Linear(in_features=self.LSTM_output[0], out_features=self.linear_output), "h -> x")])