Skip to content

Instantly share code, notes, and snippets.

@mihaidusmanu
Last active April 19, 2022 15:44
Show Gist options
  • Save mihaidusmanu/cab9d41972e68b137188c211c3af771e to your computer and use it in GitHub Desktop.
Save mihaidusmanu/cab9d41972e68b137188c211c3af771e to your computer and use it in GitHub Desktop.
COLMAP on Leonhard

Compiling COLMAP on Leonhard

This is a short tutorial for compiling COLMAP on Leonhard with GCC 6.3.0. Qt installation is quite large so COLMAP cannot be compiled in the home directories.

Modules and Paths

Create a file called colmap_startup.sh in your home directory containing the following:

export DATA=/cluster/project/infk/cvg/$USER

# COLMAP
module load gcc/6.3.0

module load cmake/3.4.3

module load boost eigen glog gflags glew

module load cgal openblas suite-sparse atlas

module load mpfr

module load mesa/12.0.3 mesa-glu

module load libxcb

module load cuda/10.0.130

export FREEIMAGE_DIR=/cluster/project/infk/cvg/$USER/dev/FreeImage/Dist
export Qt5_DIR=/cluster/project/infk/cvg/$USER/dev/qt5-build/qtbase/lib/cmake/Qt5

export COLMAP_PATH=/cluster/project/infk/cvg/$USER/dev/colmap/build/src/exe

Navigate to the project storage and create a folder for development:

source colmap_startup.sh
cd $DATA
mkdir dev
cd dev

Qt5

This part is adapted from the official tutorial.

git clone git://code.qt.io/qt/qt5.git
cd qt5
git checkout 5.9.8
perl init-repository --module-subset=qtbase
cd ..
mkdir qt5-build
cd qt5-build
../qt5/configure -developer-build -opensource -nomake examples -nomake tests
bsub -I -n 8 -R "rusage[mem=4096]" "make -j 8"
# Check that the compilation finished successfully.
cd ..

Ceres Solver

wget "http://ceres-solver.org/ceres-solver-1.14.0.tar.gz"
tar xvzf ceres-solver-1.14.0.tar.gz
rm ceres-solver-1.14.0.tar.gz
cd ceres-solver-1.14.0
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=Off -DEXPORT_BUILD_DIR=On ..
bsub -I -n 8 -R "rusage[mem=4096]" "make -j 8"
# Check that the compilation finished successfully.
bsub -I -n 8 -R "rusage[mem=4096]" "make test"
# Check that all tests pass.
cd ../..

FreeImage

wget "https://sourceforge.net/projects/freeimage/files/Source Distribution/3.18.0/FreeImage3180.zip"
unzip FreeImage3180.zip
rm FreeImage3180.zip
cd FreeImage
bsub -I -n 8 -R "rusage[mem=4096]" "make -j 8"
# Check that the compilation finished successfully.
cd ..

COLMAP

git clone https://github.com/colmap/colmap.git
cd colmap
mkdir build
cd build
cmake .. -DFREEIMAGE_INCLUDE_DIR_HINTS=$FREEIMAGE_DIR -DFREEIMAGE_LIBRARY_DIR_HINTS=$FREEIMAGE_DIR -DTESTS_ENABLED=ON -DCUDA_ARCHS="Pascal;Turing;Volta"
bsub -I -n 8 -R "rusage[mem=4096,ngpus_excl_p=1]" "make -j 8"
# Check that the compilation finished successfully.
bsub -I -n 8 -R "rusage[mem=4096,ngpus_excl_p=1]" "ctest"
# Check that tests pass. Currently known to fail: sift_test, opengl_utils_test.
cd ../..

Please note that currently there is no 30XX support on the cluster (no CUDA 11).

Comments

  • Known issue The matcher is currently not working - it seems to prefer OpenGL to CUDA even when OpenGL is disabled during compilation (-DOPENGL_ENABLED=OFF). I have tried multiple versions of CUDA and OpenGL, but the two tests mentioned above were always failing. I suggest using a custom matcher (i.e., PyTorch based) and running GV without GPU (--SiftMatching.use_gpu 0 option for matches_importer).
  • While I am around, you can probably use the compiled version of Qt / FreeImage available on my project storage. Try changing the following lines of colmap_startup.sh:
export FREEIMAGE_DIR=/cluster/project/infk/cvg/dusmanum/dev/FreeImage/Dist
export Qt5_DIR=/cluster/project/infk/cvg/dusmanum/dev/qt5-build/qtbase/lib/cmake/Qt5
@oguzhanilter
Copy link

oguzhanilter commented Apr 22, 2021

Dear Mihai,

I am trying to install pycolmap to use the following code https://github.com/cvg/Hierarchical-Localization.
Although I followed exact steps you explained here, I could not figure out how to use FreeImage since it has no cmake support. (All other libraries have *.cmake which I can set *_DIR to the corresponding directory). I am using Euler Cluster if it matters.

  _Could not find a package configuration file provided by "FreeImage" with
  any of the following names:

    FreeImageConfig.cmake
    freeimage-config.cmake

  Add the installation prefix of "FreeImage" to CMAKE_PREFIX_PATH or set
  "FreeImage_DIR" to a directory containing one of the above files.  If
  "FreeImage" provides a separate development package or SDK, be sure it has
  been installed._

Do you know how to solve this error?

Best,
Oguzhan

@mihaidusmanu
Copy link
Author

FreeImage should already be discovered with the install instructions from above. Notably, instead of passing *_DIR, you have to pass *_DIR_HINTS as follows: -DFREEIMAGE_INCLUDE_DIR_HINTS=$FREEIMAGE_DIR -DFREEIMAGE_LIBRARY_DIR_HINTS=$FREEIMAGE_DIR.

@oguzhanilter
Copy link

oguzhanilter commented Apr 22, 2021

Thank you for your fast response!

I could not understand exactly what to do with *_DIR_HINTS and I set the system variables as the following:

  export FREEIMAGE_DIR=/cluster/directory/to/shared/space/dev/FreeImage/Dist
  export DFREEIMAGE_INCLUDE_DIR_HINTS=$FREEIMAGE_DIR
  export DFREEIMAGE_LIBRARY_DIR_HINTS=$FREEIMAGE_DIR

However, it did not solve the error.

@mihaidusmanu
Copy link
Author

You need to pass them directly to cmake as above cmake .. -DFREEIMAGE_INCLUDE_DIR_HINTS=$FREEIMAGE_DIR -DFREEIMAGE_LIBRARY_DIR_HINTS=$FREEIMAGE_DIR -DTESTS_ENABLED=ON -DCUDA_ARCHS="Pascal;Turing;Volta"

@oguzhanilter
Copy link

Unfortunately, the problem continues even after the following steps:

  1. Loaded Modules: - StdEnv - cmake/3.16.5 - glog/0.3.5 - glew/2.0.0 - openblas/0.3.7 - atlas/3.10.2 - libxcb/1.13 - boost/1.69.0
    - gcc/6.3.0 - eigen/3.3.4 - gflags/2.1.2 - cgal/4.11 - suite-sparse/5.1.0 - mpfr/4.0.1 - mesa/17.2.3 - cuda/11.2.2
  2. export FREEIMAGE_DIR=/cluster/directory/to/shared/space/dev/FreeImage/Dist
    export Qt5_DIR=/cluster/directory/to/shared/space/dev/qt5-build/qtbase/lib/cmake/Qt5
    export COLMAP_PATH=/cluster/directory/to/shared/space/dev/colmap/build/src/exe
    export COLMAP_DIR = /cluster/directory/to/shared/space/dev/colmap/build/
  3. Reinstall COLMAP

Best,
Oguzhan

@sebgiles
Copy link

sebgiles commented Apr 27, 2021

Hello. I also had this issue. The problem is the cmake directory is not created in the expected place. You can fix this by running make install after building. You will need to specify a target directory and then use it as your "COLMAP_DIR" for building pycolmap. I did this a couple weeks ago let me know if you want more details.

@sebgiles
Copy link

sebgiles commented Apr 29, 2021

@oguzhanilter I am replying here instead of email so others can also see it.
After building COLMAP I also ran this to install it to an arbitrary location.

COLMAP_INSTALL_TARGET="/cluster/home/$USER/colmap"  # or what you prefer as long as you can r/w
mkdir $COLMAP_INSTALL_TARGET
bsub -I -n 8 -R "rusage[mem=4096,ngpus_excl_p=1]" "make DESTDIR=$COLMAP_INSTALL_TARGET install -j 8"

Then you will need to

export COLMAP_PATH=$COLMAP_INSTALL_TARGET/usr/local/bin/colmap
export COLMAP_DIR=$COLMAP_INSTALL_TARGET/usr/local/share/colmap

before building pycolmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment