yansong1616 commited on
Commit
99c3d60
1 Parent(s): faca4a5

Update setup.py

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