当前位置:网站首页>【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
边栏推荐
- .NET服务治理之限流中间件-FireflySoft.RateLimit
- np. allclose
- Blue Bridge Cup provincial match simulation question 9 (MST)
- Count of C # LINQ source code analysis
- Generate confrontation network
- ROS learning 1- create workspaces and function packs
- fs. Path module
- Codeworks round 638 (Div. 2) cute new problem solution
- 图解网络:什么是网关负载均衡协议GLBP?
- Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
猜你喜欢
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
RT thread kernel quick start, kernel implementation and application development learning with notes
Introduction Guide to stereo vision (5): dual camera calibration [no more collection, I charge ~]
Nodejs modularization
Wechat H5 official account to get openid climbing account
Halcon blob analysis (ball.hdev)
Programming implementation of ROS learning 2 publisher node
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
IT冷知识(更新ing~)
微信H5公众号获取openid爬坑记
随机推荐
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
MPSoC QSPI flash upgrade method
Return of missing persons
nodejs_ fs. writeFile
It cold knowledge (updating ing~)
Ecmascript6 introduction and environment construction
Huber Loss
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
资源变现小程序添加折扣充值和折扣影票插件
fs. Path module
Pearson correlation coefficient
Nodejs modularization
多元线性回归(sklearn法)
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Halcon color recognition_ fuses. hdev:classify fuses by color
Huber Loss
Golang foundation -- map, array and slice store different types of data
Codeworks round 681 (Div. 2) supplement
np. allclose
kubeadm系列-00-overview