Giter Site home page Giter Site logo

textured-mesh-gen's Introduction

Leveraging 2D Data to Learn Textured 3D Mesh Generation

This repository contains the original implementation of the above CVPR paper (also available on arXiv). It is a structured VAE that learns a distribution of textured 3D shapes from just 2D images, by learning to explain those images in terms of 3D shapes differentiably rendered over a 2D background. It also includes a mesh parameterisation guaranteed to avoid self-intersections, by having faces push each other out of the way when the shape is deformed.

If this code is useful for your research, please cite us!

@inproceedings{henderson20cvpr,
  title={Leveraging {2D} Data to Learn Textured {3D} Mesh Generation},
  author={Paul Henderson and Vagia Tsiminaki and Christoph Lampert},
  booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2020}
}

Prerequisites

  • Clone this repo recursively, with
git clone --recursive https://github.com/pmh47/textured-mesh-gen
  • Create and activate a new conda environment, then run
conda install python=3.6 tensorflow-gpu=1.13.1 numpy scipy opencv ffmpeg tqdm
pip install tensorflow-probability==0.6 trimesh meshzoo
pip install --no-deps git+https://github.com/pmh47/dirt

Pushing Mesh Parameterisation

The LP-based mesh-pushing op is independent of the rest of the code, and can be found in src/mesh_intersections. It must be compiled before use.

Compilation

  • Ensure you have the system packages Boost, GMP, MPFR, GLFW, and CMake (3.14 or newer) installed
  • Install Gurobi (and get a licence for it); we used version 8.1.1. Set the environment variable GUROBI_ROOT to the path containing its include and lib folders, e.g.
export GUROBI_ROOT=~/packages/gurobi811/linux64
  • Activate a conda env with the packages listed under prerequisites
  • Run
cd src/mesh_intersections
mkdir build && cd build
cmake \
    -DLIBIGL_WITH_CGAL=ON \
    -DLIBIGL_WITH_OPENGL=ON \
    -DLIBIGL_WITH_OPENGL_GLFW=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DGUROBI_ROOT=$GUROBI_ROOT
    ..
make -j4
cd ..
  • Test the C++ code: run ./test_app, which should display an icosphere with two deformations applied (press ESC to close each window)
  • Test the python bindings: run PYTHONPATH=.. python test_tf_mesh_pushing.py

Troubleshooting

You might need to make some of the following changes, if the build fails or you experience crashes:

Note that it is normal to see occasional warnings about numerical issues at runtime.

Training

We include the full implementation of the structured VAE model described in the paper, as well as code for preprocessing datasets. If you want to use the mesh-pushing parameterisation, follow the steps above first. However, it is quicker and simpler to begin by training with the dense parameterisation.

Datasets

Before training the model, you need to either download one of our preprocessed datasets, or generate this yourself. Preprocessed datasets are available at the following locations:

Each contains a single folder, which should be unzipped into the preprocessed-data folder in this repo.

If you prefer to preprocess the data yourself, we include scripts extract_*_crops.py for doing so. Note that to preprocess the BrnoCompSpeed data, you will need Detectron installed. You should download the original datasets from the following locations:

  • BrnoCompSpeed -- you need 2016-ITS-BrnoCompSpeed-full.tar from here
  • CUB-200-2011 -- you need the raw dataset and CMR 's cachedir.tar.gz
  • ShapeNet (HSP) -- you need shapenet_data.tar.gz from here
  • ShapeNet (3D-R2N2) -- you need ShapeNetRendering.tar.gz from here

These should be unzipped into the data folder in this repo before running the relevant preprocessing script.

Training

The following commands may be run from the src folder to reproduce (up to stochastic variability and small bug-fixes) the models used in the paper, in setting mask with parameterisation dense. Images will be written to output/images at regular intervals.

  • BrnoCompSpeed: python train.py dataset=bcs
  • CUB-200-2011: python train.py dataset=cub
  • ShapeNet cars (3D-R2N2): python train.py dataset=shapenet synset=02958343
  • ShapeNet chairs (HSP): python train.py dataset=shapenet synset=03001627
  • ShapeNet aeroplanes (HSP): python train.py dataset=shapenet synset=02691156
  • ShapeNet sofas (3D-R2N2): python train.py dataset=shapenet synset=04256520

To use setting no-mask instead, add with-gt-masks=0 to any of the above. To use parameterisation pushing instead, add shape-model=VAE-seq-att-pushing.

textured-mesh-gen's People

Contributors

pmh47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

textured-mesh-gen's Issues

mesh_intersection make error

After successful cmake, I tried to make mesh_intersection.
But an error was happend.
The error is below,

[ 82%] Linking CXX executable ../test_app
CMakeFiles/test_app.dir/mesh_intersections.cpp.o: In function solve_for_offsets_gurobi(Eigen::Matrix<float, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, std::vector<IntersectionVertex, std::allocator<IntersectionVertex> >, boost::no_property, boost::listS> const&, Eigen::Array<float, -1, 1, 0, -1, 1> const&)': mesh_intersections.cpp:(.text+0x4a19): undefined reference to GRBModel::addVar(double, double, double, char, std::string)'
mesh_intersections.cpp:(.text+0x4b2c): undefined reference to GRBModel::addConstr(GRBTempConstr const&, std::string)' mesh_intersections.cpp:(.text+0x559c): undefined reference to GRBModel::addConstr(GRBTempConstr const&, std::string)'
collect2: error: ld returned 1 exit status
CMakeFiles/test_app.dir/build.make:153: recipe for target '../test_app' failed
make[2]: *** [../test_app] Error 1
CMakeFiles/Makefile2:185: recipe for target 'CMakeFiles/test_app.dir/all' failed
make[1]: *** [CMakeFiles/test_app.dir/all] Error 2
Makefile:114: recipe for target 'all' failed
make: *** [all] Error 2

My environment is
Ubuntu 16.04 LTS
gcc 7.1.0
cmake 3.17.1
Gurobi 8.1.1
tensorflow 2.2.0

Assertion failed when train with parameterisation pushing

I try to train cub dataset with parameterisation pushing.
But Assertion error occurred while iterations. What is the cause?

My environment is
Ubunut 16.04LTS
python 3.6.10
tensorflow 1.13.1
Gurobi 8.1.1

Error Text

Solved in 95 iterations and 0.01 seconds
Optimal objective 1.147218512e+01
python: textured-mesh-gen/src/mesh_intersections/mesh_intersections.cpp:504: get_segment_vertex_indices(const Vector3i&, const Vector3i&, const IntersectionVertex&)::<lambda(const std::array<float, 3>&, const Vector3i&)>: Assertion `barycentric[1] > edge_epsilon && barycentric[2] > edge_epsilon' failed.

Error when install dirt

Hi, I try the command: pip install --no-deps git+https://github.com/pmh47/dirt and I found an error:

ERROR: Command errored out with exit status 1:
command: /home/xuanchi/anaconda3/envs/mesh/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-wsw4xc3l/setup.py'"'"'; file='"'"'/tmp/pip-req-build-wsw4xc3l/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-ja4o_lxt
cwd: /tmp/pip-req-build-wsw4xc3l/
Complete output (49 lines):
running bdist_wheel
running build
-- The CXX compiler identification is GNU 7.5.0
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenGL (missing: EGL)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.10/Modules/FindOpenGL.cmake:369 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!
See also "/tmp/pip-req-build-wsw4xc3l/build/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 50, in
'Programming Language :: Python :: 3.7',
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/site-packages/setuptools/init.py", line 161, in setup
return distutils.core.setup(**attrs)
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 223, in run
self.run_command('build')
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 24, in run
build_csrc()
File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 18, in build_csrc
subprocess.check_call(['cmake', os.path.join(base_path, 'csrc')], cwd=build_path)
File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-wsw4xc3l/csrc']' returned non-zero exit status 1.

ERROR: Failed building wheel for dirt
Running setup.py clean for dirt
Failed to build dirt
Installing collected packages: dirt
Running setup.py install for dirt ... error
ERROR: Command errored out with exit status 1:
command: /home/xuanchi/anaconda3/envs/mesh/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-wsw4xc3l/setup.py'"'"'; file='"'"'/tmp/pip-req-build-wsw4xc3l/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-xb0mrnrg/install-record.txt --single-version-externally-managed --compile --install-headers /home/xuanchi/anaconda3/envs/mesh/include/python3.6m/dirt
cwd: /tmp/pip-req-build-wsw4xc3l/
Complete output (39 lines):
running install
running build
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenGL (missing: EGL)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.10/Modules/FindOpenGL.cmake:369 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!
See also "/tmp/pip-req-build-wsw4xc3l/build/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 50, in <module>
    'Programming Language :: Python :: 3.7',
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/site-packages/setuptools/__init__.py", line 161, in setup
    return distutils.core.setup(**attrs)
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
    return orig.install.run(self)
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/command/install.py", line 545, in run
    self.run_command('build')
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 24, in run
    build_csrc()
  File "/tmp/pip-req-build-wsw4xc3l/setup.py", line 18, in build_csrc
    subprocess.check_call(['cmake', os.path.join(base_path, 'csrc')], cwd=build_path)
  File "/home/xuanchi/anaconda3/envs/mesh/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-wsw4xc3l/csrc']' returned non-zero exit status 1.
----------------------------------------

ERROR: Command errored out with exit status 1: /home/xuanchi/anaconda3/envs/mesh/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-wsw4xc3l/setup.py'"'"'; file='"'"'/tmp/pip-req-build-wsw4xc3l/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-xb0mrnrg/install-record.txt --single-version-externally-managed --compile --install-headers /home/xuanchi/anaconda3/envs/mesh/include/python3.6m/dirt Check the logs for full command output.

Can you help me figure out the error? Thank you!

Question about pose

Hi, thanks for your work.

I find you use ground truth rotation during training, however, it seems that you did not mention this in the paper and supplement. Is is the case?

mesh_intersections Build CMake Error

I'm trying to build mesh_intersections.
But when I execute cmake command with reference to README.md, an error occured.

"cmake -DLIBIGL_WITH_CGAL=ON -DLIBIGL_WITH_CGAL=ON -DLIBIGL_WITH_OPENGL_GLFW=ON DCMAKE_BUILD_TYPE=Release -DGUROBI_ROOT=$GUROBI_ROOT -DMPFR_INCLUDE_DIR=$MPFR_INCLUDE_DIR -DMPFR_LIBRARIES=$MPFR_LIBRARIES .."
(I added MPFR_INCLUDE_DIR and MPFR_LIBRARIES because another error occred )

The error is below

CMake Error at CMakeLists.txt:26 (add_executable):
Target "test_app" links to target "igl::opengl_glfw" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

CMake Error at CMakeLists.txt:25 (add_library):
Target "push_ops" links to target "igl::opengl_glfw" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

What should I do?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.