当前位置:网站首页>【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
边栏推荐
- MPSoC QSPI flash upgrade method
- Ros-11 common visualization tools
- Halcon: check of blob analysis_ Blister capsule detection
- uni-app 实现全局变量
- 什么是防火墙?防火墙基础知识讲解
- C [essential skills] use of configurationmanager class (use of file app.config)
- kubeadm系列-00-overview
- C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
- scipy.misc.imread()
- nodejs_ fs. writeFile
猜你喜欢
IT冷知识(更新ing~)
L'information et l'entropie, tout ce que vous voulez savoir est ici.
Halcon Chinese character recognition
Blogger article navigation (classified, real-time update, permanent top)
我从技术到产品经理的几点体会
Codeworks round 639 (Div. 2) cute new problem solution
Rebuild my 3D world [open source] [serialization-2]
Confusion matrix
Programming implementation of ROS learning 5-client node
Summary of "reversal" problem in challenge Programming Competition
随机推荐
MPSoC QSPI flash upgrade method
迁移学习和域自适应
信息与熵,你想知道的都在这里了
MPSoC QSPI Flash 升级办法
Halcon affine transformations to regions
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
520 diamond Championship 7-4 7-7 solution
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
浅谈Label Smoothing技术
Mengxin summary of LCs (longest identical subsequence) topics
2310. 个位数字为 K 的整数之和
容易混淆的基本概念 成员变量 局部变量 全局变量
Codeworks round 681 (Div. 2) supplement
TF coordinate transformation of common components of ros-9 ROS
Rebuild my 3D world [open source] [serialization-1]
Halcon shape_ trans
js异步错误处理
It cold knowledge (updating ing~)
C [essential skills] use of configurationmanager class (use of file app.config)