cdcseacave / openMVS

open Multi-View Stereo reconstruction library
http://cdcseacave.github.io
GNU Affero General Public License v3.0
3.31k stars 907 forks source link

RefineMesh Segmentation fault #680

Open TheTioz opened 3 years ago

TheTioz commented 3 years ago

Hello, I just installed openmvs 1.1.1-1 from archlinux aur. I was following the step from here that I adapted to linux and CPU only (I have a amd gpu). I used it on a few different models with ~50 images each time.

When I reach the RefineMesh step, it always seg fault.

work_dir_pixel_2]$ RefineMesh --use-cuda 0 --resolution-level 1 model_dense_mesh.mvs -v3
10:04:10 [App     ] Build date: Jun 23 2021, 16:23:00
10:04:10 [App     ] CPU: AMD Ryzen 9 5950X 16-Core Processor             (32 cores)
10:04:10 [App     ] RAM: 62.81GB Physical Memory 0B Virtual Memory
10:04:10 [App     ] OS: Linux 5.12.12-arch1-1 (x86_64)
10:04:10 [App     ] SSE & AVX compatible CPU & OS detected
10:04:10 [App     ] Command line: --use-cuda 0 --resolution-level 1 model_dense_mesh.mvs -v3
10:04:10 [App     ] CUDA error: cuInit(0) (CUDA_ERROR_NO_DEVICE (code 100) - no CUDA-capable device is detected)
10:04:12 [App     ] Scene loaded (1s469ms):
        46 images (46 calibrated) with a total of 534.88 MPixels (11.63 MPixels/image)
        0 points, 2440567 vertices, 4878934 faces
10:04:12 [App     ] Refine mesh at: 0.25 image scale
Decimated faces 4391041 (100%, 16s167ms)           
10:05:05 [App     ] Mesh decimated: 4878934 -> 487893 faces
10:05:06 [App     ] Removed 0 zero-area faces
10:05:06 [App     ] Removed 3 duplicate faces
10:05:06 [App     ] Removed 6 non-manifold faces
10:05:06 [App     ] Removed 0 degenerate vertices
10:05:07 [App     ] Removed 155 unreferenced vertices
10:05:07 [App     ] Removed 0 duplicate vertices
10:05:07 [App     ] Split 0 non-manifold vertices
10:05:07 [App     ] Closed 15 holes and added 3 new faces
10:05:07 [App     ] Cleaned mesh: 245029 vertices, 487886 faces (19s234ms)
10:05:07 [App     ] Removed 0 zero-area faces
10:05:07 [App     ] Removed 0 duplicate faces
10:05:07 [App     ] Removed 0 non-manifold faces
10:05:07 [App     ] Removed 0 degenerate vertices
10:05:07 [App     ] Removed 0 unreferenced vertices
10:05:08 [App     ] Removed 0 duplicate vertices
10:05:08 [App     ] Split 0 non-manifold vertices
10:05:08 [App     ] Closed 12 holes and added 0 new faces
10:05:08 [App     ] Removed 0 non-manifold faces
10:05:08 [App     ] Removed 0 non-manifold vertices
10:05:08 [App     ] Cleaned mesh: 245029 vertices, 487886 faces (665ms)
10:05:11 [App     ] Mesh imported: 245061 vertices, 487950 facets (1994 border edges)
10:05:32 [App     ] Edge size in [0.000561376, 0.0827581] (requested in [0.00977236, 0.0781789]): 51104 ops, 50 iters
10:05:32 [App     ] Mesh exported: 208339 vertices, 413467 facets (3033 border edges)
10:05:32 [App     ] Removed 0 zero-area faces
10:05:32 [App     ] Removed 0 duplicate faces
10:05:32 [App     ] Removed 0 non-manifold faces
10:05:32 [App     ] Removed 0 degenerate vertices
10:05:32 [App     ] Removed 0 unreferenced vertices
10:05:32 [App     ] Removed 0 duplicate vertices
10:05:32 [App     ] Split 0 non-manifold vertices
10:05:32 [App     ] Closed 12 holes and added 43 new faces
10:05:32 [App     ] Removed 0 non-manifold faces
10:05:33 [App     ] Removed 0 non-manifold vertices
10:05:33 [App     ] Cleaned mesh: 208339 vertices, 413510 faces (610ms)
10:05:33 [App     ] Mesh subdivided: 245029/487886 -> 208339/413510 vertices/faces
10:05:33 [App     ] Mesh saved: 208339 vertices, 413510 faces (36ms)
Segmentation fault (core dumped)

I still have plenty of ram. Any idea of what I can do to fix the issue? The model_dense_mesh.ply is "ok" but not great( some hole and not perfect quality)

Thank you very much

cdcseacave commented 3 years ago

interesting: you have plenty of RAM, but the CPU has also lots of cores, so in the end 64GB might not be that much pls try using --max-threads 8 in the command line and see if it helps if not pls share the MVS scene and images

TheTioz commented 3 years ago

Hello, thank you very much for the help. I already tried to run with less thread. With 8 and even 1, it uses maximum 11GB of ram and crash at the same spot.

In order to simplify the process I have just ran everything using the gerrard-hall datasets (the smallest one). I started only from the image folder and ran the command that you can find in the script.txt file included with the mvs in the zip file,

By the way i tried both the --use-cuda 0 and --use-cuda 1 flag but I realized that in the created log file it fail in both case with a cuda error! It seems that the cuda flag is ignored for the second part of program.

16:49:39 [App     ] Build date: Jun 23 2021, 16:23:00
16:49:39 [App     ] CPU: AMD Ryzen 9 5950X 16-Core Processor             (32 cores)
16:49:39 [App     ] RAM: 62.81GB Physical Memory 0B Virtual Memory
16:49:39 [App     ] OS: Linux 5.12.12-arch1-1 (x86_64)
16:49:39 [App     ] SSE & AVX compatible CPU & OS detected
16:49:39 [App     ] Command line: --use-cuda 0 --resolution-level 1 model_dense_mesh.mvs
16:49:40 [App     ] CUDA error: cuInit(0) (CUDA_ERROR_NO_DEVICE (code 100) - no CUDA-capable device is detected)
16:49:44 [App     ] Scene loaded (4s515ms):
    91 images (91 calibrated) with a total of 1058.14 MPixels (11.63 MPixels/image)
    0 points, 3841735 vertices, 7682498 faces
16:55:44 [App     ] Cleaned mesh: 384590 vertices, 768216 faces (1m4s972ms)
16:55:47 [App     ] Cleaned mesh: 384590 vertices, 768216 faces (3s286ms)
16:57:54 [App     ] Cleaned mesh: 343781 vertices, 685958 faces (2s433ms)
16:57:54 [App     ] Mesh subdivided: 384590/768216 -> 343781/685958 vertices/faces
16:58:06 [App     ] CUDA error: kernelComputeFaceNormal((int)faces.GetSize(), vertices, faces, CUDA::KernelRT::OutputParam(faceNormals.GetDataSize()), faces.GetSize() ) (CUDA_ERROR_OUT_OF_MEMORY (code 2) - out of memory)

Edit: removed link.

TheTioz commented 3 years ago

I compiled with SET(OpenMVS_USE_CUDA OFF CACHE BOOL "Enable CUDA library") and it works. I think the issue is related to the --use-cuda flag.

I looked a little a the source but I did not see anything yet.

TheTioz commented 3 years ago

Maybe I got it. In Mesh.cpp, the function ComputeNormalFaces() is only checking for the compilation flag _USE_CUDA and not the program parameter OPT::bUseCUDA. So it try to use cuda and crash. The function is used in SceneRefine.cpp ScoreMesh(double* gradients) itself called in RefineMesh(...).