Resize PyTorch Tensor

前端 未结 3 1159
醉梦人生
醉梦人生 2021-01-18 10:27

I am currently using the tensor.resize() function to resize a tensor to a new shape t = t.resize(1, 2, 3).

This gives me a deprecation warning:

3条回答
  •  北海茫月
    2021-01-18 11:03

    Simply use t = t.contiguous().view(1, 2, 3) if you don't really want to change its data.

    If not the case, the in-place resize_ operation will break the grad computation graph of t.
    If it doesn't matter to you, just use t = t.data.resize_(1,2,3).

提交回复
热议问题