当前位置:网站首页>【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
边栏推荐
- 浅谈Label Smoothing技术
- Editor use of VI and VIM
- Introduction Guide to stereo vision (1): coordinate system and camera parameters
- [code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
- kubeadm系列-02-kubelet的配置和启动
- Meta tag details
- MPSoC QSPI Flash 升级办法
- Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
- 微信H5公众号获取openid爬坑记
- Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
猜你喜欢
Blogger article navigation (classified, real-time update, permanent top)
Programming implementation of ROS learning 2 publisher node
资源变现小程序添加折扣充值和折扣影票插件
Introduction Guide to stereo vision (1): coordinate system and camera parameters
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
RT-Thread内核快速入门,内核实现与应用开发学习随笔记
Use and programming method of ros-8 parameters
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
Understanding rotation matrix R from the perspective of base transformation
IT冷知识(更新ing~)
随机推荐
容易混淆的基本概念 成员变量 局部变量 全局变量
Multiple linear regression (sklearn method)
np.allclose
迁移学习和域自适应
The combination of deep learning model and wet experiment is expected to be used for metabolic flux analysis
ECMAScript6介绍及环境搭建
Ros-10 roslaunch summary
Oracle advanced (III) detailed explanation of data dictionary
File server migration scheme of a company
Redis实现高性能的全文搜索引擎---RediSearch
Codeforces round 684 (Div. 2) e - green shopping (line segment tree)
kubeadm系列-01-preflight究竟有多少check
js异步错误处理
Jenkins pipeline method (function) definition and call
One dimensional vector transpose point multiplication np dot
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
Array, date, string object method
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
Ros-11 common visualization tools