input = torch.rand(128,1,128,500) is a 3D representation of 2D data. Just as add new dimension to adapt to the function, it doesn’t affect your data processing.
3D to 4D tensor:
input = torch.rand(128,128,500) # 128x128x500
input = input.unsqueeze(1) # 128x1x128x500

2D to 3D tensor:
input = torch.rand(128,500) # 128x500
input = input.unsqueeze(0) #1x128x500