I’m receiving this error:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
File "/project_cpu/layers.py", line 22, in forward
    return torch.cat((input1, input2), dim=1)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 8 and 4 in dimension 2 at /Users/soumith/code/builder/wheel/pytorch-src/aten/src/TH/generic/THTensorMath.cpp:3616

I want to concatenate two layers if their shape match in dimension 2 by a factor. If the layer1 has larger shape there is not a problem at all, but if the layer2 is larger, then I have the error.
('layer1: ', (128, 64, 8, 8))
('layer2: ', (128, 64, 16, 16))
('factor: ', 2)
This is where I check the matching layers:
if model.layerdic[x].size()[2] == factor * model.layerdic[y].size()[2]:
                        matching.append([x, y, factor])

I have a class like below:
class Concatenate(torch.nn.Module):
    def __init__(self):
        super(Concatenate, self).__init__()
        
    def forward(self, input1, input2):
        return torch.cat((input1, input2), dim=1)

Then I create this new merge layer as following:
if old_model.layerdic[layer1_id].size()[2] < old_model.layerdic[layer2_id].size()[2]:
            pool_layer = {'type': 'pool', 'params': {'poolsize': downsampling_factor, 'pooltype': 'max'}, 'id': new_id_pool,
                          'input': [layer2_id]}
            new_model_descriptor['layers'].append(pool_layer)

            merge_layer = {'type': 'merge', 'params': {'mergetype': 'concat'}, 'id': new_id,
                           'input': [layer1_id, new_id_pool]}
            new_model_descriptor['layers'].append(merge_layer)
else:
            pool_layer = {'type': 'pool', 'params': {'poolsize': downsampling_factor, 'pooltype': 'max'}, 'id': new_id_pool,
                          'input': [layer1_id]}
            new_model_descriptor['layers'].append(pool_layer)

            merge_layer = {'type': 'merge', 'params': {'mergetype': 'concat'}, 'id': new_id,
                           'input': [new_id_pool, layer2_id]}
            new_model_descriptor['layers'].append(merge_layer)

I don’t see a mismatch and I don’t understand why I have this error. I even don’t have 4 in dimension 2…