Deep learning PyTorch中nn.BCEWithLogitsLoss()中1的张量-cuda内存不足?

Deep learning PyTorch中nn.BCEWithLogitsLoss()中1的张量-cuda内存不足?,deep-learning,neural-network,pytorch,tensorflow2.0,tensor,Deep Learning,Neural Network,Pytorch,Tensorflow2.0,Tensor,为了实现PyTorch中的自定义丢失函数,我使用nn.BCEWithLogitsLoss()。 第一个参数是我从模型中得到的概率(当然,经过一些数学运算),第二个参数是1(100%) 我的代码如下所示: criterion = nn.BCEWithLogitsLoss() loss =criterion(my_probability, torch.tensor(1.).cuda()) 本部分: torch.tensor(1.).cuda()导致cuda内存不足。 我的疑问是: 是否有更好的方

为了实现PyTorch中的自定义丢失函数,我使用nn.BCEWithLogitsLoss()。 第一个参数是我从模型中得到的概率(当然,经过一些数学运算),第二个参数是1(100%)

我的代码如下所示:

criterion = nn.BCEWithLogitsLoss()
loss =criterion(my_probability, torch.tensor(1.).cuda())

本部分:
torch.tensor(1.).cuda()
导致cuda内存不足。 我的疑问是:

  • 是否有更好的方法(其他损失函数?)将我的概率与100%目标值进行比较
  • 有没有更好的方法在cuda上声明和使用张量1
  • 谢谢大家!