Hi,
Hope you are fine!
So I want to concat the output of two linear layers with dynamic batch size. I have Graph Convolutional Netowrk that I am combining with a CNN. The graph network has a Linear layer at the end and so does the CNN. I want to concatenate the two output of these layers and pass it to the next layer. (The batch size of the graph network is not static as the number of nodes changes with each graph)
Here is a code :-
def __init__(self,data, in_channels, representation_size):
        super(customTwoMLPHead, self).__init__()
        self.data=data[0]
        self.conv1 = GCNConv(data[0].x.shape[1], 128)
        self.conv2 = GCNConv(128, 256)  
        self.conv3 = GCNConv(256, 512)
        self.fc1 = torch.nn.Linear(512,1024,bias =True)
        self.fc_cnn_1= nn.Linear(in_channels, representation_size,bias =True)
        self.fc_cnn_2 = nn.Linear(representation_size+1024, representation_size,bias =True)  

    def forward(self,x,data):
        data=data[0]
        y, edge_index, edge_weight = data.x, data.edge_index, data.edge_attr
        y = F.relu(self.conv1(y, edge_index))
        y = F.relu(self.conv2(y, edge_index))
        y=F.dropout(y,p=0.5)
        y = F.relu(self.conv3(y, edge_index))
        y=F.relu(self.fc1(y)) #[batch_size,1024], batch_size is dynamic
        x = x.flatten(start_dim=1)

        x = F.relu(self.self.fc_cnn_1(x)) ##[batch_size,1024], batch_size is static
        x = torch.cat((x, y), 1)
        x = F.relu(self.self.fc_cnn_2(x))
        return x

I get errors like
RuntimeError: Sizes of tensors must match except in dimension 1. Got 1024 and 678(graph network batch_size) in dimension 0 (The offending index is 1)


Please Help !
Thanks