当前位置:网站首页>【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
2022-07-05 09:06:00 【aelum】
Case 1
Will contain Two or more The Boolean tensor of is used in if Judging conditions :
a = torch.tensor([True, False])
if a:
pass
One of the possible reasons for this error is to judge a Not for None, At this time, it should be changed to the following statement
if a is not None:
It should be noted that , If a Contains only one Boolean value , Then the judgment will not be wrong :
a = torch.tensor([True])
if a:
print(1)
# 1
Case 2
When using cross entropy loss Not instantiated first :
inputs = torch.randn(6, 4)
target = torch.randint(4, (6, ))
loss = nn.CrossEntropyLoss(inputs, target)
The loss should be calculated after instantiation :
criterion = nn.CrossEntropyLoss()
loss = criterion(inputs, target)
Case 3
Yes, it contains Two or more The Boolean tensor of performs or、and、not This kind of operation :
a = torch.tensor([True, False])
b = torch.tensor([False, True])
""" The following three operations will report errors """
print(a or b)
print(a and b)
print(not a)
It should be noted that , If a and b All contain only one Boolean value , There will be no mistakes :
a = torch.tensor([True])
b = torch.tensor([False])
print(a or b)
# tensor([True])
print(a and b)
# tensor([False])
print(not a)
# False
边栏推荐
- How many checks does kubedm series-01-preflight have
- Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
- golang 基础 ——map、数组、切片 存放不同类型的数据
- Applet (subcontracting)
- [daiy4] copy of JZ35 complex linked list
- Transfer learning and domain adaptation
- Ecmascript6 introduction and environment construction
- c#比较两张图像的差异
- Attention is all you need
- Illustrated network: what is gateway load balancing protocol GLBP?
猜你喜欢

Programming implementation of ROS learning 2 publisher node

Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
![C [essential skills] use of configurationmanager class (use of file app.config)](/img/8b/e56f87c2d0fbbb1251ec01b99204a1.png)
C [essential skills] use of configurationmanager class (use of file app.config)

Huber Loss

Nodejs modularization

牛顿迭代法(解非线性方程)

Use and programming method of ros-8 parameters

生成对抗网络

Confusion matrix

The combination of deep learning model and wet experiment is expected to be used for metabolic flux analysis
随机推荐
Codeworks round 638 (Div. 2) cute new problem solution
Halcon affine transformations to regions
2011-11-21 training record personal training (III)
Applet (global data sharing)
12、动态链接库,dll
编辑器-vi、vim的使用
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time
Use and programming method of ros-8 parameters
Solutions of ordinary differential equations (2) examples
Confusing basic concepts member variables local variables global variables
Summary of "reversal" problem in challenge Programming Competition
Generate confrontation network
混淆矩阵(Confusion Matrix)
Configuration and startup of kubedm series-02-kubelet
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Ros-10 roslaunch summary
notepad++
[daiy4] jz32 print binary tree from top to bottom