Skip to content

PyTorch

tensor操作

unsqueeze permute 交换维度

optimizer.zero_grad() BP前所有参数的梯度清零 loss.backward() optimizer.step()

# input (4, 3, 64, 64)   # [b, v, x, y]
from einops import rearrange
rearrange(input, "b v x y -> (b v) x y")
# torch.Size([12, 64, 64])  # 4*3=12
  • b: batch size
  • v: views/frames
  • x, y: height, width