亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

pytorch masked_fill報(bào)錯(cuò)的解決

 更新時(shí)間:2020年02月18日 08:48:48   作者:昕晴  
今天小編就為大家分享一篇pytorch masked_fill報(bào)錯(cuò)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

如下所示:

import torch.nn.functional as F
import numpy as np
a = torch.Tensor([1,2,3,4])
a = a.masked_fill(mask = torch.ByteTensor([1,1,0,0]), value=-np.inf)
 
print(a)
b = F.softmax(a)

print(b)

tensor([-inf, -inf, 3., 4.])
d:/pycharmdaima/star-transformer/ceshi.py:8: UserWarning: Implicit dimension choice for softmax has been deprecated. Change
the call to include dim=X as an argument.
b = F.softmax(a)
tensor([0.0000, 0.0000, 0.2689, 0.7311])

容易報(bào)錯(cuò):

Expected object of scalar type Byte but got scalar type Long for argument #2 'mask'

原因,

mask = torch.LongTensor()

解決方法:

mask = torch.ByteTensor()

在mask值為1的位置處用value填充。mask的元素個(gè)數(shù)需和本tensor相同,但尺寸可以不同

以上這篇pytorch masked_fill報(bào)錯(cuò)的解決就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論