相关疑难解决方法(0)

pytorch如何从张量中删除cuda()

我有TypeError: expected torch.LongTensor (got torch.cuda.FloatTensor).

我如何转换torch.cuda.FloatTensortorch.LongTensor

  Traceback (most recent call last):
  File "train_v2.py", line 110, in <module>
    main()
  File "train_v2.py", line 81, in main
    model.update(batch)
  File "/home/Desktop/squad_vteam/src/model.py", line 131, in update
    loss_adv = self.adversarial_loss(batch, loss, self.network.lexicon_encoder.embedding.weight, y)
  File "/home/Desktop/squad_vteam/src/model.py", line 94, in adversarial_loss
    adv_embedding = torch.LongTensor(adv_embedding)
TypeError: expected torch.LongTensor (got torch.cuda.FloatTensor)
Run Code Online (Sandbox Code Playgroud)

python type-conversion pytorch tensor

7
推荐指数
1
解决办法
3024
查看次数

标签 统计

python ×1

pytorch ×1

tensor ×1

type-conversion ×1