Code Monkey home page Code Monkey logo

ceres_python_bindings's Introduction

Ceres Python Wrapper

This project uses pybind11 to wrap Ceres with a python interface.

Build Setup

There are different ways to build this library. The safest way is build it along with the Ceres library.

Recommended: Build Alongside Ceres

Clone the repository at https://github.com/Edwinem/ceres_python_bindings into your ceres-solver folder.

Initialize and download the pybind11 submodule

git clone https://github.com/Edwinem/ceres_python_bindings
cd ceres_python_bindings
git submodule init
git submodule update

If you cloned it somewhere else then you must now copy and paste the ceres_python_bindings directory to your ceres-solver directory.

Your ceres directory should now look something like this.

ceres-solver/
│
├── CMakeLists.txt
├── include
├── ...
│
├── ceres_python_bindings/ - THIS REPOSITORY
│   ├── pybind11 
│   ├── python_bindings
│   ├── ...
│   └── AddToCeres.cmake - file to include in Ceres CMakeLists.txt

Open up your ceres-solver/CMakeLists.txt and add the following to the end of the file.

include(ceres_python_bindings/AddToCeres.cmake)

If everything was successful then when you call cmake in your build folder at the end it should output

-- Python Bindings for Ceres(PyCeres) have been added

Build Ceres as you would normally. To specifically build the bindings you should call make PyCeres .

Build separately and link to Ceres

Note that these methods assume that you have built and installed the Ceres library. Either through sudo apt-get or by doing make install.

  • You might have to modify the CMakeLists.txt to link to extra libraries such as suitesparse depending on how your Ceres library was built.

Normal Cmake

Clone the project and initialize the submodules. Call cmake as you would normally.

cd ceres_python_bindings
git submodule init
git submodule update
mkdir build
cd build
cmake ..
make

Python setup.py

This uses cmake-build-extension to call the cmake commands with python's setuptools.

Activate your python virtual env. Within the ceres_python_bindings folder run pip install .. This will call the setup.py file and install PyCeres to your virtual environment.

If this fails then your best bet is to use the normal cmake method and debug from there.

How to import PyCeres

Built with setuptools

If you used the setup.py with pip then the library should have been installed to your virtualenv, and you can simply install it with

import PyCeres

Built with cmake

Somewhere a file called PyCeres.so should have been built. It should be in your build directory. It probably more likely looks something like this PyCeres.cpython-36m-x86_64-linux-gnu.so. Mark down the location of this file. This location is what you have to add to python sys.path in order to use the library. An example of how to do this can be seen below.

pyceres_location="..."
import sys
sys.path.insert(0, pyceres_location)

After this you can now run

import PyCeres

to utilize the library.

Another option is to copy and paste the PyCeres.so file to your virtualenv/lib folder, which allows you to skip the sys path modifications.

How to use PyCeres

You should peruse some of the examples listed below. It works almost exactly like Ceres in C++. The only care you have to take is that the parameters you pass to the AddResidualBlock() function is a numpy array.

Basic HelloWorld

Code for this example can be found in examples/ceres_hello_world_example.py

This example is the same as the hello world example from Ceres.

import PyCeres  # Import the Python Bindings
import numpy as np

# The variable to solve for with its initial value.
initial_x = 5.0
x = np.array([initial_x])  # Requires the variable to be in a numpy array

# Here we create the problem as in normal Ceres
problem = PyCeres.Problem()

# Creates the CostFunction. This example uses a C++ wrapped function which
# returns the Autodiffed cost function used in the C++ example
cost_function = PyCeres.CreateHelloWorldCostFunction()

# Add the costfunction and the parameter numpy array to the problem
problem.AddResidualBlock(cost_function, None, x)

# Setup the solver options as in normal ceres
options = PyCeres.SolverOptions()
# Ceres enums live in PyCeres and require the enum Type
options.linear_solver_type = PyCeres.LinearSolverType.DENSE_QR
options.minimizer_progress_to_stdout = True
summary = PyCeres.Summary()
# Solve as you would normally
PyCeres.Solve(options, problem, summary)
print(summary.BriefReport() + " \n")
print("x : " + str(initial_x) + " -> " + str(x) + "\n")

CostFunction in Python

This library allows you to create your own custom CostFunction in Python to be used with the Ceres Solver.

An custom CostFunction in Python can be seen here.

# function f(x) = 10 - x.
# Comes from ceres/examples/helloworld_analytic_diff.cc
class QuadraticCostFunction(PyCeres.CostFunction):
    def __init__(self):
        # MUST BE CALLED. Initializes the Ceres::CostFunction class
        super().__init__()
        
        # MUST BE CALLED. Sets the size of the residuals and parameters
        self.set_num_residuals(1) 
        self.set_parameter_block_sizes([1])

    # The CostFunction::Evaluate(...) virtual function implementation
    def Evaluate(self,parameters, residuals, jacobians):
        x=parameters[0][0]

        residuals[0] = 10 - x

        if (jacobians!=None): # check for Null
            jacobians[0][0] = -1

        return True

Some things to be aware of for a custom CostFunction

  • residuals is a numpy array
  • parameters,jacobians are lists of numpy arrays ([arr1,arr2,...])
    • Indexing works similar to Ceres C++. parameters[i] is the ith parameter block
    • You must always index into the list first. Even if it only has 1 value.
  • You must call the base constructor with super.

CostFunction defined in C++

It is possible to define your custom CostFunction in C++ and utilize it within the python framework. In order to do this we provide a file python_bindings/custom_cpp_cost_functions.cpp. which provides a place to write your own wrapper code. The easiest way to do this is create an initialization function that creates your custom CostFunction class and returns a ceres::CostFunction* to it. That function should then be wrapped in the void add_custom_cost_functions(py::module& m) function.

It should end up looking something like this.

#include <CUSTOM_HEADER_FILES_WITH_COST_FUNCTION>

// Create a function that initiliazes your CostFunction and returns a ceres::CostFunction*

ceres::CostFunction* CreateCustomCostFunction(arg1,arg2,...){
    return new CustomCostFunction(arg1,arg2,...);
}

// In file custom_cpp_cost_function add the following line

void add_custom_cost_functions(py::module &m) {
    // ....
    m.def("CreateCustomCostFunction",&CreateCustomCostFunction);
}

We provide a basic example of this in custom_cpp_cost_functions.cpp. Note you are responsible for ensuring that all the dependencies and includes are set correctly for your library.

Running examples

We provide a couple examples of how to use the library under ./python_tests. They all assume the wrappers were built alongside Ceres for the PyCeres library. If you did not do this then you need to set the PYCERES_LOCATION environment variable.

You need the following python libs to run these examples.

Required:

  • numpy

Optional:

  • pytest
  • jax

Experimental PyTorch functionality

Warnings:

  • Remember Ceres was designed with a C++ memory model. So you have to be careful when using it from Python. The main problem is that Python does not really have the concept of giving away ownership of memory. So it may try to delete something that Ceres still believes is valid.
    • I think for most stuff I setup the proper procedures that this doesn't happen ( e.g Ceres::Problem by default has Ownership turned off, cost_function can't be deleted until Problem is ,...) . But you never know what I missed.
  • Careful with wrapping AutodiffCostfunction. It takes over the memory of a cost functor which can cause errors.
  • Python has GIL. Therefore, cost functions written in Python have a fundamental slowdown, and can't be truly multithreaded.

TODOs

  • The wrapper code that wraps the Evaluate pointers(residuals,parameters,..) needs a lot of improvement and optimization. We really need this to be a zero copy operation.
  • Wrap all the variables for Summary and other classes
  • LocalParameterizations and Lossfunctions need to be properly wrapped
  • Callbacks need to be wrapped
  • Investigate how to wrap a basic python function for evaluate rather than go through the CostFunction( something like in the C api).
  • Add docstrings for all the wrapped stuff
  • Add a place for users to define their CostFunctions in C++
  • Evaluate speed of Python Cost Function vs C++
  • Clean up AddResidualBlock() and set up the correct error checks
  • Figure out how google log should work with Python
  • Figure out if Jax or PyTorch could somehow be integrated so that we use their tensor/numpy arrays.

Status

Custom Cost functions work

LICENSE

Same as Ceres New BSD.

Credit

This is just a wrapper over the hard work of the main Ceres project. All the examples derive from ceres-solver/examples

ceres_python_bindings's People

Contributors

edwinem 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  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  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

ceres_python_bindings's Issues

LocalParameterization exception

I can't manage to make the LocalParameterization work.

Here is my LocalParameterization class definition

class SO3Parameterization(PyCeres.LocalParameterization):

def __init__(self):
    super().__init__()

def Plus(self, x, delta, x_plus_delta):
    #...compute step
    return True

def GlobalSize(self):
    return 4

def LocalSize(self):
    return 3

def ComputeJacobian(x, jacobian):
    # ...compute Jacobian
    return True

when I try to add the parameter block to the problem an exception is raised.

  problem.AddParameterBlock(r_params, 4, SO3Parameterization())

Am I using the LocalParameterization incorrectly?

Error during alongside build

Hello,
I am having trouble building the Bindings alongside Ceres-1-14.0. As in the doc it's confirmed that the Python Bindings have been added during cmake.
Following the instructions from the doc I get errors in the make process afterwards:

python_module.cpp:63:26: error: ‘ceres::Problem::Problem(const ceres::Problem&)’ is private within this context
return ceres::Problem(o);

and lots of different errors afterwards (variable not declared before, use of deleted function, private within this context, invalid conversion, not a member of ‘ceres’, etc.). For what ceres version is your build working?

PyCeres.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cholmod_solve

I'm an error when I call 'import PyCeres', and I've built it along side Ceres 2.0.0. Do I need to use a different version of Ceres, or I did something else wrong?

import PyCeres
Traceback (most recent call last):
File "", line 1, in
File "/home/danny/ceres/ceres-venv/lib/python3.6/site-packages/PyCeres/init.py", line 1, in
from PyCeres.PyCeres import *
ImportError: /home/danny/ceres/ceres-venv/lib/python3.6/site-packages/PyCeres/PyCeres.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cholmod_solve

custom cost function using opencv

Hey,

I try to create a custom cost function which uses opencv. Building etc. worked fine, but when I try to import I get the following error now:
Traceback (most recent call last): File "<input>", line 3, in <module> File "/snap/pycharm-professional/244/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ImportError: ../../../installation/ceres-solver/build/lib/PyCeres.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN2cv8fastFreeEPv

Any idea how to fix this?

TypeError: AddResidualBlock(): incompatible function arguments. The following argument types are supported:

Hello, when I run the " ceres_python_bindings-master/examples/ceres_simple_bundle_adjuster.py ", I get an error like the following.

Traceback (most recent call last):
File "/home/ceres_python_bindings-master/examples/ceres_simple_bundle_adjuster.py", line 40, in
problem.AddResidualBlock(cost_function, loss, numpy_cameras[cam_index], numpy_points[point_index])
TypeError: AddResidualBlock(): incompatible function arguments. The following argument types are supported:
1. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
2. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
3. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
4. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64], arg5: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
5. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64], arg5: numpy.ndarray[float64], arg6: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
6. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: List[numpy.ndarray[float64]]) -> PyCeres.ResidualBlock

Invoked with: <PyCeres.Problem object at 0x7fd202f69f30>, <PyCeres.CostFunction object at 0x7fd20139f870>, <PyCeres.HuberLoss object at 0x7fd202f50a70>, array([ 1.57415159e-02, -1.27909362e-02, -4.40084981e-03, -3.40938396e-02,
-1.07513871e-01, 1.12022403e+00, 3.99751526e+02, -3.17706439e-07,
5.88204905e-13]), array([-0.61200016, 0.57175905, -1.84708128])

parameters values are not updated

Hi,

I'm having a problem getting the final values of parameters. I defined a custom cost function (PyCeres.CostFunction) and used options.linear_solver_type = PyCeres.LinearSolverType.DENSE_QR, with options = PyCeres.SolverOptions(). I also define an initial_x and parameters = np.array(initial_x). However, once the solver converges, the value of parameters is equal to its initial value. I added a print in the cost function inside the cost function and I could see the different values of parameters evaluated at each iteration.

Is there a way to get the final values of parameters once the problem is solved?

Thanks,
Azza

Local parameterization fix

Hi,

I am using the wrapper for some of my code and noticed that the local parameterization wrapper was missing the parent argument in templates. I fixed it on my end and would like to contribute to the repo. How do I go about doing that? It would be great if I could create a branch with the fix and then initiate a merge request.

Thanks,
Abhishek

loss function?

The loss function not working.

 problem = PyCeres.Problem()
    for idx in range(num_points):
        loss = PyCeres.HuberLoss(0.1)
        cost_function = PyCeres.CreatePnPCostFunction(
            obj_pts[idx, 0], obj_pts[idx, 1],
            wld_pts[idx, 0], wld_pts[idx, 1], wld_pts[idx, 2])
        problem.AddResidualBlock(cost_function, loss, camera)
    options = PyCeres.SolverOptions()
    options.linear_solver_type = PyCeres.LinearSolverType.DENSE_SCHUR
    options.minimizer_progress_to_stdout = True

output:

TypeError: AddResidualBlock(): incompatible function arguments. The following argument types are supported:
    1. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
    2. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
    3. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
    4. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64], arg5: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
    5. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: numpy.ndarray[float64], arg3: numpy.ndarray[float64], arg4: numpy.ndarray[float64], arg5: numpy.ndarray[float64], arg6: numpy.ndarray[float64]) -> PyCeres.ResidualBlock
    6. (self: PyCeres.Problem, arg0: ceres::CostFunction, arg1: ceres::LossFunction, arg2: List[numpy.ndarray[float64]]) -> PyCeres.ResidualBlock

Invoked with: <PyCeres.Problem object at 0x7f7d20353420>, <PyCeres.CostFunction object at 0x7f7d1f197420>, <PyCeres.HuberLoss object at 0x7f7d1f197378>, array([-1.43568278,  0.59850256, -0.46698532, -0.08802976,  0.97900193,
       18.47388059])


Problems when building with PyTorch

Meet: ceres-solver/build/lib/PyCeres.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZNK5ceres6Solver7Summary11BriefReportEv

After building the library, and trying into import PyCeres after import torch

I guess it may have something to do with this instruction:

Build Ceres and GLOG that you link to with -D_GLIBCXX_USE_CXX11_ABI=0
The default PyTorch libs that you download from pip and other package managers is built with the old C++ ABI.

Cannot quite get what should be done with this. Does it simply means adding -D_GLIBCXX_USE_CXX11_ABI=0 option when running cmake (which I've tried, but turned out not working)?

Build alongside fails

I've followed the build alongside instructions, but when I run make I get a lot of errors (mostly std errors).

Building without the ceres_python_bindings folder in my ceres-solver folder results in a successful build.

I've also tried build separately and link to Ceres (which builds without errors, both for cmake and pip) but then I get the import errors mentioned in other issues (undefined symbol: cholmod_solve).

Any advice?

[ 27%] Building CXX object CMakeFiles/PyCeres.dir/ceres_python_bindings/python_bindings/python_module.cpp.o
In file included from /home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/parameter_dims.h:37,
                 from /home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/autodiff.h:150,
                 from /home/laine/Ceres/ceres-solver-2.1.0/include/ceres/autodiff_cost_function.h:130,
                 from /home/laine/Ceres/ceres-solver-2.1.0/include/ceres/ceres.h:37,
                 from /home/laine/Ceres/ceres-solver-2.1.0/ceres_python_bindings/python_bindings/python_module.cpp:30:
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:67:21: error: ‘integer_sequence’ is not a member of ‘std’
   67 | struct SumImpl<std::integer_sequence<T, N, Ns...>> {
      |                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:67:21: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:67:46: error: wrong number of template arguments (3, should be 1)
   67 | struct SumImpl<std::integer_sequence<T, N, Ns...>> {
      |                                              ^~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:63:8: note: provided for ‘template<class Seq> struct ceres::internal::SumImpl’
   63 | struct SumImpl;
      |        ^~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:67:49: error: expected unqualified-id before ‘>’ token
   67 | struct SumImpl<std::integer_sequence<T, N, Ns...>> {
      |                                                 ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:74:21: error: ‘integer_sequence’ is not a member of ‘std’
   74 | struct SumImpl<std::integer_sequence<T, N1, N2, Ns...>> {
      |                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:74:21: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:74:51: error: wrong number of template arguments (4, should be 1)
   74 | struct SumImpl<std::integer_sequence<T, N1, N2, Ns...>> {
      |                                                   ^~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:63:8: note: provided for ‘template<class Seq> struct ceres::internal::SumImpl’
   63 | struct SumImpl;
      |        ^~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:74:54: error: expected unqualified-id before ‘>’ token
   74 | struct SumImpl<std::integer_sequence<T, N1, N2, Ns...>> {
      |                                                      ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:81:21: error: ‘integer_sequence’ is not a member of ‘std’
   81 | struct SumImpl<std::integer_sequence<T, N1, N2, N3, N4, Ns...>> {
      |                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:81:21: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:81:59: error: wrong number of template arguments (6, should be 1)
   81 | struct SumImpl<std::integer_sequence<T, N1, N2, N3, N4, Ns...>> {
      |                                                           ^~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:63:8: note: provided for ‘template<class Seq> struct ceres::internal::SumImpl’
   63 | struct SumImpl;
      |        ^~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:81:62: error: expected unqualified-id before ‘>’ token
   81 | struct SumImpl<std::integer_sequence<T, N1, N2, N3, N4, Ns...>> {
      |                                                              ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:88:21: error: ‘integer_sequence’ is not a member of ‘std’
   88 | struct SumImpl<std::integer_sequence<T, N>> {
      |                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:88:21: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:88:41: error: wrong number of template arguments (2, should be 1)
   88 | struct SumImpl<std::integer_sequence<T, N>> {
      |                                         ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:63:8: note: provided for ‘template<class Seq> struct ceres::internal::SumImpl’
   63 | struct SumImpl;
      |        ^~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:88:42: error: expected unqualified-id before ‘>’ token
   88 | struct SumImpl<std::integer_sequence<T, N>> {
      |                                          ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:94:21: error: ‘integer_sequence’ is not a member of ‘std’
   94 | struct SumImpl<std::integer_sequence<T>> {
      |                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:94:21: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:94:38: error: template argument 1 is invalid
   94 | struct SumImpl<std::integer_sequence<T>> {
      |                                      ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:94:39: error: expected unqualified-id before ‘>’ token
   94 | struct SumImpl<std::integer_sequence<T>> {
      |                                       ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:138:31: error: ‘integer_sequence’ is not a member of ‘std’
  138 |                          std::integer_sequence<T, N, Ns...>,
      |                               ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:138:31: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:138:59: error: template argument 3 is invalid
  138 |                          std::integer_sequence<T, N, Ns...>,
      |                                                           ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:138:59: error: type/value mismatch at argument 4 in template parameter list for ‘template<class T, T Sum, class SeqIn, class SeqOut> struct ceres::internal::ExclusiveScanImpl’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:138:59: note:   expected a type, got ‘N’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:149:39: error: ‘integer_sequence’ is not a member of ‘std’
  149 | struct ExclusiveScanImpl<T, Sum, std::integer_sequence<T>, SeqOut> {
      |                                       ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:149:39: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:149:57: error: wrong number of template arguments (3, should be 4)
  149 | struct ExclusiveScanImpl<T, Sum, std::integer_sequence<T>, SeqOut> {
      |                                                         ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:133:8: note: provided for ‘template<class T, T Sum, class SeqIn, class SeqOut> struct ceres::internal::ExclusiveScanImpl’
  133 | struct ExclusiveScanImpl;
      |        ^~~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:163:53: error: ‘integer_sequence’ is not a member of ‘std’
  163 |       typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type;
      |                                                     ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:163:53: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:163:70: error: template argument 4 is invalid
  163 |       typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type;
      |                                                                      ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:163:16: error: expected nested-name-specifier
  163 |       typename ExclusiveScanImpl<T, T(0), Seq, std::integer_sequence<T>>::Type;
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:181:29: error: ‘integer_sequence’ is not a member of ‘std’
  181 |                        std::integer_sequence<T, Values...>,
      |                             ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:181:29: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:181:58: error: template argument 3 is invalid
  181 |                        std::integer_sequence<T, Values...>,
      |                                                          ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:181:58: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, T ValueToRemove, class ... Sequence> struct ceres::internal::RemoveValueImpl’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:181:58: note:   expected a type, got ‘Values ...’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:190:29: error: ‘integer_sequence’ is not a member of ‘std’
  190 |                        std::integer_sequence<T, Head...>,
      |                             ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:190:29: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:190:56: error: template argument 3 is invalid
  190 |                        std::integer_sequence<T, Head...>,
      |                                                        ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:190:56: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, T ValueToRemove, class ... Sequence> struct ceres::internal::RemoveValueImpl’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:190:56: note:   expected a type, got ‘Head ...’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:201:29: error: ‘integer_sequence’ is not a member of ‘std’
  201 |                        std::integer_sequence<T, Head...>,
      |                             ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:201:29: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:201:56: error: template argument 3 is invalid
  201 |                        std::integer_sequence<T, Head...>,
      |                                                        ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:201:56: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, T ValueToRemove, class ... Sequence> struct ceres::internal::RemoveValueImpl’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:201:56: note:   expected a type, got ‘Head ...’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:47: error: ‘integer_sequence’ is not a member of ‘std’
  210 | struct RemoveValueImpl<T, ValueToRemove, std::integer_sequence<T, Tail...>>
      |                                               ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:47: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:71: error: template argument 3 is invalid
  210 | struct RemoveValueImpl<T, ValueToRemove, std::integer_sequence<T, Tail...>>
      |                                                                       ^~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:71: error: type/value mismatch at argument 3 in template parameter list for ‘template<class T, T ValueToRemove, class ... Sequence> struct ceres::internal::RemoveValueImpl’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:71: note:   expected a type, got ‘Tail ...’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:210:74: error: expected unqualified-id before ‘>’ token
  210 | struct RemoveValueImpl<T, ValueToRemove, std::integer_sequence<T, Tail...>>
      |                                                                          ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:25: error: ‘integer_sequence’ is not a member of ‘std’
  246 | struct AreAllEqual<std::integer_sequence<T, Value>> : std::true_type {};
      |                         ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:25: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:45: error: template argument 1 is invalid
  246 | struct AreAllEqual<std::integer_sequence<T, Value>> : std::true_type {};
      |                                             ^~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:45: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:45: note:   expected a type, got ‘Value’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:246:50: error: expected unqualified-id before ‘>’ token
  246 | struct AreAllEqual<std::integer_sequence<T, Value>> : std::true_type {};
      |                                                  ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:25: error: ‘integer_sequence’ is not a member of ‘std’
  250 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2>>
      |                         ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:25: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:53: error: template argument 1 is invalid
  250 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2>>
      |                                                     ^~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:53: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:53: note:   expected a type, got ‘Value1’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:53: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:53: note:   expected a type, got ‘Value2’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:250:59: error: expected unqualified-id before ‘>’ token
  250 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2>>
      |                                                           ^~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:25: error: ‘integer_sequence’ is not a member of ‘std’
  256 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2, Values...> >
      |                         ^~~~~~~~~~~~~~~~
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:25: error: ‘integer_sequence’ is not a member of ‘std’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: error: template argument 1 is invalid
  256 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2, Values...> >
      |                                                                      ^
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: note:   expected a type, got ‘Value1’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: note:   expected a type, got ‘Value2’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... Sequence> struct ceres::internal::AreAllEqual’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:70: note:   expected a type, got ‘Values ...’
/home/laine/Ceres/ceres-solver-2.1.0/include/ceres/internal/integer_sequence_algorithm.h:256:72: error: expected unqualified-id before ‘>’ token
  256 | struct AreAllEqual<std::integer_sequence<T, Value1, Value2, Values...> >
      |                                                                        ^

bindings for ceres::cos, ceres::sin

Do you provide bindings for ceres::cos and ceres::sin? I want to write a custom functor which optimizes an angle variable and I want to use ceres' cos and sine so that it treats as a special variable that needs to be handled with care. Any help?

ImportError: PyCeres.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cholmod_solve

Hello,when running the 'ceres_hello_world_example.py', the following error occurs,
File "/home/miniconda3/envs/pyceres/lib/python3.6/site-packages/PyCeres/init.py", line 3, in
from PyCeres.PyCeres import *
ImportError: /home/miniconda3/envs/pyceres/lib/python3.6/site-packages/PyCeres/PyCeres.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cholmod_solve.

ModuleNotFoundError: No module named 'PyCeres.PyCeres'

I first install Ceres and then install ceres_python_bindings. It seems successful,

(Where2comm) root@386d1e05ef15:/data/localdata/hjw/Github/ceres-solver/ceres_python_bindings# pip install .
Processing /data/localdata/hjw/Github/ceres-solver/ceres_python_bindings
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: PyCeres
  Building wheel for PyCeres (pyproject.toml) ... done
  Created wheel for PyCeres: filename=PyCeres-0.0.0-cp37-cp37m-linux_x86_64.whl size=1611978 sha256=57c4e95a1f3bae1def39ec135ce50acf019da47e2f74bcefac02b8b97a2ad271
  Stored in directory: /tmp/pip-ephem-wheel-cache-8v00wsv5/wheels/18/8e/5f/5a4a7bdf7bb119e9aae6b12fc0531bee90b11dcbb69327067c
Successfully built PyCeres
Installing collected packages: PyCeres
  Attempting uninstall: PyCeres
    Found existing installation: PyCeres 0.0.0
    Uninstalling PyCeres-0.0.0:
      Successfully uninstalled PyCeres-0.0.0
Successfully installed PyCeres-0.0.0

However, when I run "import PyCeres", it tells me no module named PyCeres.PyCeres, whether I use base environment or my own virtual environment

(base) root@386d1e05ef15:/data/localdata/hjw/Code# python whileboard.py 
Traceback (most recent call last):
  File "/data/localdata/hjw/Code/whileboard.py", line 4, in <module>
    import PyCeres
  File "/opt/conda/lib/python3.9/site-packages/PyCeres/__init__.py", line 1, in <module>
    from PyCeres.PyCeres import *
ModuleNotFoundError: No module named 'PyCeres.PyCeres'

Thanks for any insight.

About custom_cpp_cost_functions.cpp

I have a question. Whether AutoDiffCostFunction support a lot of parameters counts ,such as return new ceres::AutoDiffCostFunction<ExampleFunctor, 16364, 11281>

Error installing on Amazon Linux 2

Hi there,

I tried to install ceres_python_bindings along-side ceres-solver (v2.2.0 cloned from ceres-solver main branch on github). The installation is on an Amazon Linux 2 distribution, with g++ 7.3.1 and cmake 3.24.2. I am working with python3.8

I run the cmake for ceres using the flags
cmake -DSUITESPARSE=OFF -DCMAKE_CXX_STANDARD=17, and after having modifyed the CMakeList file with the cerer_python_bindings path.

I obtained a positive cmake output:

-- Detected Ceres version: 2.2.0 from /home/vferro/workplace/CERES/ceres-solver/include/ceres/version.h
-- Detected available Ceres threading models: [CXX_THREADS, OPENMP, NO_THREADS]
-- Found Eigen version 3.3.7: /usr/share/eigen3
-- Enabling use of Eigen as a sparse linear algebra library.
-- Building without CUDA.
-- Found LAPACK library: /usr/lib64/libopenblas.so;-lpthread;-lm;-ldl
-- Building without SuiteSparse.
-- Building without Eigen METIS support.
-- Building without Apple's Accelerate sparse support.
-- Use of gflags disabled - no tests or tools will be built!
-- No preference for use of exported glog CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported glog CMake configuration if available.
-- Found installed version of glog: /usr/local/lib64/cmake/glog
-- Detected glog version: 0.7.0
-- Found Google Log (glog). Assuming glog was NOT built with gflags support as gflags was not found.  If glog was built with gflags, please set the gflags search locations such that it can be found by Ceres.  Otherwise, Ceres may fail to link due to missing gflags symbols.
-- Using Ceres threading model: CXX_THREADS
-- Building Ceres as a static library.
-- Enabling CERES_USE_EIGEN_SPARSE in Ceres config.h
-- Enabling CERES_NO_SUITESPARSE in Ceres config.h
-- Enabling CERES_NO_CUDA in Ceres config.h
-- Enabling CERES_NO_ACCELERATE_SPARSE in Ceres config.h
-- Enabling CERES_USE_CXX_THREADS in Ceres config.h
-- Enabling CERES_NO_CHOLMOD_PARTITION in Ceres config.h
-- Enabling CERES_NO_EIGEN_METIS in Ceres config.h
-- Build the examples.
-- pybind11 v2.4.dev4
**-- Python Bindings for Ceres(PyCeres) have been added**
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vferro/workplace/CERES/ceres-solver

However, then I try to run make, I get the following errors:

Consolidate compiler generated dependencies of target ceres_internal
[ 78%] Built target ceres_internal
Consolidate compiler generated dependencies of target ceres
[ 83%] Built target ceres
[ 83%] Building CXX object CMakeFiles/PyCeres.dir/ceres_python_bindings/python_bindings/python_module.cpp.o
/home/vferro/workplace/CERES/ceres-solver/ceres_python_bindings/python_bindings/python_module.cpp: In function ‘ceres::Problem CreatePythonProblem()’:
/home/vferro/workplace/CERES/ceres-solver/ceres_python_bindings/python_bindings/python_module.cpp:60:16: warning: no previous declaration for ‘ceres::Problem CreatePythonProblem()’ [-Wmissing-declarations]
 ceres::Problem CreatePythonProblem() {
                ^~~~~~~~~~~~~~~~~~~
/home/vferro/workplace/CERES/ceres-solver/ceres_python_bindings/python_bindings/python_module.cpp:62:5: error: ‘struct ceres::Problem::Options’ has no member named ‘local_parameterization_ownership’; did you mean ‘loss_function_ownership’?
   o.local_parameterization_ownership = ceres::Ownership::DO_NOT_TAKE_OWNERSHIP;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     loss_function_ownership

...

I cropped the entire error message above for brevity. Here is an attachment of the entire output.
debug_ceres_python_bindings.txt

If I try to compile ceres-solver without adding python bindings, it compiles without problems.

I also tried to compile python binding directly with cmake (not alongside ceres), and got a similar error:

[ 25%] Building CXX object CMakeFiles/PyCeres.dir/python_bindings/python_module.cpp.o
/home/vferro/workplace/CERES/ceres-solver/ceres_python_bindings/python_bindings/python_module.cpp: In function ‘ceres::Problem CreatePythonProblem()’:
/home/vferro/workplace/CERES/ceres-solver/ceres_python_bindings/python_bindings/python_module.cpp:62:5: error: ‘struct ceres::Problem::Options’ has no member named ‘local_parameterization_ownership’; did you mean ‘loss_function_ownership’?
   o.local_parameterization_ownership = ceres::Ownership::DO_NOT_TAKE_OWNERSHIP;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     loss_function_ownership

....

Finally, for completeness, I also tried to install using pip install . , but that failed too.


I am not sure if this has something to do with the version of ceres-solver that I cloned, and whether I should revert to an earlier version.

Please let me know if you need more info on this issue, and/or if you there is something I missed in the installation guide.

Build along-side ceres does not work

I've setup following the instructions in the README to build with ceres. There's nothing wrong with the building process, except for that I cannot find the generated python binding to import from.

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.