NeRF-SLAM icon indicating copy to clipboard operation
NeRF-SLAM copied to clipboard

Build problem about gtsam

Open JIANG-CX opened this issue 3 years ago • 28 comments

When I run the command "cmake --build build_gtsam --config RelWithDebInfo -j", it gave an error as follows. Could you please help me to fix it? Thanks.

Traceback (most recent call last): File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/scripts/pybind_wrap.py", line 94, in <module> main() File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/scripts/pybind_wrap.py", line 90, in main wrapper.wrap(sources, args.out) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/pybind_wrapper.py", line 723, in wrap submodules=submodules) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/pybind_wrapper.py", line 624, in wrap_file module = parser.Module.parseString(content) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/interface_parser/module.py", line 56, in parseString return Module.rule.parseString(s)[0] File "/opt/ros/noetic/lib/python3/dist-packages/pyparsing/core.py", line 1141, in parse_string raise exc.with_traceback(None) pyparsing.exceptions.ParseException: Expected string_end, found 'namespace' (at char 1249), (line:46, col:1) make[2]: *** [python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/build.make:76: python/gtsam_unstable.cpp] Error 1 make[1]: *** [CMakeFiles/Makefile2:32620: python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....

JIANG-CX avatar Dec 28 '22 12:12 JIANG-CX

Same issue here. New Ubuntu 20.04 install.

pgaston avatar Dec 28 '22 19:12 pgaston

@phamquandung I have done as you said, but I still have the problem. Which version pyparsing you used?

hjxwhy avatar Dec 29 '22 07:12 hjxwhy

@JIANG-CX, @pgaston I found the solution. Please go to the folder thirdparty and delete gtsam then git clone the updated (https://github.com/ToniRV/gtsam-1/tree/feature/nerf_slam). Then build again.

@ToniRV . I think you should update the gtsam in thirdparty to avoid this issue.

After downloading the new gtsam, I find this error still exists.

JIANG-CX avatar Dec 29 '22 12:12 JIANG-CX

@JIANG-CX @pgaston @hjxwhy you can fork https://github.com/borglab/gtsam this one and build python wrapper like this https://github.com/borglab/gtsam/tree/develop/python. I tried, and it works.

phamquandung avatar Dec 29 '22 14:12 phamquandung

@phamquandung Okay, still hung up here. I moved the gtsam you specified above and built it per instructions. However... when I run I get:

File "/home/pg/repos/NeRF-SLAM/./examples/../slam/vio_slam.py", line 65, in initial_state naive_pose = gtsam.Pose3.identity() AttributeError: type object 'gtsam.gtsam.Pose3' has no attribute 'identity'

Thoughts?

pgaston avatar Dec 29 '22 21:12 pgaston

@phamquandung Okay, still hung up here. I moved the gtsam you specified above and built it per instructions. However... when I run I get:

File "/home/pg/repos/NeRF-SLAM/./examples/../slam/vio_slam.py", line 65, in initial_state naive_pose = gtsam.Pose3.identity() AttributeError: type object 'gtsam.gtsam.Pose3' has no attribute 'identity'

Thoughts?

I think it's a problem of gtsam version. According to https://github.com/borglab/gtsam/issues/1298, identity() was replaced to Identity() (UpperCase)

richard7714 avatar Dec 30 '22 01:12 richard7714

Then, another error:

File "/home/user/research/NeRF-SLAM/./examples/../slam/visual_frontends/visual_frontend.py", line 48, in gtsam_pose_to_torch q = pose.rotation().quaternion() AttributeError: 'gtsam.gtsam.Rot3' object has no attribute 'quaternion'

phamquandung avatar Dec 30 '22 04:12 phamquandung

@phamquandung Then, another error:

File "/home/user/research/NeRF-SLAM/./examples/../slam/visual_frontends/visual_frontend.py", line 48, in gtsam_pose_to_torch q = pose.rotation().quaternion() AttributeError: 'gtsam.gtsam.Rot3' object has no attribute 'quaternion'

That line and the following return statement should be replaced like this

    q = pose.rotation().toQuaternion()
    return torch.tensor([t[0], t[1], t[2], q.x(), q.y(), q.z(), q.w()], device=device, dtype=dtype)

richard7714 avatar Dec 30 '22 06:12 richard7714

@JIANG-CX @pgaston @hjxwhy you can fork https://github.com/borglab/gtsam this one and build python wrapper like this https://github.com/borglab/gtsam/tree/develop/python. I tried, and it works.

Thanks for your kindly help. I can pass the build step now. But when I run the "./examples/slam_demo.py”, I find there is an error about the gtsam. I wonder have you met such error? How did you solve it? Thanks a lot. File "./examples/slam_demo.py", line 200, in <module> run(args) File "./examples/slam_demo.py", line 143, in run slam_module.spin() # visualizer should be the main spin, but pytorch has a memory bug/leak if threaded... File "./examples/../pipeline/pipeline_module.py", line 88, in spin self.initialize_module() File "./examples/../slam/slam_module.py", line 18, in initialize_module from slam.vio_slam import VioSLAM File "./examples/../slam/vio_slam.py", line 9, in <module> from factor_graph.factor_graph import TorchFactorGraph File "./examples/../factor_graph/factor_graph.py", line 14, in <module> from gtsam import NonlinearFactorGraph as FactorGraph ModuleNotFoundError: No module named 'gtsam'

JIANG-CX avatar Dec 30 '22 07:12 JIANG-CX

@JIANG-CX @pgaston @hjxwhy you can fork https://github.com/borglab/gtsam this one and build python wrapper like this https://github.com/borglab/gtsam/tree/develop/python. I tried, and it works.

Thanks for your kindly help. I can pass the build step now. But when I run the "./examples/slam_demo.py”, I find there is an error about the gtsam. I wonder have you met such error? How did you solve it? Thanks a lot. File "./examples/slam_demo.py", line 200, in <module> run(args) File "./examples/slam_demo.py", line 143, in run slam_module.spin() # visualizer should be the main spin, but pytorch has a memory bug/leak if threaded... File "./examples/../pipeline/pipeline_module.py", line 88, in spin self.initialize_module() File "./examples/../slam/slam_module.py", line 18, in initialize_module from slam.vio_slam import VioSLAM File "./examples/../slam/vio_slam.py", line 9, in <module> from factor_graph.factor_graph import TorchFactorGraph File "./examples/../factor_graph/factor_graph.py", line 14, in <module> from gtsam import NonlinearFactorGraph as FactorGraph ModuleNotFoundError: No module named 'gtsam'

In the build folder you should run make python-install and make python-test, then it should be OK.

phamquandung avatar Dec 30 '22 07:12 phamquandung

Yes, I have run make python-install and make python-test, and got the feedback "[100%] Built target python-test" and "Successfully installed gtsam-4.2a8". But the error still exits.

JIANG-CX avatar Dec 30 '22 08:12 JIANG-CX

Maybe you installed gtsam to another python environment?

Also, I made a bunch the changes to adopt to new gtsam in this PR, in case it helps: https://github.com/ToniRV/NeRF-SLAM/issues/12

jrpowers avatar Jan 01 '23 16:01 jrpowers

Using the branch feature/nerf_slam https://github.com/ToniRV/gtsam-1/tree/feature/nerf_slam I found that there is a syntax error in gtsam_unstable/gtsam_unstable.i causing a parsing error: virtual class LinearizedHessianFactor : gtsam::LinearizedGaussianFactor { Needs to be closed 2 lines below (line 818) with };.

EDIT: the author has fixed it and the feature/nerf_slam branch of gtsam should be ok now.

sxyu avatar Jan 01 '23 21:01 sxyu

Maybe you installed gtsam to another python environment?

Also, I made a bunch the changes to adopt to new gtsam in this PR, in case it helps: #12

It works well! Nice job!

yzslab avatar Jan 02 '23 09:01 yzslab

@jrpowers Using your latest PR I got everything to build - whew. The cube sample scene runs fine! Unfortunately, the first example dies a horrible death... (perhaps I'll wait for the dust to settle on all these changes...) Thanks again to all!

(nerf) pg@pg-MS-7A59:~/repos/NeRF-SLAM$ python ./examples/slam_demo.py --dataset_dir=./datasets/Replica/office0 --dataset_name=nerf --buffer=100 --slam --img_stride=2 --fusion='nerf' --multi_gpu --gui
Running with GPUs: 0
Running pipeline in sequential mode.
Loading 1000 images.
  0%|                                                  | 0/1000 [00:00<?, ?it/s]/home/pg/miniconda3/envs/nerf/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
Segmentation fault (core dumped)

The "GPUs: 0" looks fishy. However, nvidia-smi; nvcc --version; and nvitop -- all seem to be showing the usual results.

pgaston avatar Jan 02 '23 17:01 pgaston

works fully for me with the fixed GTSAM from the author & (only) python changes in this repo made by jrpowers

sxyu avatar Jan 02 '23 19:01 sxyu

what is you gcc version or other environment setup ? , after switch the branch. met this error

/usr/include/c++/8/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using pointer = _Tp*;
                           ^
/usr/include/c++/8/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using const_pointer = const _Tp*;

Solved by checking: image

works fully for me with the fixed GTSAM from the author & (only) python changes in this repo made by jrpowers

pengwangucla avatar Jan 05 '23 06:01 pengwangucla

what is you gcc version or other environment setup ? , after switch the branch. met this error

/usr/include/c++/8/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using pointer = _Tp*;
                           ^
/usr/include/c++/8/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using const_pointer = const _Tp*;

Solved by checking: image

works fully for me with the fixed GTSAM from the author & (only) python changes in this repo made by jrpowers

I do not understand this comment. Could you tell me how to fix the linear.cpp? What's the "inner const X& ..." stands for?

JIANG-CX avatar Jan 06 '23 14:01 JIANG-CX

what is you gcc version or other environment setup ? , after switch the branch. met this error

/usr/include/c++/8/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using pointer = _Tp*;
                           ^
/usr/include/c++/8/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘const Eigen::Matrix<double, -1, -1>&’
       using const_pointer = const _Tp*;

Solved by checking: image

works fully for me with the fixed GTSAM from the author & (only) python changes in this repo made by jrpowers

I do not understand this comment. Could you tell me how to fix the linear.cpp? What's the "inner const X& ..." stands for?

It seems that the solution comes from README installation-issues: 3. But i'm also not clear about the "inner const X& ..." and still stuck with this problem now. If you have figured it out, please let me know. @JIANG-CX @pengwangucla

OceanYing avatar Jan 08 '23 13:01 OceanYing

You may change const std::vector<const gtsam::Matrix&>& to const std::vector<gtsam::Matrix>& use & as pointer is not proper define of std::vector

pengwangucla avatar Jan 08 '23 19:01 pengwangucla

You may change const std::vector<const gtsam::Matrix&>& to const std::vector<gtsam::Matrix>& use & as pointer is not proper define of std::vector

Thanks a lot! That's the solution and it works now!

OceanYing avatar Jan 09 '23 15:01 OceanYing

@JIANG-CX, @pgaston I found the solution. Please go to the folder thirdparty and delete gtsam then git clone the updated (https://github.com/ToniRV/gtsam-1/tree/feature/nerf_slam). Then build again. @ToniRV . I think you should update the gtsam in thirdparty to avoid this issue.

After downloading the new gtsam, I find this error still exists.

this worked for me

yusuf-wadi avatar Apr 05 '23 16:04 yusuf-wadi

@phamquandung Then, another error: File "/home/user/research/NeRF-SLAM/./examples/../slam/visual_frontends/visual_frontend.py", line 48, in gtsam_pose_to_torch q = pose.rotation().quaternion() AttributeError: 'gtsam.gtsam.Rot3' object has no attribute 'quaternion'

That line and the following return statement should be replaced like this

    q = pose.rotation().toQuaternion()
    return torch.tensor([t[0], t[1], t[2], q.x(), q.y(), q.z(), q.w()], device=device, dtype=dtype)

Thanks for your reply! It saved my day! I have run into an error because of wrong modification of this.

My wrong version is pose.rotation().toQuaternion().coeffs(); This modification leads q to all nan

KnightOfTheMoonlight avatar Apr 17 '23 08:04 KnightOfTheMoonlight

When I run the command "cmake --build build_gtsam --config RelWithDebInfo -j", it gave an error as follows. Could you please help me to fix it? Thanks.

Traceback (most recent call last): File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/scripts/pybind_wrap.py", line 94, in <module> main() File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/scripts/pybind_wrap.py", line 90, in main wrapper.wrap(sources, args.out) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/pybind_wrapper.py", line 723, in wrap submodules=submodules) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/pybind_wrapper.py", line 624, in wrap_file module = parser.Module.parseString(content) File "/home/jiangcx/Documents/Nerf_related/NeRF-SLAM/thirdparty/gtsam/wrap/gtwrap/interface_parser/module.py", line 56, in parseString return Module.rule.parseString(s)[0] File "/opt/ros/noetic/lib/python3/dist-packages/pyparsing/core.py", line 1141, in parse_string raise exc.with_traceback(None) pyparsing.exceptions.ParseException: Expected string_end, found 'namespace' (at char 1249), (line:46, col:1) make[2]: *** [python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/build.make:76: python/gtsam_unstable.cpp] Error 1 make[1]: *** [CMakeFiles/Makefile2:32620: python/CMakeFiles/pybind_wrap_gtsam_unstable.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....

thirdparty/gtsam/gtsam_unstable/gtsam_unstable.i 815,1: virtual class LinearizedHessianFactor : gtsam::LinearizedGaussianFactor { 这个类结尾 少了两个字符 }; ,加上即可

Tonny24Wang avatar Jul 10 '23 10:07 Tonny24Wang

try "git clone https://github.com/ToniRV/gtsam-1" then cmake it!

SimonsRoad avatar Sep 04 '23 09:09 SimonsRoad

try "git clone https://github.com/ToniRV/gtsam-1" then cmake it!

this worked for me.

lllray avatar Sep 24 '23 08:09 lllray

@jrpowers Using your latest PR I got everything to build - whew. The cube sample scene runs fine! Unfortunately, the first example dies a horrible death... (perhaps I'll wait for the dust to settle on all these changes...) Thanks again to all!

(nerf) pg@pg-MS-7A59:~/repos/NeRF-SLAM$ python ./examples/slam_demo.py --dataset_dir=./datasets/Replica/office0 --dataset_name=nerf --buffer=100 --slam --img_stride=2 --fusion='nerf' --multi_gpu --gui
Running with GPUs: 0
Running pipeline in sequential mode.
Loading 1000 images.
  0%|                                                  | 0/1000 [00:00<?, ?it/s]/home/pg/miniconda3/envs/nerf/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
Segmentation fault (core dumped)

The "GPUs: 0" looks fishy. However, nvidia-smi; nvcc --version; and nvitop -- all seem to be showing the usual results.

Hi I also met this segmentation fault error. Could you please tell me how did you solve this issue? Thx a lot!

wbjsamuel avatar Dec 17 '23 15:12 wbjsamuel

@JIANG-CX @pgaston @hjxwhy you can fork https://github.com/borglab/gtsam this one and build python wrapper like this https://github.com/borglab/gtsam/tree/develop/python. I tried, and it works.

Thanks for your kindly help. I can pass the build step now. But when I run the "./examples/slam_demo.py”, I find there is an error about the gtsam. I wonder have you met such error? How did you solve it? Thanks a lot. File "./examples/slam_demo.py", line 200, in <module> run(args) File "./examples/slam_demo.py", line 143, in run slam_module.spin() # visualizer should be the main spin, but pytorch has a memory bug/leak if threaded... File "./examples/../pipeline/pipeline_module.py", line 88, in spin self.initialize_module() File "./examples/../slam/slam_module.py", line 18, in initialize_module from slam.vio_slam import VioSLAM File "./examples/../slam/vio_slam.py", line 9, in <module> from factor_graph.factor_graph import TorchFactorGraph File "./examples/../factor_graph/factor_graph.py", line 14, in <module> from gtsam import NonlinearFactorGraph as FactorGraph ModuleNotFoundError: No module named 'gtsam'

Hello, I have the same problem when I run the demo. Although I have update gtsam and torch118, it didn't work. So how did you solve the problem(No module named 'gtsam')?

Zhangxr02 avatar May 31 '24 03:05 Zhangxr02