facebookresearch / sam2

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
11.52k stars 1k forks source link

ImportError: Failed to map segment from shared object for _C.so #360

Open VoyageWang opened 6 days ago

VoyageWang commented 6 days ago

ImportError: Failed to map segment from shared object for _C.so

描述: run the code: python demo_video.py segmentation/evf-sam2-multitask ImportError: /EVF-SAM/model/segment_anything_2/sam2/_C.so: failed to map segment from shared object

I have successfully compiled the code using python setup.py build_ext --inplace

/miniconda3/envs/evf-sam/lib/python3.10/site-packages/torch/utils/cpp_extension.py:428: UserWarning: There are no g++ version bounds defined for CUDA version 12.1 warnings.warn(f'There are no {compiler_name} version bounds defined for CUDA version {cuda_str_version}') building 'sam2._C' extension /miniconda3/envs/evf-sam/lib/python3.10/site-packages/torch/utils/cpp_extension.py:1967: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST']. warnings.warn( Emitting ninja build file EVF-SAM/model/segment_anything_2/build/temp.linux-x86_64-cpython-310/build.ninja... Compiling objects... Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N) ninja: no work to do. g++ -pthread -B /miniconda3/envs/evf-sam/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -O2 -isystem miniconda3/envs/evf-sam/include -fPIC -O2 -isystem miniconda3/envs/evf-sam/include -pthread -B miniconda3/envs/evf-sam/compiler_compat -shared //EVF-SAM/model/segment_anything_2/build/temp.linux-x86_64-cpython-310/sam2/csrc/connected_components.o -Lminiconda3/envs/evf-sam/lib/python3.10/site-packages/torch/lib -L/cuda/cuda-12.1/lib64 -lc10 -ltorch -ltorch_cpu -ltorch_python -lcudart -lc10_cuda -ltorch_cuda -o build/lib.linux-x86_64-cpython-310/sam2/_C.so copying build/lib.linux-x86_64-cpython-310/sam2/_C.so -> sam2

How to solve it, thanks for your attention!!!!

Thanks for your reply! I have tried the original sam2 repo, which is ok for me. However, it stiff faces the same issue when I try evf-sam2. The environment is here:

OS: [Ubuntu 20.04] Python版本: [ 3.10] PyTorch版本: [ 2.3.1] CUDA版本: [12.1] GPU型号: [ NVIDIA RTX 3090]

ronghanghu commented 5 days ago

Hi @VoyageWang, the build error you saw (especially the line UserWarning: There are no g++ version bounds defined for CUDA version 12.1) might suggest that your GCC (g++) compiler version doesn't match (and is likely too new for) your CUDA version 12.1. For CUDA 12.1, it maximum supported gcc version is GCC 12.2 (more details of supported compiler versions are in https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html). You could resolve it by installing a GCC version compatible with your CUDA version.

Meanwhile, as an alternative workaround, you can also skip building the CUDA extension for SAM 2, which should still give similar results in most cases.

pip uninstall -y SAM-2 && SAM2_BUILD_CUDA=0 pip install -e ".[notebooks]"