torch 多維topk

 

flatten和view(-1) 是按行展開,一行一行的拼接

    import torch

 
    anch_ious = torch.Tensor([[1, 2, 3,4], [7,8,9,3]])
    # anch_ious = torch.Tensor([[1, 2, 3,4], [4, 5, 6,7]]).view(-1)


    neg_count=3
    top_data,index= torch.topk(anch_ious, neg_count, dim=1, largest=True, sorted=True, out=None)

    # print(anch_ious[index])

    index_num = torch.arange(0, anch_ious.size(0)).repeat(3,1)
    index_num=torch.flatten(index_num.t())
    print(index_num)

    # indexs = index[:, 1:]
    index = torch.flatten(index)

    print(anch_ious[index_num,index])

 

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