Pytorch 类型错误:can';t将str分配给火炬。LongTensor pytoch
我试图将字符串列表转换为张量,但我得到了这个错误Pytorch 类型错误:can';t将str分配给火炬。LongTensor pytoch,pytorch,torch,Pytorch,Torch,我试图将字符串列表转换为张量,但我得到了这个错误 lengths = [len(cap) for cap in captions] targets = torch.zeros(len(captions), max(lengths)).long() for i, cap in enumerate(captions): end = lengths[i] targets[i, :end] = cap[:end] 可以使用python将字符转换为unic
lengths = [len(cap) for cap in captions]
targets = torch.zeros(len(captions), max(lengths)).long()
for i, cap in enumerate(captions):
end = lengths[i]
targets[i, :end] = cap[:end]
可以使用python将字符转换为unicode:
targets[i, :end] = torch.from_numpy(np.array(list(map(ord, cap[:end])))).to(torch.long)
可能是重复的,但没有解决方案