首页 > 其他 > 详细

pytorch中onehot编码转为普通label标签

时间:2019-06-30 01:16:19      阅读:342      评论:0      收藏:0      [点我收藏+]

label转onehot的很多,但是onehot转label的有点难找,所以就只能自己实现以下,用的topk函数,不知道有没有更好的实现

one_hot = torch.tensor([[0,0,1],[0,1,0],[0,1,0]])
print(one_hot)
label = torch.topk(one_hot, 1)[1].squeeze(1)
print(label)

 

tensor([[0, 0, 1],
[0, 1, 0],
[0, 1, 0]])
tensor([2, 1, 1])

pytorch中onehot编码转为普通label标签

原文:https://www.cnblogs.com/youmuchen/p/11108247.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!