exp_vml_cpu not implemented for 'Long'

 

exp_vml_cpu not implemented for 'Long'

 

from torch import nn

if __name__ == '__main__':

 
    import torch

    bce_loss = nn.BCEWithLogitsLoss(reduction='sum')
    labels=torch.Tensor([1,2])
    input_tensor = torch.tensor([[1, 2, 3],
                                 [4, 5,6]])

    index_num = torch.arange(0, labels.size(0))
    value, index = torch.max(input_tensor, dim=1)  # 按列SoftMax,列和爲1

    # _, index = torch.topk(thetas, 1, dim=1, largest=True, sorted=True, out=None)

    select_pos = index != labels.long()

    pos_label = torch.ones((input_tensor[index_num, labels.long()][select_pos]).size(0))

    data=input_tensor[index_num, labels.long()][select_pos]
    pos_loss =  bce_loss(data, pos_label)

    print(pos_loss)

data需要是float32類型的,

pos_loss =  bce_loss(data.float(), pos_label)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章