解决neural-renderer-pytorch编译安装问题

解决neural-renderer-pytorch编译安装问题

  • 问题概述
  • 错误列表如下
  • 解决方案
    • step 1
    • step 2
    • step 3
  • 已经修改好的源码

问题概述

由于neural-renderer-pytorch这个python资源库本身的编写问题,导致和高版本的pytorch不兼容,我使用的是 pytorch=1.8.1

错误列表如下

ERROR: Command errored out with exit status 1:
   command: /home/majunfu/anaconda3/envs/spin/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-r1_gkzyn/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-r1_gkzyn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-m2pz9umc
       cwd: /tmp/pip-req-build-r1_gkzyn/
  Complete output (156 lines):
  running bdist_wheel
  /home/majunfu/anaconda3/envs/spin/lib/python3.6/site-packages/torch/utils/cpp_extension.py:369: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
    warnings.warn(msg.format('we could not find ninja.'))
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/get_points_from_angles.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/mesh.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/look_at.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/renderer.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/load_obj.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/projection.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/vertices_to_faces.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/look.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/save_obj.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/perspective.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/lighting.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/__init__.py -> build/lib.linux-x86_64-3.6/neural_renderer
  copying neural_renderer/rasterize.py -> build/lib.linux-x86_64-3.6/neural_renderer
  creating build/lib.linux-x86_64-3.6/neural_renderer/cuda
  copying neural_renderer/cuda/__init__.py -> build/lib.linux-x86_64-3.6/neural_renderer/cuda
  running build_ext
  building 'neural_renderer.cuda.load_textures' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/neural_renderer
  creating build/temp.linux-x86_64-3.6/neural_renderer/cuda
  gcc -pthread -B /home/majunfu/anaconda3/envs/spin/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/majunfu/anaconda3/envs/spin/lib/python3.6/site-packages/torch/include -I/home/majunfu/anaconda3/envs/spin/lib/python3.6/site-packages/torch/include/torch/csrc/api/include -I/home/majunfu/anaconda3/envs/spin/lib/python3.6/site-packages/torch/include/TH -I/home/majunfu/anaconda3/envs/spin/lib/python3.6/site-packages/torch/include/THC -I/usr/local/cuda-11.0/include -I/home/majunfu/anaconda3/envs/spin/include/python3.6m -c neural_renderer/cuda/load_textures_cuda.cpp -o build/temp.linux-x86_64-3.6/neural_renderer/cuda/load_textures_cuda.o -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE="_gcc" -DPYBIND11_STDLIB="_libstdcpp" -DPYBIND11_BUILD_ABI="_cxxabi1011" -DTORCH_EXTENSION_NAME=load_textures -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14
......................................................................
省略................................................................
......................................................................
       DeprecatedTypeProperties & type() const {
                                  ^~~~
    neural_renderer/cuda/load_textures_cuda.cpp:15:23: error: ‘AT_CHECK’ was not declared in this scope
     #define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
                           ^
    neural_renderer/cuda/load_textures_cuda.cpp:15:23: note: in definition of macro ‘CHECK_CUDA’
     #define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
                           ^~~~~~~~
    neural_renderer/cuda/load_textures_cuda.cpp:28:5: note: in expansion of macro ‘CHECK_INPUT’
         CHECK_INPUT(image);
         ^
    neural_renderer/cuda/load_textures_cuda.cpp:15:23: note: suggested alternative: ‘DCHECK’
     #define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
                           ^
    neural_renderer/cuda/load_textures_cuda.cpp:15:23: note: in definition of macro ‘CHECK_CUDA’
     #define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
                           ^~~~~~~~
    neural_renderer/cuda/load_textures_cuda.cpp:28:5: note: in expansion of macro ‘CHECK_INPUT’
         CHECK_INPUT(image);
         ^
    neural_renderer/cuda/load_textures_cuda.cpp:15:39: warning: ‘at::DeprecatedTypeProperties& at::Tensor::type() const’ is deprecated: Tensor.type() is deprecated. Instead use Tensor.options(), which in many cases (e.g. in a constructor) is a drop-in replacement. If you were using data from type(), that is now available from Tensor itself, so instead of tensor.type().scalar_type(), use tensor.scalar_type() instead and instead of tensor.type().backend() use tensor.device(). [-Wdeprecated-declarations]
     #define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
                                           ^
    neural_renderer/cuda/load_textures_cuda.cpp:17:24: note: in expansion of macro ‘CHECK_CUDA’
     #define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
                            ^~~~~~~~~~
    neural_renderer/cuda/load_textures_cuda.cpp:29:5: note: in expansion of macro ‘CHECK_INPUT’
         CHECK_INPUT(faces);
         ^

解决方案

step 1

下载源码:https://github.com/daniilidis-group/neural_renderer

step 2

修改源码中以下文件:

  1. neural_renderer/cuda/create_texture_image_cuda.cpp
  2. neural_renderer/cuda/load_textures_cuda.cpp
  3. neural_renderer/cuda/rasterize_cuda.cpp

修改内容:将三个文件中所有的 AT_CHECK 替换为 TORCH_CHECK

step 3

进入到 neural_renderer-master 文件夹下,执行 python setup.py install

已经修改好的源码

链接:https://download.csdn.net/download/u011058765/18843724

你可能感兴趣的:(日常BUG,neural_renderer,renderer_torch,renderer_pytor)