Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There may be some bugs for the function "get_connected_components" in utils\misc.py? #200

Closed
zhangxin06 opened this issue Aug 12, 2024 · 1 comment

Comments

@zhangxin06
Copy link

When I call this function, the following error occurs, and I find that none of the later cuda-related operations can be performed.

Snipaste_2024-08-12_09-10-13

@ronghanghu
Copy link
Contributor

ronghanghu commented Aug 12, 2024

Hi, this is likely due to an error in building the SAM 2 CUDA extension, leading to the error above that prevents get_connected_components from working. You're probably using an earlier version of this repo -- after https://github.com/facebookresearch/segment-anything-2/pull/155 and https://github.com/facebookresearch/segment-anything-2/pull/175, this should become a warning now instead of an error.

From the error message in the screenshot, the root cause seems that the CUDA kernel is somehow not compiled towards your GPU capability (as mentioned in https://developer.nvidia.com/cuda-gpus).

Maybe you can try pulling the latest code and running the following via TORCH_CUDA_ARCH_LIST=9.0 8.0 8.6 8.9 7.0 7.2 6.0 to manually specify the CUDA capability version?

# run the line below inside the SAM 2 repo
git pull;
pip uninstall -y SAM-2;
rm -f sam2/*.so;
TORCH_CUDA_ARCH_LIST="9.0 8.0 8.6 8.9 7.0 7.2 6.0" \
pip install -e ".[demo]"

In case it still doesn't work, you may remove the line "++model.fill_hole_area=8" in https://github.com/facebookresearch/segment-anything-2/blob/778e1127404547429b281d9c9394ddb3652b85a5/sam2/build_sam.py#L64 to turn off this post-processing step that calls into get_connected_components (the results should stay the same in most cases)


Also, we have recently made the CUDA extension step optional (in https://github.com/facebookresearch/segment-anything-2/pull/155 and https://github.com/facebookresearch/segment-anything-2/pull/175) as a workaround to this problem.

Now we allows using SAM 2 without CUDA extension (the results should stay the same in most cases, see INSTALL.md for details).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants