- edited description
Using the python wrapper for IMU pre-Integration
I had trouble activating the tests in python/gtsam_tests
I had to manually add to path the place of the sitepackage:
export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/site-packages/gtsam
In addition I had to add
export PYTHONPATH=${PYTHONPATH}:/home/yonatan/gtsam/build/python/handwritten
Otherwise python could not find gtsampy.so
After solving these problems I ran into another problem.
When typing:
python ImuFactorExample.py
I get the following error:
File "/usr/local/lib/python2.7/site-packages/gtsam_utils/plot.py", line 39, in plotPose3OnAxes
xAxis = C + gRp[:, 0] * axisLength
TypeError: unsupported operand type(s) for +: 'Point3' and 'float'
C is Point3 type and gRp[:, 0] is numpy vector. There doesn't appear to be a conversion between the two.
Is this a genuine bug or a mistake in the way I compiled the python wrapper?
Comments (18)
-
reporter -
Sorry if I am wrong, but I think it is related question.
Also, it is not apparent for me:
- how (if it is possible) to export
gtsam.KeyVector
as numpy array or arrays.
For examlpe I would like to use gtsam python wrapper in Jupyter Notebook,
print
method unfortunately prints to terminal.So if it is already possible it would be nice to see how gtsam->numpy direction works.
- how (if it is possible) to export
-
reporter - changed title to Using the python wrapper for IMU pre-Integration
-
@YontanSimson , did you solve this issue?
-
reporter No. I found another way to work directly with C++ code.
-
Tnx! I will do so too.
-
Hey all,
in the past couple of days I tested the pull request with a new cython wrapper by @thduynguyen (thanks a lot for that!) and tried translating the IMUkittixample.m to python. I had a small issue with PreintegrationParams, which would throw me
gtsam.PreintegrationParams(n_gravity)
which would throw me the following type error
gtsam.pyx in gtsam.PreintegratedRotationParams.__cinit__ (gtsam.cpp:326130)() TypeError: PreintegratedRotationParams construction failed!
For now I just hardcoded n_gravity to np.array([0., 0., -9.81]) in gtsam.pyx.
Other than that, translating IMU Kitti worked fine, and the example runs through, but I still need to do a direct comparison with the MATLAB output. Would be great to get in touch with others who are interested in using GTSAM through python, so let me know if you would like to try out the script.
Best wishes,
Ludwig
-
@auerl Thanks for trying it out! I've just pushed a fix. Can you let me know if that fixes your problem?
It was because PreintegratedRotationParams is the base class of PreintegrationParams, and the base class's cinit is automatically called by Cython with all parameters passed to the subclass, in this case, n_gravity. However, the base class doesn't have any constructor accepting a Vector, thus the error.
Changing cinit to init seems to fix the problem. All the tests still pass, so I think it's ok.
Thanks!
-
Hi @thduynguyen, thanks much, that fixed the problem! I'll keep you posted about how the results compare to the ones obtained with the MATLAB version of it. Greets, Ludwig
-
@auerl: Great! Thanks!
-
reporter I tried the cython wrapper. There were a few problems in the tests. 3/13 failed:
====================================================================== ERROR: test_Pose3SLAMExample (unittest.loader.ModuleImportFailure)
ImportError: Failed to import test module: test_Pose3SLAMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_Pose3SLAMExample.py", line 5, in <module> from gtsam.utils.circlePose3 import * ImportError: No module named utils.circlePose3
====================================================================== ERROR: test_VisualISAMExample (unittest.loader.ModuleImportFailure)
ImportError: Failed to import test module: test_VisualISAMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_VisualISAMExample.py", line 4, in <module> import gtsam.utils.visual_data_generator as generator ImportError: No module named utils.visual_data_generator
====================================================================== ERROR: test_SFMExample (unittest.loader.ModuleImportFailure)
ImportError: Failed to import test module: test_SFMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_SFMExample.py", line 5, in <module> import gtsam.utils.visual_data_generator as generator ImportError: No module named utils.visual_data_generator
cc: @thduynguyen
-
@YontanSimson Thanks for trying it out! Please make sure you stay in your <GTSAM_CYTHON_INSTALL_PATH> folder (or above) when running the unittests. I get the same problem if I stay inside <GTSAM_CYTHON_INSTALL_PATH/gtsam>. "gtsam" is installed as a package inside your <GTSAM_CYTHON_INSTALL_PATH> folder, and "utils" is a sub_package inside gtsam. Also, I've recently made some changes on how the packages should be installed, so if you still have problems after pulling down the latest version, please let me know. Thanks!
-
reporter In the<GTSAM_CYTHON_INSTALL_PATH> I get:
Ran 0 tests in 0.000s
OK
-
"ls -R | grep test", do you see any test_*.py in <GTSAM_CYTHON_INSTALL_PATH>/gtsam/tests? If yes, "python -m unittest discover" should be able to find them. Note the "discover" option: https://docs.python.org/2/library/unittest.html#test-discovery
-
reporter I did what you suggested and all the tests ran flawlessly. Thanks so much!
-
Ah great! Thanks!
-
A solution to the original question about the Point3 to float conversion is to modify (in /usr/local/lib/python2.7/dist-packages/gtsam_utils/plot.py) line 36 to be:
C = pose.translation().vector()
-
- edited description
- changed status to resolved
Resolved in discussion
- Log in to comment