In PyTorch, you can change the shape of tensors using the .view() method, which allows you to reshape a tensor as long as the new shape is compatible with the original number of elements. Given that a1 and b1 both have a size of [256, 14400], to reshape them to [256, 128, 15, 15], you need to ensure that the total number of elements remains the same.
The original size has 256 * 14400 elements, and the desired size has 256 * 128 * 15 * 15 elements. Let's verify that these two are equal:
Original elements: 256 * 14400
Desired elements: 256 * 128 * 15 * 15
Both shapes must have the same total number of elements to allow a reshape. Let's calculate:
14400 = 128 * 15 * 15
If we calculate the right-hand side:
128 * 15 * 15 = 28800
This does not equal 14400, which means that the original size of [256, 14400] cannot be directly reshaped to [256, 128, 15, 15]. There's a mismatch in the total number of elements. It seems there might be a mistake either in the original tensor size or in the desired target size.
However, if you intended to have a tensor with a different number of channels (other than 128) that would match the 14400 elements when multiplied by the spatial dimensions (15 x 15), you could calculate the appropriate number of channels like this:
Channels = 14400 / (15 * 15) = 64
So you could reshape a1 and b1 to [256, 64, 15, 15] like this:
a1_reshaped = a1.view(256, 64, 15, 15)
b1_reshaped = b1.view(256, 64, 15, 15)
If you need a different number of channels but with the same spatial dimensions (15 x 15), you will have to adjust the number of channels accordingly to keep the total number of elements consistent.
If you made a mistake in your question and the target size is indeed possible with the number of elements you have, please provide the correct sizes, and I will help you with the code to reshape the tensors accordingly.