setup.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (c) Meta Platforms, Inc. and affiliates.
  2. # All rights reserved.
  3. # This source code is licensed under the license found in the
  4. # LICENSE file in the root directory of this source tree.
  5. from setuptools import find_packages, setup
  6. from torch.utils.cpp_extension import BuildExtension, CUDAExtension
  7. # Package metadata
  8. NAME = "SAM 2"
  9. VERSION = "1.0"
  10. DESCRIPTION = "SAM 2: Segment Anything in Images and Videos"
  11. URL = "https://github.com/facebookresearch/segment-anything-2"
  12. AUTHOR = "Meta AI"
  13. AUTHOR_EMAIL = "segment-anything@meta.com"
  14. LICENSE = "Apache 2.0"
  15. # Read the contents of README file
  16. with open("README.md", "r") as f:
  17. LONG_DESCRIPTION = f.read()
  18. # Required dependencies
  19. REQUIRED_PACKAGES = [
  20. "torch>=2.3.1",
  21. "torchvision>=0.18.1",
  22. "numpy>=1.24.4",
  23. "tqdm>=4.66.1",
  24. "hydra-core>=1.3.2",
  25. "iopath>=0.1.10",
  26. "pillow>=9.4.0",
  27. ]
  28. EXTRA_PACKAGES = {
  29. "demo": ["matplotlib>=3.9.1", "jupyter>=1.0.0", "opencv-python>=4.7.0"],
  30. "dev": ["black==24.2.0", "usort==1.0.2", "ufmt==2.0.0b2"],
  31. }
  32. def get_extensions():
  33. srcs = ["sam2/csrc/connected_components.cu"]
  34. compile_args = {
  35. "cxx": [],
  36. "nvcc": [
  37. "-DCUDA_HAS_FP16=1",
  38. "-D__CUDA_NO_HALF_OPERATORS__",
  39. "-D__CUDA_NO_HALF_CONVERSIONS__",
  40. "-D__CUDA_NO_HALF2_OPERATORS__",
  41. ],
  42. }
  43. ext_modules = [CUDAExtension("sam2._C", srcs, extra_compile_args=compile_args)]
  44. return ext_modules
  45. # Setup configuration
  46. setup(
  47. name=NAME,
  48. version=VERSION,
  49. description=DESCRIPTION,
  50. long_description=LONG_DESCRIPTION,
  51. long_description_content_type="text/markdown",
  52. url=URL,
  53. author=AUTHOR,
  54. author_email=AUTHOR_EMAIL,
  55. license=LICENSE,
  56. packages=find_packages(exclude="notebooks"),
  57. install_requires=REQUIRED_PACKAGES,
  58. extras_require=EXTRA_PACKAGES,
  59. python_requires=">=3.10.0",
  60. ext_modules=get_extensions(),
  61. cmdclass={"build_ext": BuildExtension.with_options(no_python_abi_suffix=True)},
  62. )