RuntimeError: bool value of Tensor with more than one value is ambiguous
程序员文章站
2022-05-27 12:46:36
...
Pytorch 跑模型报错。
if labels:
loss = self.loss_fn(out, labels)
return out, loss
else:
return out
if labels 那一行报错。
这一行代码想判断labels是否为空。
因为labels是torch.tensor类型,不能直接转换成bool值。
需要改成:
if labels is not None。
by the way
python的基本类型如list 如 test = []可以通过if test 判断是否为空。
推荐阅读
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
python报错ValueError: The truth value of an array with more than one element is ambiguous. Use a.any()
-
Python报错:The truth value of an array with more than one element is ambiguous
-
Python ValueError: The truth value of an array with more than one element is ambiguous.
-
成功解决Python的ValueError: The truth value of an array with more than one element is ambiguous
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
RuntimeError: bool value of Tensor with more than one value is ambiguous
-
Bool value of Tensor with more than one value is ambiguous
-
[numpy问题]The truth value of an array with more than one element is ambiguous.
-
学习随笔-ValueError: The truth value of an array with more than one element is ambiguous