Spaces:
Running
on
Zero
Running
on
Zero
Update setup.py
Browse files
setup.py
CHANGED
@@ -3,22 +3,21 @@
|
|
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 |
-
import spaces
|
10 |
|
11 |
# Package metadata
|
12 |
-
NAME = "SAM
|
13 |
VERSION = "1.0"
|
14 |
DESCRIPTION = "SAM 2: Segment Anything in Images and Videos"
|
15 |
-
URL = "https://github.com/facebookresearch/
|
16 |
AUTHOR = "Meta AI"
|
17 |
AUTHOR_EMAIL = "segment-anything@meta.com"
|
18 |
LICENSE = "Apache 2.0"
|
19 |
|
20 |
# Read the contents of README file
|
21 |
-
with open("README.md", "r") as f:
|
22 |
LONG_DESCRIPTION = f.read()
|
23 |
|
24 |
# Required dependencies
|
@@ -33,26 +32,127 @@ REQUIRED_PACKAGES = [
|
|
33 |
]
|
34 |
|
35 |
EXTRA_PACKAGES = {
|
36 |
-
"
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
|
40 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def get_extensions():
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
return ext_modules
|
54 |
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
# Setup configuration
|
57 |
setup(
|
58 |
name=NAME,
|
@@ -65,9 +165,10 @@ setup(
|
|
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=
|
73 |
)
|
|
|
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 |
+
import os
|
7 |
|
8 |
from setuptools import find_packages, setup
|
|
|
|
|
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/sam2"
|
15 |
AUTHOR = "Meta AI"
|
16 |
AUTHOR_EMAIL = "segment-anything@meta.com"
|
17 |
LICENSE = "Apache 2.0"
|
18 |
|
19 |
# Read the contents of README file
|
20 |
+
with open("README.md", "r", encoding="utf-8") as f:
|
21 |
LONG_DESCRIPTION = f.read()
|
22 |
|
23 |
# Required dependencies
|
|
|
32 |
]
|
33 |
|
34 |
EXTRA_PACKAGES = {
|
35 |
+
"notebooks": [
|
36 |
+
"matplotlib>=3.9.1",
|
37 |
+
"jupyter>=1.0.0",
|
38 |
+
"opencv-python>=4.7.0",
|
39 |
+
"eva-decord>=0.6.1",
|
40 |
+
],
|
41 |
+
"interactive-demo": [
|
42 |
+
"Flask>=3.0.3",
|
43 |
+
"Flask-Cors>=5.0.0",
|
44 |
+
"av>=13.0.0",
|
45 |
+
"dataclasses-json>=0.6.7",
|
46 |
+
"eva-decord>=0.6.1",
|
47 |
+
"gunicorn>=23.0.0",
|
48 |
+
"imagesize>=1.4.1",
|
49 |
+
"pycocotools>=2.0.8",
|
50 |
+
"strawberry-graphql>=0.239.2",
|
51 |
+
],
|
52 |
+
"dev": [
|
53 |
+
"black==24.2.0",
|
54 |
+
"usort==1.0.2",
|
55 |
+
"ufmt==2.0.0b2",
|
56 |
+
"fvcore>=0.1.5.post20221221",
|
57 |
+
"pandas>=2.2.2",
|
58 |
+
"scikit-image>=0.24.0",
|
59 |
+
"tensorboard>=2.17.0",
|
60 |
+
"pycocotools>=2.0.8",
|
61 |
+
"tensordict>=0.5.0",
|
62 |
+
"opencv-python>=4.7.0",
|
63 |
+
"submitit>=1.5.1",
|
64 |
+
],
|
65 |
}
|
66 |
|
67 |
+
# By default, we also build the SAM 2 CUDA extension.
|
68 |
+
# You may turn off CUDA build with `export SAM2_BUILD_CUDA=0`.
|
69 |
+
BUILD_CUDA = os.getenv("SAM2_BUILD_CUDA", "1") == "1"
|
70 |
+
# By default, we allow SAM 2 installation to proceed even with build errors.
|
71 |
+
# You may force stopping on errors with `export SAM2_BUILD_ALLOW_ERRORS=0`.
|
72 |
+
BUILD_ALLOW_ERRORS = os.getenv("SAM2_BUILD_ALLOW_ERRORS", "1") == "1"
|
73 |
+
|
74 |
+
# Catch and skip errors during extension building and print a warning message
|
75 |
+
# (note that this message only shows up under verbose build mode
|
76 |
+
# "pip install -v -e ." or "python setup.py build_ext -v")
|
77 |
+
CUDA_ERROR_MSG = (
|
78 |
+
"{}\n\n"
|
79 |
+
"Failed to build the SAM 2 CUDA extension due to the error above. "
|
80 |
+
"You can still use SAM 2 and it's OK to ignore the error above, although some "
|
81 |
+
"post-processing functionality may be limited (which doesn't affect the results in most cases; "
|
82 |
+
"(see https://github.com/facebookresearch/sam2/blob/main/INSTALL.md).\n"
|
83 |
+
)
|
84 |
+
|
85 |
+
|
86 |
def get_extensions():
|
87 |
+
if not BUILD_CUDA:
|
88 |
+
return []
|
89 |
+
|
90 |
+
try:
|
91 |
+
from torch.utils.cpp_extension import CUDAExtension
|
92 |
+
|
93 |
+
srcs = ["sam2/csrc/connected_components.cu"]
|
94 |
+
compile_args = {
|
95 |
+
"cxx": [],
|
96 |
+
"nvcc": [
|
97 |
+
"-DCUDA_HAS_FP16=1",
|
98 |
+
"-D__CUDA_NO_HALF_OPERATORS__",
|
99 |
+
"-D__CUDA_NO_HALF_CONVERSIONS__",
|
100 |
+
"-D__CUDA_NO_HALF2_OPERATORS__",
|
101 |
+
],
|
102 |
+
}
|
103 |
+
ext_modules = [CUDAExtension("sam2._C", srcs, extra_compile_args=compile_args)]
|
104 |
+
except Exception as e:
|
105 |
+
if BUILD_ALLOW_ERRORS:
|
106 |
+
print(CUDA_ERROR_MSG.format(e))
|
107 |
+
ext_modules = []
|
108 |
+
else:
|
109 |
+
raise e
|
110 |
+
|
111 |
return ext_modules
|
112 |
|
113 |
|
114 |
+
try:
|
115 |
+
from torch.utils.cpp_extension import BuildExtension
|
116 |
+
|
117 |
+
class BuildExtensionIgnoreErrors(BuildExtension):
|
118 |
+
|
119 |
+
def finalize_options(self):
|
120 |
+
try:
|
121 |
+
super().finalize_options()
|
122 |
+
except Exception as e:
|
123 |
+
print(CUDA_ERROR_MSG.format(e))
|
124 |
+
self.extensions = []
|
125 |
+
|
126 |
+
def build_extensions(self):
|
127 |
+
try:
|
128 |
+
super().build_extensions()
|
129 |
+
except Exception as e:
|
130 |
+
print(CUDA_ERROR_MSG.format(e))
|
131 |
+
self.extensions = []
|
132 |
+
|
133 |
+
def get_ext_filename(self, ext_name):
|
134 |
+
try:
|
135 |
+
return super().get_ext_filename(ext_name)
|
136 |
+
except Exception as e:
|
137 |
+
print(CUDA_ERROR_MSG.format(e))
|
138 |
+
self.extensions = []
|
139 |
+
return "_C.so"
|
140 |
+
|
141 |
+
cmdclass = {
|
142 |
+
"build_ext": (
|
143 |
+
BuildExtensionIgnoreErrors.with_options(no_python_abi_suffix=True)
|
144 |
+
if BUILD_ALLOW_ERRORS
|
145 |
+
else BuildExtension.with_options(no_python_abi_suffix=True)
|
146 |
+
)
|
147 |
+
}
|
148 |
+
except Exception as e:
|
149 |
+
cmdclass = {}
|
150 |
+
if BUILD_ALLOW_ERRORS:
|
151 |
+
print(CUDA_ERROR_MSG.format(e))
|
152 |
+
else:
|
153 |
+
raise e
|
154 |
+
|
155 |
+
|
156 |
# Setup configuration
|
157 |
setup(
|
158 |
name=NAME,
|
|
|
165 |
author_email=AUTHOR_EMAIL,
|
166 |
license=LICENSE,
|
167 |
packages=find_packages(exclude="notebooks"),
|
168 |
+
include_package_data=True,
|
169 |
install_requires=REQUIRED_PACKAGES,
|
170 |
extras_require=EXTRA_PACKAGES,
|
171 |
python_requires=">=3.10.0",
|
172 |
+
# ext_modules=get_extensions(),
|
173 |
+
cmdclass=cmdclass,
|
174 |
)
|