首页 > 解决方案 > 来自 pytorch 的“torch.relu_(input) 未知参数类型”

问题描述

我正在尝试在 GPU 上的 Google Colab 中运行此3D 姿势估计存储库,但是在完成所有步骤并放入我自己的左/右 cam vid 之后,我在 Colab 中收到此错误:

infering thread started
1 1
: cannot connect to X server 
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/content/Stereo-3D-Pose-Estimation/poseinferscheduler.py", line 59, in infer_pose_loop
    l_pose_t = infer_fast(self.net, l_img, height, self.stride, self.upsample_ratio, self.cpu)
  File "/content/Stereo-3D-Pose-Estimation/pose3dmodules.py", line 47, in infer_fast
    stages_output = net(tensor_img)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/content/Stereo-3D-Pose-Estimation/models/with_mobilenet.py", line 115, in forward
    backbone_features = self.model(x)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 139, in forward
    input = module(input)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 139, in forward
    input = module(input)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/activation.py", line 102, in forward
    return F.relu(input, inplace=self.inplace)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py", line 1296, in relu
    result = torch.relu_(input)
RuntimeError: unknown parameter type

我对为什么看到它有点困惑,我已经安装了所有必要的先决条件;也无法解释它的含义。

标签: python-3.xpytorchgoogle-colaboratorypose-estimation

解决方案


由于回溯发生在 pytorch 库中,我在 pytorch github 上检查了那里的代码。

错误的意思是你在 torch.relu_ 中调用了一个就地激活函数来调用一些名为 input 的对象。但是,正在发生的事情是,torch 后端无法识别输入类型,这就是为什么它是运行时错误。

因此,我建议打印出输入并运行

type(input)

找出对象输入代表什么以及该变量是什么。作为进一步的参考,这是 Pytorch 在后端运行的特定脚本,导致它抛出未知参数类型错误。乍一看,它似乎是一个 switch 语句,用于确认一个值是否属于类型列表。如果它不在类型列表中,那么它将运行抛出未知参数类型错误的默认块。

https://github.com/pytorch/pytorch/blob/aacc722aeca3de1aedd35adb41e6f8149bd656cd/torch/csrc/utils/python_arg_parser.cpp#L518-L541

编辑:

如果 type(input) 返回一个 torch.tensor,那么这可能是您使用的 python 版本的问题。我知道你说你有先决条件,但我认为最好仔细检查你是否有 python 3.6,也许但不太优选 python 3.5 或 3.7。这些是与您刚刚发送给我的 repo 一起使用的 python 版本。

您可以通过在其中一个单元格上键入来在您的协作中找到 python 版本 !python --version。确保它返回您正在运行的软件支持的正确版本。这个错误可能是因为 python 本身在其后端表达了这个错误,而不是 torch。

我发现这个 stackoverflow 很有用,因为它显示了一些代码如何无法识别 python 中的内置类型字典:“TypeError: Unknown parameter type: <class 'dict_values'>” 解决方案是检查 python 版本。

萨尔塔克


推荐阅读