RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 256 and 130 in dimension 2 at /pytorch/aten/src/THC/generic/THCTensorMath.cu:71

Error :

Traceback (most recent call last):
  File "main.py", line 118, in <module>
    main()
  File "main.py", line 48, in main
    model.train()
  File "/workspace/aniket/edge-informed-sisr/src/edge_match.py", line 120, in train
    hr_images_pred, gen_loss, dis_loss, logs = self.sr_model.process(lr_images, hr_images, lr_edges, hr_edges_pred)
  File "/workspace/aniket/edge-informed-sisr/src/models.py", line 210, in process
    outputs = self(lr_images, hr_edges)
  File "/workspace/aniket/edge-informed-sisr/eisr-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/workspace/aniket/edge-informed-sisr/src/models.py", line 263, in forward
    inputs = torch.cat((hr_images, hr_edges), dim=1)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 256 and 130 in dimension 2 at /pytorch/aten/src/THC/generic/THCTensorMath.cu:71

Code :

    def forward(self, lr_images, hr_edges):
        hr_images = F.conv_transpose2d(lr_images, self.scale_kernel, padding=0, stride=2, groups=3)
        inputs = torch.cat((hr_images, hr_edges), dim=1)
        outputs = self.generator(inputs)
        return outputs

I am getting dimension mismatch error.

Based on the error message hr_images and hr_edges have different shapes in dim2, while only a size mismatch would be allowed in dim1, which is used to concatenate the tensors.
You can print the shape of both tensors before applying the torch.cat operation and make sure the spatial shapes match.

I am training the EISR model https://github.com/knazeri/edge-informed-sisr.git, I can train the model properly for the x2 scale factor, but while training for the x4 scale factor, I’m facing the dimension mismatch issue. Can you guide me on how to fix the above issue?

I’m not familiar with the repository, but it seems that the scale factors are used here so you could check why the shapes are wrong using a larger scale factor of 4.