simple-sam2 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simple_sam2-0.1.0/LICENSE +182 -0
- simple_sam2-0.1.0/NOTICE +12 -0
- simple_sam2-0.1.0/PKG-INFO +376 -0
- simple_sam2-0.1.0/README.md +162 -0
- simple_sam2-0.1.0/pyproject.toml +44 -0
- simple_sam2-0.1.0/setup.cfg +4 -0
- simple_sam2-0.1.0/simple_sam2/__init__.py +17 -0
- simple_sam2-0.1.0/simple_sam2/service.py +720 -0
- simple_sam2-0.1.0/simple_sam2.egg-info/PKG-INFO +376 -0
- simple_sam2-0.1.0/simple_sam2.egg-info/SOURCES.txt +11 -0
- simple_sam2-0.1.0/simple_sam2.egg-info/dependency_links.txt +1 -0
- simple_sam2-0.1.0/simple_sam2.egg-info/requires.txt +5 -0
- simple_sam2-0.1.0/simple_sam2.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work.
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
58
|
+
whom a Contribution has been received by the Licensor and included
|
|
59
|
+
within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
65
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
66
|
+
Work and such Derivative Works in Source or Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
(except as stated in this section) patent license to make, have made,
|
|
72
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
73
|
+
where such license applies only to those patent claims licensable
|
|
74
|
+
by such Contributor that are necessarily infringed by their
|
|
75
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
76
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
77
|
+
institute patent litigation against any entity (including a cross-claim
|
|
78
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
79
|
+
Contribution embodied within the Work constitutes direct or
|
|
80
|
+
contributory patent infringement, then any patent licenses granted to
|
|
81
|
+
You under this License for that Work shall terminate as of the date
|
|
82
|
+
such litigation is filed.
|
|
83
|
+
|
|
84
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
85
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
86
|
+
modifications, and in Source or Object form, provided that You
|
|
87
|
+
meet the following conditions:
|
|
88
|
+
|
|
89
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
90
|
+
a copy of this License; and
|
|
91
|
+
|
|
92
|
+
(b) You must cause any modified files to carry prominent notices
|
|
93
|
+
stating that You changed the files; and
|
|
94
|
+
|
|
95
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
96
|
+
that You distribute, all copyright, patent, trademark, and
|
|
97
|
+
attribution notices from the Source form of the Work,
|
|
98
|
+
excluding those notices that do not pertain to any part of
|
|
99
|
+
the Derivative Works; and
|
|
100
|
+
|
|
101
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
102
|
+
distribution, You must include a readable copy of the attribution
|
|
103
|
+
notices contained within such NOTICE file, in at least one
|
|
104
|
+
of the following places: within a NOTICE text file distributed
|
|
105
|
+
as part of the Derivative Works; within the Source form or
|
|
106
|
+
documentation, if provided along with the Derivative Works; or,
|
|
107
|
+
within a display generated by the Derivative Works, if and
|
|
108
|
+
wherever such third-party notices normally appear. The contents
|
|
109
|
+
of the NOTICE file are for informational purposes only and
|
|
110
|
+
do not modify the License. You may add Your own attribution
|
|
111
|
+
notices within Derivative Works that You distribute, alongside
|
|
112
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
113
|
+
that such additional attribution notices cannot be construed
|
|
114
|
+
as modifying the License.
|
|
115
|
+
|
|
116
|
+
You may add Your own license statement for Your modifications and
|
|
117
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
118
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
119
|
+
Contribution, either on an inclusive or exclusive basis, as You
|
|
120
|
+
determine appropriate, for any period, or Your discretion.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate license agreement you may have executed
|
|
128
|
+
with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any warranties or conditions
|
|
140
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
141
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
142
|
+
appropriateness of using or reproducing the Work and assume any
|
|
143
|
+
risks associated with Your exercise of permissions under this License.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
147
|
+
unless required by applicable law (such as deliberate and grossly
|
|
148
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special,
|
|
150
|
+
incidental, or exemplary damages of any character arising as a
|
|
151
|
+
result of this License or out of the use or inability to use the
|
|
152
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
153
|
+
work stoppage, computer failure or malfunction, or all other
|
|
154
|
+
commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
158
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
159
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
160
|
+
or other liability obligations and/or rights consistent with this
|
|
161
|
+
License. However, in accepting such obligations, You may act only
|
|
162
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
163
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
164
|
+
defend, and hold each Contributor harmless for any liability
|
|
165
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
166
|
+
of your accepting any such warranty or additional liability.
|
|
167
|
+
|
|
168
|
+
END OF TERMS AND CONDITIONS
|
|
169
|
+
|
|
170
|
+
Copyright 2026 Varun Kolluru
|
|
171
|
+
|
|
172
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
173
|
+
you may not use this file except in compliance with the License.
|
|
174
|
+
You may obtain a copy of the License at
|
|
175
|
+
|
|
176
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
177
|
+
|
|
178
|
+
Unless required by applicable law or agreed to in writing, software
|
|
179
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
180
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
181
|
+
See the License for the specific language governing permissions and
|
|
182
|
+
limitations under the License.
|
simple_sam2-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
simple-sam2
|
|
2
|
+
Copyright 2026 Varun Kolluru
|
|
3
|
+
|
|
4
|
+
This project is a wrapper around SAM2 (Segment Anything Model 2) by Meta AI Research.
|
|
5
|
+
|
|
6
|
+
SAM2 Repository : https://github.com/facebookresearch/sam2
|
|
7
|
+
SAM2 License : Apache 2.0
|
|
8
|
+
SAM2 Copyright : Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
|
|
10
|
+
In compliance with the Apache 2.0 License, the original SAM2 license and
|
|
11
|
+
copyright notice are reproduced above. This project does not redistribute
|
|
12
|
+
SAM2 source code; it declares SAM2 as a pip dependency.
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simple-sam2
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight wrapper around Meta SAM2 for practical long-video segmentation.
|
|
5
|
+
Author-email: Varun Kolluru <your@email.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship made available under
|
|
41
|
+
the License, as indicated by a copyright notice that is included in
|
|
42
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
45
|
+
form, that is based on (or derived from) the Work and for which the
|
|
46
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
47
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
48
|
+
of this License, Derivative Works shall not include works that remain
|
|
49
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
50
|
+
the Work and Derivative Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
53
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
54
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
55
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
56
|
+
or written communication sent to the Licensor or its representatives,
|
|
57
|
+
including but not limited to communication on electronic mailing lists,
|
|
58
|
+
source code control systems, and issue tracking systems that are managed
|
|
59
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
60
|
+
improving the Work.
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
63
|
+
whom a Contribution has been received by the Licensor and included
|
|
64
|
+
within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a cross-claim
|
|
83
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
84
|
+
Contribution embodied within the Work constitutes direct or
|
|
85
|
+
contributory patent infringement, then any patent licenses granted to
|
|
86
|
+
You under this License for that Work shall terminate as of the date
|
|
87
|
+
such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
95
|
+
a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, You must include a readable copy of the attribution
|
|
108
|
+
notices contained within such NOTICE file, in at least one
|
|
109
|
+
of the following places: within a NOTICE text file distributed
|
|
110
|
+
as part of the Derivative Works; within the Source form or
|
|
111
|
+
documentation, if provided along with the Derivative Works; or,
|
|
112
|
+
within a display generated by the Derivative Works, if and
|
|
113
|
+
wherever such third-party notices normally appear. The contents
|
|
114
|
+
of the NOTICE file are for informational purposes only and
|
|
115
|
+
do not modify the License. You may add Your own attribution
|
|
116
|
+
notices within Derivative Works that You distribute, alongside
|
|
117
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
118
|
+
that such additional attribution notices cannot be construed
|
|
119
|
+
as modifying the License.
|
|
120
|
+
|
|
121
|
+
You may add Your own license statement for Your modifications and
|
|
122
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
123
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
124
|
+
Contribution, either on an inclusive or exclusive basis, as You
|
|
125
|
+
determine appropriate, for any period, or Your discretion.
|
|
126
|
+
|
|
127
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
128
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
129
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
130
|
+
this License, without any additional terms or conditions.
|
|
131
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
132
|
+
the terms of any separate license agreement you may have executed
|
|
133
|
+
with Licensor regarding such Contributions.
|
|
134
|
+
|
|
135
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
136
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
137
|
+
except as required for reasonable and customary use in describing the
|
|
138
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
139
|
+
|
|
140
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
141
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
142
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
143
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
144
|
+
implied, including, without limitation, any warranties or conditions
|
|
145
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
146
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
147
|
+
appropriateness of using or reproducing the Work and assume any
|
|
148
|
+
risks associated with Your exercise of permissions under this License.
|
|
149
|
+
|
|
150
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
151
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
152
|
+
unless required by applicable law (such as deliberate and grossly
|
|
153
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
154
|
+
liable to You for damages, including any direct, indirect, special,
|
|
155
|
+
incidental, or exemplary damages of any character arising as a
|
|
156
|
+
result of this License or out of the use or inability to use the
|
|
157
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
158
|
+
work stoppage, computer failure or malfunction, or all other
|
|
159
|
+
commercial damages or losses), even if such Contributor has been
|
|
160
|
+
advised of the possibility of such damages.
|
|
161
|
+
|
|
162
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
163
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
164
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
165
|
+
or other liability obligations and/or rights consistent with this
|
|
166
|
+
License. However, in accepting such obligations, You may act only
|
|
167
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
168
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
169
|
+
defend, and hold each Contributor harmless for any liability
|
|
170
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
171
|
+
of your accepting any such warranty or additional liability.
|
|
172
|
+
|
|
173
|
+
END OF TERMS AND CONDITIONS
|
|
174
|
+
|
|
175
|
+
Copyright 2026 Varun Kolluru
|
|
176
|
+
|
|
177
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
178
|
+
you may not use this file except in compliance with the License.
|
|
179
|
+
You may obtain a copy of the License at
|
|
180
|
+
|
|
181
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
182
|
+
|
|
183
|
+
Unless required by applicable law or agreed to in writing, software
|
|
184
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
185
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
186
|
+
See the License for the specific language governing permissions and
|
|
187
|
+
limitations under the License.
|
|
188
|
+
|
|
189
|
+
Project-URL: Homepage, https://github.com/varun-kolluru/simple-sam2
|
|
190
|
+
Project-URL: Repository, https://github.com/varun-kolluru/simple-sam2
|
|
191
|
+
Project-URL: Bug Tracker, https://github.com/varun-kolluru/simple-sam2/issues
|
|
192
|
+
Keywords: sam2,segmentation,video,computer vision,meta ai
|
|
193
|
+
Classifier: Development Status :: 3 - Alpha
|
|
194
|
+
Classifier: Intended Audience :: Developers
|
|
195
|
+
Classifier: Intended Audience :: Science/Research
|
|
196
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
197
|
+
Classifier: Programming Language :: Python :: 3
|
|
198
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
199
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
200
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
201
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
202
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
203
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
204
|
+
Requires-Python: >=3.9
|
|
205
|
+
Description-Content-Type: text/markdown
|
|
206
|
+
License-File: LICENSE
|
|
207
|
+
License-File: NOTICE
|
|
208
|
+
Requires-Dist: torch>=2.0
|
|
209
|
+
Requires-Dist: torchvision
|
|
210
|
+
Requires-Dist: numpy
|
|
211
|
+
Requires-Dist: Pillow
|
|
212
|
+
Requires-Dist: opencv-python>=4.8
|
|
213
|
+
Dynamic: license-file
|
|
214
|
+
|
|
215
|
+
# simple-sam2
|
|
216
|
+
|
|
217
|
+
A lightweight Python wrapper around [Meta SAM2](https://github.com/facebookresearch/sam2) that makes long-video segmentation practical.
|
|
218
|
+
|
|
219
|
+
## What this adds on top of SAM2
|
|
220
|
+
|
|
221
|
+
| Problem | What simple-sam2 does |
|
|
222
|
+
|---|---|
|
|
223
|
+
| SAM2 only accepts mask OR points+box separately | **Unified prompt API** — pass mask, points, and box together in one call |
|
|
224
|
+
| SAM2 loads the entire video into memory | **Batch processing** — only `batch_size` frames in memory at once |
|
|
225
|
+
| No way to inspect/correct mid-video | **Incremental propagation** — segment N frames, check, then continue |
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Installation
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# 1. Install SAM2 manually first (not on PyPI)
|
|
233
|
+
pip install git+https://github.com/facebookresearch/sam2.git
|
|
234
|
+
|
|
235
|
+
# 2. Then install simple-sam2
|
|
236
|
+
pip install simple-sam2
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
> **Note:** SAM2 is a dependency which is installed from Meta's GitHub repo. You still need to **download the model weights** separately (see below).
|
|
240
|
+
|
|
241
|
+
### Download SAM2 weights
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Tiny (fastest)
|
|
245
|
+
wget https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt
|
|
246
|
+
|
|
247
|
+
# Small
|
|
248
|
+
wget https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt
|
|
249
|
+
|
|
250
|
+
# Base+
|
|
251
|
+
wget https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt
|
|
252
|
+
|
|
253
|
+
# Large (most accurate)
|
|
254
|
+
wget https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The matching config files are bundled with the `sam2` package — pass the config name directly (e.g. `"sam2.1_hiera_t.yaml"`).
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Quick start
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
from simple_sam2 import SAM2Service
|
|
265
|
+
|
|
266
|
+
CONFIG = "configs/sam2.1/sam2.1_hiera_t.yaml" # or if want to use sam2 then path is :- configs/sam2/sam2_hiera_t.yaml
|
|
267
|
+
WEIGHTS = "path/to/sam2.1_hiera_tiny.pt". # make sure .pt file matches the config
|
|
268
|
+
VIDEO = "path/to/my_video.mp4"
|
|
269
|
+
|
|
270
|
+
#Note:- you only have to download weights (.pt) files, config files are already present at configs/ dir of sam2
|
|
271
|
+
|
|
272
|
+
svc = SAM2Service(cfg=CONFIG, ckpt=WEIGHTS, batch_size=10)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 1. Initialise the video
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
info = svc.init_video("demo", video_path=VIDEO)
|
|
279
|
+
print(f"Video has {info['total_frames']} frames")
|
|
280
|
+
print(f"Frames extracted to: {info['frame_dir']}")
|
|
281
|
+
print(f"Masks will be saved to: {info['masks_dir']}")
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
This creates the following layout under `simple_sam2_storage/` in your current directory:
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
simple_sam2_storage/
|
|
288
|
+
└── demo/
|
|
289
|
+
├── frames/ ← extracted JPEG frames (00000.jpg, 00001.jpg, …)
|
|
290
|
+
├── masks/ ← output masks written here
|
|
291
|
+
└── tmp_batches/ ← transient working dirs (auto-managed)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
If frames are already extracted from a previous run, extraction is skipped automatically.
|
|
295
|
+
|
|
296
|
+
### 2. Add prompts
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
# Positive click only
|
|
300
|
+
svc.add_prompts("demo", frame_idx=0, obj_id=1, pos_points=[[320, 240]])
|
|
301
|
+
|
|
302
|
+
# Or mix points + bounding box
|
|
303
|
+
svc.add_prompts(
|
|
304
|
+
"demo", frame_idx=0, obj_id=2,
|
|
305
|
+
pos_points=[[400, 300]],
|
|
306
|
+
neg_points=[[100, 100]],
|
|
307
|
+
box=[200, 150, 600, 480],
|
|
308
|
+
)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 3. Propagate and save
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
n = svc.propagate_and_save(
|
|
315
|
+
"demo",
|
|
316
|
+
start_frame_idx=0,
|
|
317
|
+
end_frame_idx=5, # optional, defaults to end of video
|
|
318
|
+
obj_labels={"1": "person", "2": "car"},
|
|
319
|
+
progress_callback=lambda p: print(f"Progress: {p:.1f}%"),
|
|
320
|
+
)
|
|
321
|
+
print(f"Done! Saved {n} masks to {info['masks_dir']}")
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Output filenames follow the pattern `<frame_index>_<obj_id>_<label>.png`:
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
masks/
|
|
328
|
+
├── 00000_1_person.png
|
|
329
|
+
├── 00001_1_person.png
|
|
330
|
+
├── 00000_2_car.png
|
|
331
|
+
...
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### 4. Clean up
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
svc.clear_video("demo") # free GPU memory
|
|
338
|
+
svc.clear_video("demo", delete_storage= True) # delete all video related frames, tmp_batches, masks
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## API reference
|
|
344
|
+
|
|
345
|
+
### `SAM2Service(cfg, ckpt, batch_size=10, storage_dir=...)`
|
|
346
|
+
|
|
347
|
+
| Parameter | Description |
|
|
348
|
+
|---|---|
|
|
349
|
+
| `cfg` | SAM2 YAML config name concatenated to configs/sam2.1/ for sam2.1 or configs/sam2/ for sam2 (e.g. `"configs/sam2.1/sam2.1_hiera_t.yaml"`) |
|
|
350
|
+
| `ckpt` | Path to SAM2 `.pt` checkpoint file |
|
|
351
|
+
| `batch_size` | Frames in memory at once. Reduce if you run out of GPU memory |
|
|
352
|
+
| `storage_dir` | Root directory for all data. Defaults to `<cwd>/simple_sam2_storage` |
|
|
353
|
+
|
|
354
|
+
### `init_video(video_name, video_path)`
|
|
355
|
+
|
|
356
|
+
Extracts frames and sets up storage. Returns a dict with `total_frames`, `total_batches`, `batch_size`, `frame_dir`, `masks_dir`.
|
|
357
|
+
|
|
358
|
+
### `add_prompts(video_name, frame_idx, obj_id, pos_points, neg_points, box, binary_mask)`
|
|
359
|
+
|
|
360
|
+
All prompt types are optional — provide at least one. Returns a uint8 preview mask (0 or 255).
|
|
361
|
+
|
|
362
|
+
### `propagate_and_save(video_name, out_dir, start_frame_idx, end_frame_idx, obj_labels, progress_callback)`
|
|
363
|
+
|
|
364
|
+
Propagates all tracked objects and saves mask PNGs. `out_dir` defaults to `simple_sam2_storage/<video_name>/masks/`. Returns the number of files saved.
|
|
365
|
+
|
|
366
|
+
### `clear_video(video_name, delete_storag=False)`
|
|
367
|
+
|
|
368
|
+
Frees GPU memory and removes temp files. Pass `delete_storage= True` to also delete the extracted frames,masks directory.
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## License
|
|
373
|
+
|
|
374
|
+
Apache 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
375
|
+
|
|
376
|
+
SAM2 is © Meta Platforms, Inc. and affiliates, also under Apache 2.0.
|