【问题标题】:undefined symbol: THPVariableClaload_textures.cpython-37m-x86_64-linux-gnu.so: undefined symbol: THPVariableClass未定义符号:THPVariableClaload_textures.cpython-37m-x86_64-linux-gnu.so:未定义符号:THPVariableClass
【发布时间】:2020-09-23 23:32:25
【问题描述】:

你知道我该如何解决这个问题吗?我正在尝试使用https://github.com/benjiebob/SMALViewer/issues/3 repo,但是在neural_renderer 端口上出现错误:

$ python smal_viewer.py 
Traceback (most recent call last):
  File "smal_viewer.py", line 2, in <module>
    import pyqt_viewer
  File "/home/mona/research/3danimals/SMALViewer/pyqt_viewer.py", line 13, in <module>
    from smal.smal3d_renderer import SMAL3DRenderer
  File "/home/mona/research/3danimals/SMALViewer/smal/smal3d_renderer.py", line 6, in <module>
    import neural_renderer as nr
  File "/home/mona/anaconda3/lib/python3.7/site-packages/neural_renderer/__init__.py", line 3, in <module>
    from .load_obj import load_obj
  File "/home/mona/anaconda3/lib/python3.7/site-packages/neural_renderer/load_obj.py", line 8, in <module>
    import neural_renderer.cuda.load_textures as load_textures_cuda
ImportError: /home/mona/anaconda3/lib/python3.7/site-packages/neural_renderer/cuda/load_textures.cpython-37m-x86_64-linux-gnu.so: undefined symbol: THPVariableClass

这里有一些细节:

$ python
Python 3.7.6 (default, Jan  8 2020, 19:59:22) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.6.0'
>>> torch.version.cuda
'10.1'
>>> torch.cuda.is_available()
True


$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal

这里是神经渲染器 git repo:https://github.com/daniilidis-group/neural_renderer

我使用pip install neural_renderer_pytorch安装了神经渲染器

【问题讨论】:

    标签: python pytorch shared-libraries cpython


    【解决方案1】:

    看起来neural_renderer_pytorch 不是您自己构建的,而是使用了轮子。但是,此轮子是使用较旧的pytorch 版本构建的,不适用于您机器上当前的pytorch 版本。

    使用当前的 pytorch 版本,即从源代码构建 neural_renderer(在卸载 neural_renderer 之后),即

    $ pip uninstall neural-renderer-pytorch
    
    $ pip install https://github.com/daniilidis-group/neural_renderer/zipball/master
    

    它应该可以工作。


    在 pytorch 1.5 之前,它使用了一种在 Linux 上构建扩展的脆弱方式:尽管依赖于 torch,扩展并没有明确链接到 libtorch.so。提供缺少的符号只是因为import torchRTLD_GLOBAL 加载了libtorch.so,从而使其符号全局可见/可访问-这就是为什么在加载这些扩展之前(例如neural_renderer_pytorchhere)一个有导入torch

    可以在导入 torch 之前强制执行旧的行为设置 RTLD_GLOBAL,因为这是第一次发生:

    import sys; import ctypes;
    sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
    import torch # now all symbols of torch
                 # have global visibility and can be used in 
                 # other extensions
    

    但是,使用RTLD_GLOBAL 非常危险,因为它可能会插入不相关的符号并导致细微的错误甚至崩溃。

    因此,由于 1.5 pytorch 不再使用 RTLD_GLOBAL,而是明确链接到 libpytorch.so(请参阅此 commit),并且使用旧 pytorch 版本构建的扩展将不起作用。

    【讨论】:

    • 不幸的是,它不起作用pastebin.com/raw/Gfh4qFHE
    • @MonaJalal README (github.com/daniilidis-group/neural_renderer/blob/master/…) 说对于较新的版本,应该尝试使用 at_assert_fix-branch,即pip install https://github.com/daniilidis-group/neural_renderer/zipball/at_assert_fix。我无法检查这个,因为我手头没有合适的机器。这个项目近 2 年没有活跃,所以如果另一个分支不起作用,你的选择是使用变通方法或使用 pytorch 1.4。
    【解决方案2】:

    我能够通过首先找到所有 AT_CHECK 并将它们转换为 AT_ASSERT 来解决此问题。检查at_assert_fix 分支并没有为我解决问题。我正在使用 PyTorch 1.6 和 CUDA 10.1

    https://github.com/daniilidis-group/neural_renderer/search?q=AT_CHECK

    (base) mona@mona:~/neural_renderer/neural_renderer/cuda$ vi create_texture_image_cuda.cpp 
    (base) mona@mona:~/neural_renderer/neural_renderer/cuda$ vi load_textures_cuda.cpp 
    (base) mona@mona:~/neural_renderer/neural_renderer/cuda$ vi rasterize_cuda.cpp 
    
    (base) mona@mona:~/neural_renderer$ pip install .
    Processing /home/mona/neural_renderer
    Building wheels for collected packages: neural-renderer-pytorch
      Building wheel for neural-renderer-pytorch (setup.py) ... done
      Created wheel for neural-renderer-pytorch: filename=neural_renderer_pytorch-1.1.3-cp37-cp37m-linux_x86_64.whl size=6215781 sha256=fbd9e8ef7340fa71b9fcd69da8ee06a1079ebbe5b4c2c3ce92e8124bc8cea7c5
      Stored in directory: /tmp/pip-ephem-wheel-cache-tddilaof/wheels/c6/9b/9b/d2cda4f9ac2127278c21ea5c5e23c3354fe0e63365b7af7842
    Successfully built neural-renderer-pytorch
    Installing collected packages: neural-renderer-pytorch
    Successfully installed neural-renderer-pytorch-1.1.3
    (base) mona@mona:~/neural_renderer$ python examples/example1.py 
    Drawing: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 90/90 [00:04<00:00, 19.37it/s]
    
    

    https://github.com/daniilidis-group/neural_renderer/issues/94

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-17
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 2012-07-20
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多