cvg/pyceres

Cost functions from pycolmap is not available

Closed this issue · 11 comments

Thanks for the nice project! I am trying to follow examples/test_BA.ipynb, but it seems that cost_functions is not pycolmap attribute anymore (I install pycolmap through pip install pycolmap directly, in a clean python 3.10 conda environment).
I tried to look around in the pycolmap repo, and I didn't see cost_functions in it. I'd appreciate it if you could help me to find those pre-defined cost functions. Thanks in advance!

As mentioned in the pycolmap README, the development has moved to the colmap repo. The cost functions are in src/pycolmap/estimators/cost_functions.h but haven't made it into the previous release, so you need to build pycolmap from source rather than from PyPI. We will create a new release soon.

Thanks for the prompt response and the pointer! I was able to install pycolmap from source (from the main branch of the official colmap mentioned above).
I still encountered an error when adding the cost function:

    prob = pyceres.Problem()
    loss = pyceres.TrivialLoss()
    for im in rec.images.values():
        cam = rec.cameras[im.camera_id]
        for p in im.points2D:
---->         cost = pycolmap.cost_functions.ReprojErrorCost(
                cam.model, im.cam_from_world, p.xy
               )

The error message is

TypeError: Unable to convert function return value to a Python type! The signature was
	(camera_model_id: pycolmap.CameraModelId, cam_from_world: pycolmap.Rigid3d, point2D: numpy.ndarray[numpy.float64[2, 1]]) -> ceres::CostFunction

I may not install the pycolmap properly, as I copied colmap src folder to pycolmap subfolder and changed the CMakeLists.txt in pycolmap folder slightly for the path, to be able to run python -m pip install . successfully to install the library.

I'd appreciate it if you could take a look into this issue.

You likely need to install pyceres from source as well.

I may not install the pycolmap properly, as I copied colmap src folder to pycolmap subfolder and changed the CMakeLists.txt in pycolmap folder slightly for the path, to be able to run python -m pip install . successfully to install the library.

Why is this needed? python -m pip install . should work fine when when the source files are in src/.

Thanks for the help. I tried to install pyceres from sources. Now there seems to be a conflict between two libraries pycolmap and pyceres. When they are imported together, the following error shows up:

Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!

Why is this needed? python -m pip install . should work fine when when the source files are in src/.

When I tried to run the command in the directory colmap/pycolmap, the pypi will complain it can't find source files. If I copy source files over to the same directory, it will work fine. I am not sure why. One guess is that pypi will copy things to one temporary build location, but only the current directory is included. Sorry I don't know much about how it works internally.

Thanks for the help. I tried to install pyceres from sources. Now there seems to be a conflict between two libraries pycolmap and pyceres. When they are imported together, the following error shows up:
Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!

Apologies for the issues. Are you building with glog < 0.6.0? These versions have an issue that has been fixed in 0.6.0. We will add a min version requirement to CMake.

If I copy source files over to the same directory, it will work fine. I am not sure why. One guess is that pypi will copy things to one temporary build location, but only the current directory is included. Sorry I don't know much about how it works internally.

We have never experienced this in any of our build environments. What versions of pip and Python are you using?

Apologies for the issues. Are you building with glog < 0.6.0? These versions have an issue that has been fixed in 0.6.0. We will add a min version requirement to CMake.

No worries at all, thanks for the tip! I will try again later when I have time (on the weekend most likely).

We have never experienced this in any of our build environments. What versions of pip and Python are you using?

I am on Ubuntu 20.04, with system Python and pip via apt (Python 3.8.10, pip 20.0.2). I will try a newer version of Python and pip later.

Did you solve this? After installing glog 0.6.0 from source I got this when import pyceres and import pycolmap

F20240309 20:35:05.630461 108393 utilities.cc:365] Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
*** Check failure stack trace: ***

ERROR: C++ code terminated. Kernel Died. See log files for details.

Were pyceres and pycolmap both installed from source? This this should not occur. Did it regardless of the order in which you import them?

Sorry for the late reply. I tried to install both pyceres and pycolmap from source today (basically go to the source code folder, and run pip install .). I didn't encounter the problem as @colin-de (yet). But when I imported pycolmap, there is an error:
xxx/site-packages/pycolmap.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN5ceres6Solver7SummaryC1Ev

In the meantime, I can import pyceres, and run colmap itself successfully. My Ceres version from apt is 1.14.0. I guess pycolmap might expect a different version.

now it works when I install the colmap again from source after updating the glog to 0.6.0
My ceres=2.1 colmap=3.9.1

Sorry for the late reply. After building both pycolmap and pyceres from source, I am able to run the notebook without problem. For reference, I am using ceres=2.2, colmap=3.10, glog=0.6.0.
Thanks for the help and I am closing this issue.