今天就跟大家聊聊有關torch.Tensor.type()方法如何使用,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
總結:
該方法的功能是: 當不指定dtype時,返回類型. 當指定dtype時,返回類型轉換后的數據,如果類型已經符合要求, 那么不做額外的復制,返回原對象.
Microsoft Windows [版本 10.0.18363.1256](c) 2019 Microsoft Corporation。保留所有權利。 C:\Users\chenxuqi>conda activate ssd4pytorch2_2_0(ssd4pytorch2_2_0) C:\Users\chenxuqi>python Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.>>> import torch>>> a = torch.ones(2,3)>>> a.type()'torch.FloatTensor'>>> a.dtype torch.float32>>>>>> a tensor([[1., 1., 1.],[1., 1., 1.]])>>>>>>>>>>>>>>> b = a.type(dtype='torch.DoubleTensor')>>> b tensor([[1., 1., 1.],[1., 1., 1.]], dtype=torch.float64)>>> b.type()'torch.DoubleTensor'>>> b.dtype torch.float64>>>>>>>>>>>> b = a.type(dtype='torch.cuda.DoubleTensor')>>> b tensor([[1., 1., 1.],[1., 1., 1.]], device='cuda:0', dtype=torch.float64)>>> b.type()'torch.cuda.DoubleTensor'>>> b.dtype torch.float64>>>>>>>>> a tensor([[1., 1., 1.],[1., 1., 1.]])>>> a.type()'torch.FloatTensor'>>> a.dtype torch.float32>>>>>>>>>>>>
看完上述內容,你們對torch.Tensor.type()方法如何使用有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。