How does the “view” method work in PyTorch?

后端 未结 8 2036
别那么骄傲
别那么骄傲 2020-12-07 07:14

I am confused about the method view() in the following code snippet.

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__in         


        
8条回答
  •  春和景丽
    2020-12-07 07:37

    weights.reshape(a, b) will return a new tensor with the same data as weights with size (a, b) as in it copies the data to another part of memory.

    weights.resize_(a, b) returns the same tensor with a different shape. However, if the new shape results in fewer elements than the original tensor, some elements will be removed from the tensor (but not from memory). If the new shape results in more elements than the original tensor, new elements will be uninitialized in memory.

    weights.view(a, b) will return a new tensor with the same data as weights with size (a, b)

提交回复
热议问题