当前位置:网站首页>【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
边栏推荐
- 【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
- Wechat H5 official account to get openid climbing account
- Confusing basic concepts member variables local variables global variables
- scipy.misc.imread()
- 信息與熵,你想知道的都在這裏了
- Redis实现高性能的全文搜索引擎---RediSearch
- Meta tag details
- Codeworks round 681 (Div. 2) supplement
- AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
- Use arm neon operation to improve memory copy speed
猜你喜欢

Introduction Guide to stereo vision (7): stereo matching

L'information et l'entropie, tout ce que vous voulez savoir est ici.
![Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]](/img/d8/39020b1ce174299f60b6f278ae0b91.jpg)
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]

nodejs_ fs. writeFile

Huber Loss

编辑器-vi、vim的使用
![Rebuild my 3D world [open source] [serialization-2]](/img/e6/aad5f432aca619b992753187729dcf.jpg)
Rebuild my 3D world [open source] [serialization-2]

Halcon affine transformations to regions

Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method

混淆矩阵(Confusion Matrix)
随机推荐
File server migration scheme of a company
OpenFeign
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Halcon: check of blob analysis_ Blister capsule detection
Count of C # LINQ source code analysis
Nodejs modularization
notepad++
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
某公司文件服务器迁移方案
Codeforces Round #648 (Div. 2) D. Solve The Maze
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
C [essential skills] use of configurationmanager class (use of file app.config)
Applet (global data sharing)
Kubedm series-00-overview
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
fs. Path module
Multiple linear regression (sklearn method)
TF coordinate transformation of common components of ros-9 ROS