What arguments are you passing into F.affine_grid? affine_grid takes two arguments: F.affine_grid(theta, size). The error is suggesting that theta.size()[0] should be equal to 1, but is actually equal to 49 (or the other way around).