Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError when add an error function to objective with only one opt_var #660

Open
EmeryLee97 opened this issue Sep 3, 2024 · 3 comments

Comments

@EmeryLee97
Copy link

❓ Questions and Help

Hi, I'm doing pose graph optimization with theseus. I get the following error:

4294 Traceback (most recent call last):
4295   File "/home/stud/lxuh/LoopClosure_for_Gaussian_Splatting_SLAM/run_slam.py", line 109, in <module>
4296     gslam.run()
4297   File "/home/stud/lxuh/LoopClosure_for_Gaussian_Splatting_SLAM/src/entities/gaussian_slam.py", line 259, in run
4298     self.pose_graph_optimization(frame_id, gaussian_model)
4299   File "/home/stud/lxuh/LoopClosure_for_Gaussian_Splatting_SLAM/src/entities/gaussian_slam.py", line 177, in pose_graph_optimization
4300     optimize_info = self.pose_graph.optimize()
4301   File "/home/stud/lxuh/LoopClosure_for_Gaussian_Splatting_SLAM/src/entities/pose_graph.py", line 141, in optimize
4302     _, info = layer.forward(optimizer_kwargs={
4303   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/theseus_layer.py", line 93, in forward
4304     vars, info = _forward(
4305   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/theseus_layer.py", line 171, in _forward
4306     info = optimizer.optimize(**optimizer_kwargs)
4307   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/optimizer.py", line 51, in optimize
4308     return self._optimize_impl(**kwargs)
4309   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/nonlinear/nonlinear_least_squares.py", line 251, in _optimize_impl
4310     self._optimize_loop(
4311   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/nonlinear/nonlinear_least_squares.py", line 117, in _optimize_loop
4312     self.linear_solver.linearization.linearize(
4313   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/linearization.py", line 56, in linearize
4314     self._linearize_hessian_impl(_detach_hessian=_detach_hessian)
4315   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/sparse_linearization.py", line 155, in _linearize_hessian_impl
4316     self._linearize_jacobian_impl()
4317   File "/home/stud/lxuh/miniconda3/envs/gslam/lib/python3.10/site-packages/theseus/optimizer/sparse_linearization.py", line 136, in _linearize_jacobian_impl
4318     pointer = block_pointers[var_idx_in_cost_function]
4319 IndexError: index 1 is out of bounds for axis 0 with size 1

My pose graph contains SE(3) nodes, and node_0 is defined as aux_var, the others are all opt_var. Every time I add a constraint between node_0 and node_i, I get this error during optimization. What can be the reason that causes this and how can I avoid?

@EmeryLee97 EmeryLee97 changed the title IndexError when optimizing an error function between IndexError when add an error function to objective with only one opt_var Sep 3, 2024
@luisenp
Copy link
Contributor

luisenp commented Sep 11, 2024

Hi @EmeryLee97. What kind of constraint you are adding between the two nodes? Not sure if this is the cause of your error, but if the cost function class you are using expects both variables to be optimization variables, this will eventually result in an error during the optimization process.

@EmeryLee97
Copy link
Author

Hi @EmeryLee97. What kind of constraint you are adding between the two nodes? Not sure if this is the cause of your error, but if the cost function class you are using expects both variables to be optimization variables, this will eventually result in an error during the optimization process.

I'm using the AutoDiffCostFunction, and a custom error function. The custom error function takes two inputs: opt_var and aux_var.

@luisenp
Copy link
Contributor

luisenp commented Sep 16, 2024

@EmeryLee97 Do you have a short repro for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants