当前位置:网站首页>【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
边栏推荐
- 2310. 个位数字为 K 的整数之和
- How many checks does kubedm series-01-preflight have
- What is a firewall? Explanation of basic knowledge of firewall
- Adaboost使用
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- 一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
- Multiple linear regression (gradient descent method)
- Halcon: check of blob analysis_ Blister capsule detection
- Multiple linear regression (sklearn method)
- 什么是防火墙?防火墙基础知识讲解
猜你喜欢
![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]
![Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]](/img/7d/e7370e757c18b3dbb47e633703c346.jpg)
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]

Blogger article navigation (classified, real-time update, permanent top)
![[code practice] [stereo matching series] Classic ad census: (5) scan line optimization](/img/54/cb1373fbe7b21c5383580e8b638a2c.jpg)
[code practice] [stereo matching series] Classic ad census: (5) scan line optimization
![[Niuke brush questions day4] jz55 depth of binary tree](/img/f7/ca8ad43b8d9bf13df949b2f00f6d6c.png)
[Niuke brush questions day4] jz55 depth of binary tree

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

Use and programming method of ros-8 parameters

Understanding rotation matrix R from the perspective of base transformation

Halcon blob analysis (ball.hdev)

Programming implementation of ROS learning 5-client node
随机推荐
golang 基础 ——map、数组、切片 存放不同类型的数据
深度学习模型与湿实验的结合,有望用于代谢通量分析
Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
Nodemon installation and use
ROS learning 1- create workspaces and function packs
notepad++
C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
Editor use of VI and VIM
Mengxin summary of LCs (longest identical subsequence) topics
Count of C # LINQ source code analysis
Array, date, string object method
2309. 兼具大小写的最好英文字母
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
Meta标签详解
scipy.misc.imread()
L'information et l'entropie, tout ce que vous voulez savoir est ici.
Golang foundation -- map, array and slice store different types of data
Halcon wood texture recognition
Programming implementation of ROS learning 5-client node