PRBonn / make_it_dense

Make it Dense: Self-Supervised Geometric Scan Completion of Sparse 3D LiDAR Scans in Large Outdoor Environments
https://www.ipb.uni-bonn.de/wp-content/papercite-data/pdf/vizzo2022ral-iros.pdf
132 stars 11 forks source link

AttributeError: 'VDBVolume' object has no attribute 'tsdf' #4

Closed amwfarid closed 1 year ago

amwfarid commented 1 year ago

I managed to install the dependencies and tried to run the test on the 00 sequence, but I get the following error.

./apps/test_scan.py --cuda  data/kitti-odometry/dataset/sequences/00/velodyne/000000.bin

INFO - 2022-10-26 11:36:39,987 - instantiator - Created a temporary directory at /tmp/tmpme_5u8tm
INFO - 2022-10-26 11:36:39,987 - instantiator - Writing /tmp/tmpme_5u8tm/_remote_module_non_scriptable.py
Traceback (most recent call last):

  File "./apps/test_scan.py", line 54, in <module>
    typer.run(test)

  File "./apps/test_scan.py", line 36, in test
    out_grid, in_grid = run_completion_pipeline(

  File "/home/farid/projects/make_it_dense/venv/lib/python3.8/site-packages/make_it_dense/evaluation/scan_complete.py", line 58, in run_completion_pipeline
    tsdf_volume, coords_xyz = run_tsdf(scan, voxel_size, voxel_size * voxel_trunc)

  File "/home/farid/projects/make_it_dense/venv/lib/python3.8/site-packages/make_it_dense/evaluation/scan_complete.py", line 18, in run_tsdf
    target_coords_ijk_a, _ = LeafNodeGrid(base_volume.tsdf).numpy()

AttributeError: 'VDBVolume' object has no attribute 'tsdf'

It seems to be related to the vdbfusion library. I installed it from source as instructed, but I seem to be missing something.

Looking forward to your help!

nachovizzo commented 1 year ago

Hello, sorry for the late reply!

This is because vdbfusion was not compiled with pyopenvdb support enabled. The way I check this on the build system is qutie dirty, and couldn't find a better solution: https://github.com/PRBonn/vdbfusion/blob/8d01832419050aed1105e666040c4e5d3a14c96c/src/vdbfusion/pybind/CMakeLists.txt#L5

You can debug this problem yourself by firing up a python shell and try to import the library import pyopenvdb. Is this fails, then the rest fails. Probably something went wrong while building OpenVDB from source.

amwfarid commented 1 year ago

@nachovizzo Thank you very much for the response and help!

I managed to get rid of the attribute error (but then got another error with FloatGrid). The issue you linked to gave some good hints. Here's what I did:

I made sure I uninstalled the vdbfusion on my venv pip uninstall vdbfusion

I reinstalled OpenVDB in the way prescribed here (conda approach):

git clone --depth 1 https://github.com/nachovizzo/openvdb.git -b nacho/vdbfusion \
    && cd openvdb \
    && mkdir build && cd build \
    && cmake \
    -DOPENVDB_BUILD_PYTHON_MODULE=ON \
    -DUSE_NUMPY=ON \
    -DPYOPENVDB_INSTALL_DIRECTORY="/home/farid/projects/make_it_dense/venv/lib/python3.8/dist-packages" \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
    -DUSE_ZLIB=OFF \
    ..\
    && make -j$(nproc) all install \
    && cd ../.. \
    && rm -rf openvdb

However importantly, I set DPYOPENVDB_INSTALL_DIRECTORY to point to my venv python install directory instead.

Afterwards, I went to the root of vdbfusion and did make install

The attribute error went away, but now I get this:

./apps/test_scan.py --cuda  data/kitti-odometry/dataset/sequences/00/velodyne/000000.bin
INFO - 2022-11-04 16:40:02,816 - instantiator - Created a temporary directory at /tmp/tmpcyqo1ika
INFO - 2022-11-04 16:40:02,816 - instantiator - Writing /tmp/tmpcyqo1ika/_remote_module_non_scriptable.py
Traceback (most recent call last):

  File "./apps/test_scan.py", line 54, in <module>
    typer.run(test)

  File "./apps/test_scan.py", line 36, in test
    out_grid, in_grid = run_completion_pipeline(

  File "/home/farid/projects/make_it_dense/venv/lib/python3.8/site-packages/make_it_dense/evaluation/scan_complete.py", line 58, in run_completion_pipeline
    tsdf_volume, coords_xyz = run_tsdf(scan, voxel_size, voxel_size * voxel_trunc)

  File "/home/farid/projects/make_it_dense/venv/lib/python3.8/site-packages/make_it_dense/evaluation/scan_complete.py", line 18, in run_tsdf
    target_coords_ijk_a, _ = LeafNodeGrid(base_volume.tsdf).numpy()

  File "/home/farid/projects/make_it_dense/venv/lib/python3.8/site-packages/vdb_to_numpy/grid_wrappers/leaf_node_grid.py", line 22, in __init__
    self.leaf_nodes = vdb_pybind.extract_leaf_nodes(self.vdb_grid)

ValueError: GridType: <class 'pyopenvdb.FloatGrid'> not supported

I recognize that we are using your fork of OpenVDB because of a wrong value issue related to FloatGrid, but this one says outright that the class is not supported. might there be a version mismatch somewhere?

nachovizzo commented 1 year ago

Almost there, could you paste the output of this command: python3 -c "import pyopenvdb; print(dir(pyopenvdb))" | tr ',' '\n' | grep Grid. In my case the output is:

'BoolGrid'
 'FloatGrid'
 'GridClass'
 'GridTypes'
 'Vec3SGrid'
 'readAllGridMetadata'
 'readGridMetadata'

The reason behind all this madness is to provide a way to pass a Python object back and forth without having to re-convert or to even think about the C++ native type. The code for this is:

https://github.com/PRBonn/vdbfusion/blob/a0ca08e46c8082e11b757689b3384818b646e4fc/src/vdbfusion/pybind/pyopenvdb.h#L28

template <>
struct type_caster<openvdb::FloatGrid::Ptr> {
public:
    /// Converts Python to C++
    bool load(handle src, bool /*unused*/) {
        PyObject* source = src.ptr();
        boost::python::extract<typename openvdb::FloatGrid::Ptr> grid_ptr(source);
        if (!grid_ptr.check()) return false;
        value = grid_ptr();
        return (value && (PyErr_Occurred() == nullptr));
    }

    /// Converts from C++ to Python
    static handle cast(openvdb::FloatGrid::Ptr src, return_value_policy, handle) {
        if (!src) return none().inc_ref();
        py::module::import("pyopenvdb").attr("FloatGrid");
        boost::python::object obj = boost::python::object(src);
        auto out = reinterpret_borrow<py::object>(obj.ptr());
        return out.release();
    }

    PYBIND11_TYPE_CASTER(openvdb::FloatGrid::Ptr, _("pyopenvdb.FloatGrid"));
};
nachovizzo commented 1 year ago

@amwfarid Could you please try the solution from here?

amwfarid commented 1 year ago

@nachovizzo I'm terribly sorry for responding late! I couldn't access the server to test the fix.

It finally worked! Indeed, the "-I" managed to fix the issue and now I can run the code. Thank you very much!