tensor.expand returns a new view of the tensor with singleton dimensions expanded to a larger size.
Based on your code snippet I assume you would like to expand the batch dimension.
If that’s the case, you would need to keep the channel, height, and width dimension equal, which is not the case in your code snippet.
imgs_A seems to have 3 channels, while you are passing 1 to the expand operation in dim1.
PS: Variables are deprecated since PyTorch 0.4, so you can use tensors in newer versions.