Zeeshan01 commited on
Commit
04daa95
1 Parent(s): 923f1cd

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +17 -35
  2. .gitignore +14 -0
  3. LICENSE.txt +661 -0
  4. Pytorch-Correlation-extension/.gitignore +1 -0
  5. Pytorch-Correlation-extension/Correlation_Module/correlation.cpp +178 -0
  6. Pytorch-Correlation-extension/Correlation_Module/correlation_cuda_kernel.cu +327 -0
  7. Pytorch-Correlation-extension/Correlation_Module/correlation_sampler.cpp +138 -0
  8. Pytorch-Correlation-extension/Correlation_Module/spatial_correlation_sampler/__init__.py +1 -0
  9. Pytorch-Correlation-extension/Correlation_Module/spatial_correlation_sampler/spatial_correlation_sampler.py +107 -0
  10. Pytorch-Correlation-extension/LICENSE +21 -0
  11. Pytorch-Correlation-extension/README.md +146 -0
  12. Pytorch-Correlation-extension/benchmark.py +90 -0
  13. Pytorch-Correlation-extension/check.py +119 -0
  14. Pytorch-Correlation-extension/grad_check.py +47 -0
  15. Pytorch-Correlation-extension/requirements.txt +2 -0
  16. Pytorch-Correlation-extension/setup.py +69 -0
  17. Pytorch-Correlation-extension/setup_cpu.py +4 -0
  18. README.md +213 -8
  19. SegTracker.py +264 -0
  20. __pycache__/SegTracker.cpython-310.pyc +0 -0
  21. __pycache__/aot_tracker.cpython-310.pyc +0 -0
  22. __pycache__/model_args.cpython-310.pyc +0 -0
  23. __pycache__/seg_track_anything.cpython-310.pyc +0 -0
  24. aot/LICENSE +29 -0
  25. aot/MODEL_ZOO.md +115 -0
  26. aot/README.md +152 -0
  27. aot/__init__.py +0 -0
  28. aot/__pycache__/__init__.cpython-310.pyc +0 -0
  29. aot/configs/default.py +138 -0
  30. aot/configs/models/aotb.py +9 -0
  31. aot/configs/models/aotl.py +13 -0
  32. aot/configs/models/aots.py +9 -0
  33. aot/configs/models/aott.py +7 -0
  34. aot/configs/models/deaotb.py +9 -0
  35. aot/configs/models/deaotl.py +13 -0
  36. aot/configs/models/deaots.py +9 -0
  37. aot/configs/models/deaott.py +7 -0
  38. aot/configs/models/default.py +27 -0
  39. aot/configs/models/default_deaot.py +17 -0
  40. aot/configs/models/r101_aotl.py +16 -0
  41. aot/configs/models/r50_aotl.py +16 -0
  42. aot/configs/models/r50_deaotl.py +16 -0
  43. aot/configs/models/rs101_aotl.py +16 -0
  44. aot/configs/models/swinb_aotl.py +17 -0
  45. aot/configs/models/swinb_deaotl.py +17 -0
  46. aot/configs/pre.py +19 -0
  47. aot/configs/pre_dav.py +21 -0
  48. aot/configs/pre_ytb.py +17 -0
  49. aot/configs/pre_ytb_dav.py +19 -0
  50. aot/configs/ytb.py +10 -0
.gitattributes CHANGED
@@ -1,35 +1,17 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+ assets/840_iSXIa0hE8Ek.zip filter=lfs diff=lfs merge=lfs -text
4
+ assets/cars.mp4 filter=lfs diff=lfs merge=lfs -text
5
+ assets/cell.mp4 filter=lfs diff=lfs merge=lfs -text
6
+ assets/demo_3x2.gif filter=lfs diff=lfs merge=lfs -text
7
+ assets/top.gif filter=lfs diff=lfs merge=lfs -text
8
+ ckpt/groundingdino_swint_ogc.pth filter=lfs diff=lfs merge=lfs -text
9
+ ckpt/sam_vit_b_01ec64.pth filter=lfs diff=lfs merge=lfs -text
10
+ sam/assets/masks1.png filter=lfs diff=lfs merge=lfs -text
11
+ sam/assets/notebook2.png filter=lfs diff=lfs merge=lfs -text
12
+ src/groundingdino/.asset/GD_GLIGEN.png filter=lfs diff=lfs merge=lfs -text
13
+ src/groundingdino/.asset/GD_SD.png filter=lfs diff=lfs merge=lfs -text
14
+ src/groundingdino/.asset/hero_figure.png filter=lfs diff=lfs merge=lfs -text
15
+ tutorial/img/click_segment.jpg filter=lfs diff=lfs merge=lfs -text
16
+ tutorial/img/input_video.jpg filter=lfs diff=lfs merge=lfs -text
17
+ tutorial/img/start_tracking.jpg filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .vscode
2
+ ckpt/*
3
+ assets/*masks
4
+ assets/*mp4
5
+ # assets/*zip
6
+ assets/*gif
7
+ *.pyc
8
+ debug
9
+ cym_utils
10
+ /src
11
+ /tracking_results
12
+ /aot/results
13
+ /aot/pretrain_models
14
+ /aot/datasets
LICENSE.txt ADDED
@@ -0,0 +1,661 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU Affero General Public License is a free, copyleft license for
11
+ software and other kinds of works, specifically designed to ensure
12
+ cooperation with the community in the case of network server software.
13
+
14
+ The licenses for most software and other practical works are designed
15
+ to take away your freedom to share and change the works. By contrast,
16
+ our General Public Licenses are intended to guarantee your freedom to
17
+ share and change all versions of a program--to make sure it remains free
18
+ software for all its users.
19
+
20
+ When we speak of free software, we are referring to freedom, not
21
+ price. Our General Public Licenses are designed to make sure that you
22
+ have the freedom to distribute copies of free software (and charge for
23
+ them if you wish), that you receive source code or can get it if you
24
+ want it, that you can change the software or use pieces of it in new
25
+ free programs, and that you know you can do these things.
26
+
27
+ Developers that use our General Public Licenses protect your rights
28
+ with two steps: (1) assert copyright on the software, and (2) offer
29
+ you this License which gives you legal permission to copy, distribute
30
+ and/or modify the software.
31
+
32
+ A secondary benefit of defending all users' freedom is that
33
+ improvements made in alternate versions of the program, if they
34
+ receive widespread use, become available for other developers to
35
+ incorporate. Many developers of free software are heartened and
36
+ encouraged by the resulting cooperation. However, in the case of
37
+ software used on network servers, this result may fail to come about.
38
+ The GNU General Public License permits making a modified version and
39
+ letting the public access it on a server without ever releasing its
40
+ source code to the public.
41
+
42
+ The GNU Affero General Public License is designed specifically to
43
+ ensure that, in such cases, the modified source code becomes available
44
+ to the community. It requires the operator of a network server to
45
+ provide the source code of the modified version running there to the
46
+ users of that server. Therefore, public use of a modified version, on
47
+ a publicly accessible server, gives the public access to the source
48
+ code of the modified version.
49
+
50
+ An older license, called the Affero General Public License and
51
+ published by Affero, was designed to accomplish similar goals. This is
52
+ a different license, not a version of the Affero GPL, but Affero has
53
+ released a new version of the Affero GPL which permits relicensing under
54
+ this license.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ TERMS AND CONDITIONS
60
+
61
+ 0. Definitions.
62
+
63
+ "This License" refers to version 3 of the GNU Affero General Public License.
64
+
65
+ "Copyright" also means copyright-like laws that apply to other kinds of
66
+ works, such as semiconductor masks.
67
+
68
+ "The Program" refers to any copyrightable work licensed under this
69
+ License. Each licensee is addressed as "you". "Licensees" and
70
+ "recipients" may be individuals or organizations.
71
+
72
+ To "modify" a work means to copy from or adapt all or part of the work
73
+ in a fashion requiring copyright permission, other than the making of an
74
+ exact copy. The resulting work is called a "modified version" of the
75
+ earlier work or a work "based on" the earlier work.
76
+
77
+ A "covered work" means either the unmodified Program or a work based
78
+ on the Program.
79
+
80
+ To "propagate" a work means to do anything with it that, without
81
+ permission, would make you directly or secondarily liable for
82
+ infringement under applicable copyright law, except executing it on a
83
+ computer or modifying a private copy. Propagation includes copying,
84
+ distribution (with or without modification), making available to the
85
+ public, and in some countries other activities as well.
86
+
87
+ To "convey" a work means any kind of propagation that enables other
88
+ parties to make or receive copies. Mere interaction with a user through
89
+ a computer network, with no transfer of a copy, is not conveying.
90
+
91
+ An interactive user interface displays "Appropriate Legal Notices"
92
+ to the extent that it includes a convenient and prominently visible
93
+ feature that (1) displays an appropriate copyright notice, and (2)
94
+ tells the user that there is no warranty for the work (except to the
95
+ extent that warranties are provided), that licensees may convey the
96
+ work under this License, and how to view a copy of this License. If
97
+ the interface presents a list of user commands or options, such as a
98
+ menu, a prominent item in the list meets this criterion.
99
+
100
+ 1. Source Code.
101
+
102
+ The "source code" for a work means the preferred form of the work
103
+ for making modifications to it. "Object code" means any non-source
104
+ form of a work.
105
+
106
+ A "Standard Interface" means an interface that either is an official
107
+ standard defined by a recognized standards body, or, in the case of
108
+ interfaces specified for a particular programming language, one that
109
+ is widely used among developers working in that language.
110
+
111
+ The "System Libraries" of an executable work include anything, other
112
+ than the work as a whole, that (a) is included in the normal form of
113
+ packaging a Major Component, but which is not part of that Major
114
+ Component, and (b) serves only to enable use of the work with that
115
+ Major Component, or to implement a Standard Interface for which an
116
+ implementation is available to the public in source code form. A
117
+ "Major Component", in this context, means a major essential component
118
+ (kernel, window system, and so on) of the specific operating system
119
+ (if any) on which the executable work runs, or a compiler used to
120
+ produce the work, or an object code interpreter used to run it.
121
+
122
+ The "Corresponding Source" for a work in object code form means all
123
+ the source code needed to generate, install, and (for an executable
124
+ work) run the object code and to modify the work, including scripts to
125
+ control those activities. However, it does not include the work's
126
+ System Libraries, or general-purpose tools or generally available free
127
+ programs which are used unmodified in performing those activities but
128
+ which are not part of the work. For example, Corresponding Source
129
+ includes interface definition files associated with source files for
130
+ the work, and the source code for shared libraries and dynamically
131
+ linked subprograms that the work is specifically designed to require,
132
+ such as by intimate data communication or control flow between those
133
+ subprograms and other parts of the work.
134
+
135
+ The Corresponding Source need not include anything that users
136
+ can regenerate automatically from other parts of the Corresponding
137
+ Source.
138
+
139
+ The Corresponding Source for a work in source code form is that
140
+ same work.
141
+
142
+ 2. Basic Permissions.
143
+
144
+ All rights granted under this License are granted for the term of
145
+ copyright on the Program, and are irrevocable provided the stated
146
+ conditions are met. This License explicitly affirms your unlimited
147
+ permission to run the unmodified Program. The output from running a
148
+ covered work is covered by this License only if the output, given its
149
+ content, constitutes a covered work. This License acknowledges your
150
+ rights of fair use or other equivalent, as provided by copyright law.
151
+
152
+ You may make, run and propagate covered works that you do not
153
+ convey, without conditions so long as your license otherwise remains
154
+ in force. You may convey covered works to others for the sole purpose
155
+ of having them make modifications exclusively for you, or provide you
156
+ with facilities for running those works, provided that you comply with
157
+ the terms of this License in conveying all material for which you do
158
+ not control copyright. Those thus making or running the covered works
159
+ for you must do so exclusively on your behalf, under your direction
160
+ and control, on terms that prohibit them from making any copies of
161
+ your copyrighted material outside their relationship with you.
162
+
163
+ Conveying under any other circumstances is permitted solely under
164
+ the conditions stated below. Sublicensing is not allowed; section 10
165
+ makes it unnecessary.
166
+
167
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168
+
169
+ No covered work shall be deemed part of an effective technological
170
+ measure under any applicable law fulfilling obligations under article
171
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172
+ similar laws prohibiting or restricting circumvention of such
173
+ measures.
174
+
175
+ When you convey a covered work, you waive any legal power to forbid
176
+ circumvention of technological measures to the extent such circumvention
177
+ is effected by exercising rights under this License with respect to
178
+ the covered work, and you disclaim any intention to limit operation or
179
+ modification of the work as a means of enforcing, against the work's
180
+ users, your or third parties' legal rights to forbid circumvention of
181
+ technological measures.
182
+
183
+ 4. Conveying Verbatim Copies.
184
+
185
+ You may convey verbatim copies of the Program's source code as you
186
+ receive it, in any medium, provided that you conspicuously and
187
+ appropriately publish on each copy an appropriate copyright notice;
188
+ keep intact all notices stating that this License and any
189
+ non-permissive terms added in accord with section 7 apply to the code;
190
+ keep intact all notices of the absence of any warranty; and give all
191
+ recipients a copy of this License along with the Program.
192
+
193
+ You may charge any price or no price for each copy that you convey,
194
+ and you may offer support or warranty protection for a fee.
195
+
196
+ 5. Conveying Modified Source Versions.
197
+
198
+ You may convey a work based on the Program, or the modifications to
199
+ produce it from the Program, in the form of source code under the
200
+ terms of section 4, provided that you also meet all of these conditions:
201
+
202
+ a) The work must carry prominent notices stating that you modified
203
+ it, and giving a relevant date.
204
+
205
+ b) The work must carry prominent notices stating that it is
206
+ released under this License and any conditions added under section
207
+ 7. This requirement modifies the requirement in section 4 to
208
+ "keep intact all notices".
209
+
210
+ c) You must license the entire work, as a whole, under this
211
+ License to anyone who comes into possession of a copy. This
212
+ License will therefore apply, along with any applicable section 7
213
+ additional terms, to the whole of the work, and all its parts,
214
+ regardless of how they are packaged. This License gives no
215
+ permission to license the work in any other way, but it does not
216
+ invalidate such permission if you have separately received it.
217
+
218
+ d) If the work has interactive user interfaces, each must display
219
+ Appropriate Legal Notices; however, if the Program has interactive
220
+ interfaces that do not display Appropriate Legal Notices, your
221
+ work need not make them do so.
222
+
223
+ A compilation of a covered work with other separate and independent
224
+ works, which are not by their nature extensions of the covered work,
225
+ and which are not combined with it such as to form a larger program,
226
+ in or on a volume of a storage or distribution medium, is called an
227
+ "aggregate" if the compilation and its resulting copyright are not
228
+ used to limit the access or legal rights of the compilation's users
229
+ beyond what the individual works permit. Inclusion of a covered work
230
+ in an aggregate does not cause this License to apply to the other
231
+ parts of the aggregate.
232
+
233
+ 6. Conveying Non-Source Forms.
234
+
235
+ You may convey a covered work in object code form under the terms
236
+ of sections 4 and 5, provided that you also convey the
237
+ machine-readable Corresponding Source under the terms of this License,
238
+ in one of these ways:
239
+
240
+ a) Convey the object code in, or embodied in, a physical product
241
+ (including a physical distribution medium), accompanied by the
242
+ Corresponding Source fixed on a durable physical medium
243
+ customarily used for software interchange.
244
+
245
+ b) Convey the object code in, or embodied in, a physical product
246
+ (including a physical distribution medium), accompanied by a
247
+ written offer, valid for at least three years and valid for as
248
+ long as you offer spare parts or customer support for that product
249
+ model, to give anyone who possesses the object code either (1) a
250
+ copy of the Corresponding Source for all the software in the
251
+ product that is covered by this License, on a durable physical
252
+ medium customarily used for software interchange, for a price no
253
+ more than your reasonable cost of physically performing this
254
+ conveying of source, or (2) access to copy the
255
+ Corresponding Source from a network server at no charge.
256
+
257
+ c) Convey individual copies of the object code with a copy of the
258
+ written offer to provide the Corresponding Source. This
259
+ alternative is allowed only occasionally and noncommercially, and
260
+ only if you received the object code with such an offer, in accord
261
+ with subsection 6b.
262
+
263
+ d) Convey the object code by offering access from a designated
264
+ place (gratis or for a charge), and offer equivalent access to the
265
+ Corresponding Source in the same way through the same place at no
266
+ further charge. You need not require recipients to copy the
267
+ Corresponding Source along with the object code. If the place to
268
+ copy the object code is a network server, the Corresponding Source
269
+ may be on a different server (operated by you or a third party)
270
+ that supports equivalent copying facilities, provided you maintain
271
+ clear directions next to the object code saying where to find the
272
+ Corresponding Source. Regardless of what server hosts the
273
+ Corresponding Source, you remain obligated to ensure that it is
274
+ available for as long as needed to satisfy these requirements.
275
+
276
+ e) Convey the object code using peer-to-peer transmission, provided
277
+ you inform other peers where the object code and Corresponding
278
+ Source of the work are being offered to the general public at no
279
+ charge under subsection 6d.
280
+
281
+ A separable portion of the object code, whose source code is excluded
282
+ from the Corresponding Source as a System Library, need not be
283
+ included in conveying the object code work.
284
+
285
+ A "User Product" is either (1) a "consumer product", which means any
286
+ tangible personal property which is normally used for personal, family,
287
+ or household purposes, or (2) anything designed or sold for incorporation
288
+ into a dwelling. In determining whether a product is a consumer product,
289
+ doubtful cases shall be resolved in favor of coverage. For a particular
290
+ product received by a particular user, "normally used" refers to a
291
+ typical or common use of that class of product, regardless of the status
292
+ of the particular user or of the way in which the particular user
293
+ actually uses, or expects or is expected to use, the product. A product
294
+ is a consumer product regardless of whether the product has substantial
295
+ commercial, industrial or non-consumer uses, unless such uses represent
296
+ the only significant mode of use of the product.
297
+
298
+ "Installation Information" for a User Product means any methods,
299
+ procedures, authorization keys, or other information required to install
300
+ and execute modified versions of a covered work in that User Product from
301
+ a modified version of its Corresponding Source. The information must
302
+ suffice to ensure that the continued functioning of the modified object
303
+ code is in no case prevented or interfered with solely because
304
+ modification has been made.
305
+
306
+ If you convey an object code work under this section in, or with, or
307
+ specifically for use in, a User Product, and the conveying occurs as
308
+ part of a transaction in which the right of possession and use of the
309
+ User Product is transferred to the recipient in perpetuity or for a
310
+ fixed term (regardless of how the transaction is characterized), the
311
+ Corresponding Source conveyed under this section must be accompanied
312
+ by the Installation Information. But this requirement does not apply
313
+ if neither you nor any third party retains the ability to install
314
+ modified object code on the User Product (for example, the work has
315
+ been installed in ROM).
316
+
317
+ The requirement to provide Installation Information does not include a
318
+ requirement to continue to provide support service, warranty, or updates
319
+ for a work that has been modified or installed by the recipient, or for
320
+ the User Product in which it has been modified or installed. Access to a
321
+ network may be denied when the modification itself materially and
322
+ adversely affects the operation of the network or violates the rules and
323
+ protocols for communication across the network.
324
+
325
+ Corresponding Source conveyed, and Installation Information provided,
326
+ in accord with this section must be in a format that is publicly
327
+ documented (and with an implementation available to the public in
328
+ source code form), and must require no special password or key for
329
+ unpacking, reading or copying.
330
+
331
+ 7. Additional Terms.
332
+
333
+ "Additional permissions" are terms that supplement the terms of this
334
+ License by making exceptions from one or more of its conditions.
335
+ Additional permissions that are applicable to the entire Program shall
336
+ be treated as though they were included in this License, to the extent
337
+ that they are valid under applicable law. If additional permissions
338
+ apply only to part of the Program, that part may be used separately
339
+ under those permissions, but the entire Program remains governed by
340
+ this License without regard to the additional permissions.
341
+
342
+ When you convey a copy of a covered work, you may at your option
343
+ remove any additional permissions from that copy, or from any part of
344
+ it. (Additional permissions may be written to require their own
345
+ removal in certain cases when you modify the work.) You may place
346
+ additional permissions on material, added by you to a covered work,
347
+ for which you have or can give appropriate copyright permission.
348
+
349
+ Notwithstanding any other provision of this License, for material you
350
+ add to a covered work, you may (if authorized by the copyright holders of
351
+ that material) supplement the terms of this License with terms:
352
+
353
+ a) Disclaiming warranty or limiting liability differently from the
354
+ terms of sections 15 and 16 of this License; or
355
+
356
+ b) Requiring preservation of specified reasonable legal notices or
357
+ author attributions in that material or in the Appropriate Legal
358
+ Notices displayed by works containing it; or
359
+
360
+ c) Prohibiting misrepresentation of the origin of that material, or
361
+ requiring that modified versions of such material be marked in
362
+ reasonable ways as different from the original version; or
363
+
364
+ d) Limiting the use for publicity purposes of names of licensors or
365
+ authors of the material; or
366
+
367
+ e) Declining to grant rights under trademark law for use of some
368
+ trade names, trademarks, or service marks; or
369
+
370
+ f) Requiring indemnification of licensors and authors of that
371
+ material by anyone who conveys the material (or modified versions of
372
+ it) with contractual assumptions of liability to the recipient, for
373
+ any liability that these contractual assumptions directly impose on
374
+ those licensors and authors.
375
+
376
+ All other non-permissive additional terms are considered "further
377
+ restrictions" within the meaning of section 10. If the Program as you
378
+ received it, or any part of it, contains a notice stating that it is
379
+ governed by this License along with a term that is a further
380
+ restriction, you may remove that term. If a license document contains
381
+ a further restriction but permits relicensing or conveying under this
382
+ License, you may add to a covered work material governed by the terms
383
+ of that license document, provided that the further restriction does
384
+ not survive such relicensing or conveying.
385
+
386
+ If you add terms to a covered work in accord with this section, you
387
+ must place, in the relevant source files, a statement of the
388
+ additional terms that apply to those files, or a notice indicating
389
+ where to find the applicable terms.
390
+
391
+ Additional terms, permissive or non-permissive, may be stated in the
392
+ form of a separately written license, or stated as exceptions;
393
+ the above requirements apply either way.
394
+
395
+ 8. Termination.
396
+
397
+ You may not propagate or modify a covered work except as expressly
398
+ provided under this License. Any attempt otherwise to propagate or
399
+ modify it is void, and will automatically terminate your rights under
400
+ this License (including any patent licenses granted under the third
401
+ paragraph of section 11).
402
+
403
+ However, if you cease all violation of this License, then your
404
+ license from a particular copyright holder is reinstated (a)
405
+ provisionally, unless and until the copyright holder explicitly and
406
+ finally terminates your license, and (b) permanently, if the copyright
407
+ holder fails to notify you of the violation by some reasonable means
408
+ prior to 60 days after the cessation.
409
+
410
+ Moreover, your license from a particular copyright holder is
411
+ reinstated permanently if the copyright holder notifies you of the
412
+ violation by some reasonable means, this is the first time you have
413
+ received notice of violation of this License (for any work) from that
414
+ copyright holder, and you cure the violation prior to 30 days after
415
+ your receipt of the notice.
416
+
417
+ Termination of your rights under this section does not terminate the
418
+ licenses of parties who have received copies or rights from you under
419
+ this License. If your rights have been terminated and not permanently
420
+ reinstated, you do not qualify to receive new licenses for the same
421
+ material under section 10.
422
+
423
+ 9. Acceptance Not Required for Having Copies.
424
+
425
+ You are not required to accept this License in order to receive or
426
+ run a copy of the Program. Ancillary propagation of a covered work
427
+ occurring solely as a consequence of using peer-to-peer transmission
428
+ to receive a copy likewise does not require acceptance. However,
429
+ nothing other than this License grants you permission to propagate or
430
+ modify any covered work. These actions infringe copyright if you do
431
+ not accept this License. Therefore, by modifying or propagating a
432
+ covered work, you indicate your acceptance of this License to do so.
433
+
434
+ 10. Automatic Licensing of Downstream Recipients.
435
+
436
+ Each time you convey a covered work, the recipient automatically
437
+ receives a license from the original licensors, to run, modify and
438
+ propagate that work, subject to this License. You are not responsible
439
+ for enforcing compliance by third parties with this License.
440
+
441
+ An "entity transaction" is a transaction transferring control of an
442
+ organization, or substantially all assets of one, or subdividing an
443
+ organization, or merging organizations. If propagation of a covered
444
+ work results from an entity transaction, each party to that
445
+ transaction who receives a copy of the work also receives whatever
446
+ licenses to the work the party's predecessor in interest had or could
447
+ give under the previous paragraph, plus a right to possession of the
448
+ Corresponding Source of the work from the predecessor in interest, if
449
+ the predecessor has it or can get it with reasonable efforts.
450
+
451
+ You may not impose any further restrictions on the exercise of the
452
+ rights granted or affirmed under this License. For example, you may
453
+ not impose a license fee, royalty, or other charge for exercise of
454
+ rights granted under this License, and you may not initiate litigation
455
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
456
+ any patent claim is infringed by making, using, selling, offering for
457
+ sale, or importing the Program or any portion of it.
458
+
459
+ 11. Patents.
460
+
461
+ A "contributor" is a copyright holder who authorizes use under this
462
+ License of the Program or a work on which the Program is based. The
463
+ work thus licensed is called the contributor's "contributor version".
464
+
465
+ A contributor's "essential patent claims" are all patent claims
466
+ owned or controlled by the contributor, whether already acquired or
467
+ hereafter acquired, that would be infringed by some manner, permitted
468
+ by this License, of making, using, or selling its contributor version,
469
+ but do not include claims that would be infringed only as a
470
+ consequence of further modification of the contributor version. For
471
+ purposes of this definition, "control" includes the right to grant
472
+ patent sublicenses in a manner consistent with the requirements of
473
+ this License.
474
+
475
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
476
+ patent license under the contributor's essential patent claims, to
477
+ make, use, sell, offer for sale, import and otherwise run, modify and
478
+ propagate the contents of its contributor version.
479
+
480
+ In the following three paragraphs, a "patent license" is any express
481
+ agreement or commitment, however denominated, not to enforce a patent
482
+ (such as an express permission to practice a patent or covenant not to
483
+ sue for patent infringement). To "grant" such a patent license to a
484
+ party means to make such an agreement or commitment not to enforce a
485
+ patent against the party.
486
+
487
+ If you convey a covered work, knowingly relying on a patent license,
488
+ and the Corresponding Source of the work is not available for anyone
489
+ to copy, free of charge and under the terms of this License, through a
490
+ publicly available network server or other readily accessible means,
491
+ then you must either (1) cause the Corresponding Source to be so
492
+ available, or (2) arrange to deprive yourself of the benefit of the
493
+ patent license for this particular work, or (3) arrange, in a manner
494
+ consistent with the requirements of this License, to extend the patent
495
+ license to downstream recipients. "Knowingly relying" means you have
496
+ actual knowledge that, but for the patent license, your conveying the
497
+ covered work in a country, or your recipient's use of the covered work
498
+ in a country, would infringe one or more identifiable patents in that
499
+ country that you have reason to believe are valid.
500
+
501
+ If, pursuant to or in connection with a single transaction or
502
+ arrangement, you convey, or propagate by procuring conveyance of, a
503
+ covered work, and grant a patent license to some of the parties
504
+ receiving the covered work authorizing them to use, propagate, modify
505
+ or convey a specific copy of the covered work, then the patent license
506
+ you grant is automatically extended to all recipients of the covered
507
+ work and works based on it.
508
+
509
+ A patent license is "discriminatory" if it does not include within
510
+ the scope of its coverage, prohibits the exercise of, or is
511
+ conditioned on the non-exercise of one or more of the rights that are
512
+ specifically granted under this License. You may not convey a covered
513
+ work if you are a party to an arrangement with a third party that is
514
+ in the business of distributing software, under which you make payment
515
+ to the third party based on the extent of your activity of conveying
516
+ the work, and under which the third party grants, to any of the
517
+ parties who would receive the covered work from you, a discriminatory
518
+ patent license (a) in connection with copies of the covered work
519
+ conveyed by you (or copies made from those copies), or (b) primarily
520
+ for and in connection with specific products or compilations that
521
+ contain the covered work, unless you entered into that arrangement,
522
+ or that patent license was granted, prior to 28 March 2007.
523
+
524
+ Nothing in this License shall be construed as excluding or limiting
525
+ any implied license or other defenses to infringement that may
526
+ otherwise be available to you under applicable patent law.
527
+
528
+ 12. No Surrender of Others' Freedom.
529
+
530
+ If conditions are imposed on you (whether by court order, agreement or
531
+ otherwise) that contradict the conditions of this License, they do not
532
+ excuse you from the conditions of this License. If you cannot convey a
533
+ covered work so as to satisfy simultaneously your obligations under this
534
+ License and any other pertinent obligations, then as a consequence you may
535
+ not convey it at all. For example, if you agree to terms that obligate you
536
+ to collect a royalty for further conveying from those to whom you convey
537
+ the Program, the only way you could satisfy both those terms and this
538
+ License would be to refrain entirely from conveying the Program.
539
+
540
+ 13. Remote Network Interaction; Use with the GNU General Public License.
541
+
542
+ Notwithstanding any other provision of this License, if you modify the
543
+ Program, your modified version must prominently offer all users
544
+ interacting with it remotely through a computer network (if your version
545
+ supports such interaction) an opportunity to receive the Corresponding
546
+ Source of your version by providing access to the Corresponding Source
547
+ from a network server at no charge, through some standard or customary
548
+ means of facilitating copying of software. This Corresponding Source
549
+ shall include the Corresponding Source for any work covered by version 3
550
+ of the GNU General Public License that is incorporated pursuant to the
551
+ following paragraph.
552
+
553
+ Notwithstanding any other provision of this License, you have
554
+ permission to link or combine any covered work with a work licensed
555
+ under version 3 of the GNU General Public License into a single
556
+ combined work, and to convey the resulting work. The terms of this
557
+ License will continue to apply to the part which is the covered work,
558
+ but the work with which it is combined will remain governed by version
559
+ 3 of the GNU General Public License.
560
+
561
+ 14. Revised Versions of this License.
562
+
563
+ The Free Software Foundation may publish revised and/or new versions of
564
+ the GNU Affero General Public License from time to time. Such new versions
565
+ will be similar in spirit to the present version, but may differ in detail to
566
+ address new problems or concerns.
567
+
568
+ Each version is given a distinguishing version number. If the
569
+ Program specifies that a certain numbered version of the GNU Affero General
570
+ Public License "or any later version" applies to it, you have the
571
+ option of following the terms and conditions either of that numbered
572
+ version or of any later version published by the Free Software
573
+ Foundation. If the Program does not specify a version number of the
574
+ GNU Affero General Public License, you may choose any version ever published
575
+ by the Free Software Foundation.
576
+
577
+ If the Program specifies that a proxy can decide which future
578
+ versions of the GNU Affero General Public License can be used, that proxy's
579
+ public statement of acceptance of a version permanently authorizes you
580
+ to choose that version for the Program.
581
+
582
+ Later license versions may give you additional or different
583
+ permissions. However, no additional obligations are imposed on any
584
+ author or copyright holder as a result of your choosing to follow a
585
+ later version.
586
+
587
+ 15. Disclaimer of Warranty.
588
+
589
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597
+
598
+ 16. Limitation of Liability.
599
+
600
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608
+ SUCH DAMAGES.
609
+
610
+ 17. Interpretation of Sections 15 and 16.
611
+
612
+ If the disclaimer of warranty and limitation of liability provided
613
+ above cannot be given local legal effect according to their terms,
614
+ reviewing courts shall apply local law that most closely approximates
615
+ an absolute waiver of all civil liability in connection with the
616
+ Program, unless a warranty or assumption of liability accompanies a
617
+ copy of the Program in return for a fee.
618
+
619
+ END OF TERMS AND CONDITIONS
620
+
621
+ How to Apply These Terms to Your New Programs
622
+
623
+ If you develop a new program, and you want it to be of the greatest
624
+ possible use to the public, the best way to achieve this is to make it
625
+ free software which everyone can redistribute and change under these terms.
626
+
627
+ To do so, attach the following notices to the program. It is safest
628
+ to attach them to the start of each source file to most effectively
629
+ state the exclusion of warranty; and each file should have at least
630
+ the "copyright" line and a pointer to where the full notice is found.
631
+
632
+ <one line to give the program's name and a brief idea of what it does.>
633
+ Copyright (C) <year> <name of author>
634
+
635
+ This program is free software: you can redistribute it and/or modify
636
+ it under the terms of the GNU Affero General Public License as published
637
+ by the Free Software Foundation, either version 3 of the License, or
638
+ (at your option) any later version.
639
+
640
+ This program is distributed in the hope that it will be useful,
641
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
642
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643
+ GNU Affero General Public License for more details.
644
+
645
+ You should have received a copy of the GNU Affero General Public License
646
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
647
+
648
+ Also add information on how to contact you by electronic and paper mail.
649
+
650
+ If your software can interact with users remotely through a computer
651
+ network, you should also make sure that it provides a way for users to
652
+ get its source. For example, if your program is a web application, its
653
+ interface could display a "Source" link that leads users to an archive
654
+ of the code. There are many ways you could offer source, and different
655
+ solutions will be better for different programs; see section 13 for the
656
+ specific requirements.
657
+
658
+ You should also get your employer (if you work as a programmer) or school,
659
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
660
+ For more information on this, and how to apply and follow the GNU AGPL, see
661
+ <https://www.gnu.org/licenses/>.
Pytorch-Correlation-extension/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ *.egg*
Pytorch-Correlation-extension/Correlation_Module/correlation.cpp ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <torch/extension.h>
2
+ using namespace torch;
3
+
4
+ #include <vector>
5
+
6
+ #define WITHIN_BOUNDS(x, y, H, W) (x >= 0 && x < H && y >= 0 && y < W)
7
+
8
+ template <typename scalar_t>
9
+ static void correlate_patch(
10
+ TensorAccessor<scalar_t,3> input1,
11
+ TensorAccessor<scalar_t,3> input2,
12
+ scalar_t *dst,
13
+ int kH, int kW,
14
+ int dilationH, int dilationW,
15
+ int u, int v,
16
+ int shiftU, int shiftV){
17
+ const int C = input1.size(0);
18
+ const int iH = input1.size(1);
19
+ const int iW = input1.size(2);
20
+ for (int c=0; c<C; ++c){
21
+ for (int i=0; i<kH; ++i){
22
+ int i1 = u + i * dilationH;
23
+ int i2 = i1 + shiftU;
24
+ if WITHIN_BOUNDS(i1, i2, iH, iH){
25
+ for (int j=0; j<kW; ++j){
26
+ int j1 = v + j * dilationW;
27
+ int j2 = j1 + shiftV;
28
+ if WITHIN_BOUNDS(j1, j2, iW, iW){
29
+ scalar_t v1 = input1[c][i1][j1];
30
+ scalar_t v2 = input2[c][i2][j2];
31
+ *dst += v1 * v2;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ template <typename scalar_t>
40
+ static void correlate_patch_grad(
41
+ TensorAccessor<scalar_t,3> input1,
42
+ TensorAccessor<scalar_t,3> gradInput1,
43
+ TensorAccessor<scalar_t,3> input2,
44
+ TensorAccessor<scalar_t,3> gradInput2,
45
+ scalar_t gradOutput,
46
+ int kH, int kW,
47
+ int dilationH, int dilationW,
48
+ int u, int v,
49
+ int shiftU, int shiftV){
50
+
51
+ const int C = input1.size(0);
52
+ const int iH = input1.size(1);
53
+ const int iW = input1.size(2);
54
+
55
+ for (int c=0; c<C; ++c){
56
+ for (int i=0; i<kH; ++i){
57
+ int i1 = u + i * dilationH;
58
+ int i2 = i1 + shiftU;
59
+ if WITHIN_BOUNDS(i1, i2, iH, iH){
60
+ for (int j=0; j<kW; ++j){
61
+ int j1 = v + j * dilationW;
62
+ int j2 = j1 + shiftV;
63
+ if WITHIN_BOUNDS(j1, j2, iW, iW){
64
+ scalar_t v1 = input1[c][i1][j1];
65
+ scalar_t v2 = input2[c][i2][j2];
66
+ gradInput2[c][i2][j2] += gradOutput * v1;
67
+ gradInput1[c][i1][j1] += gradOutput * v2;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ torch::Tensor correlation_cpp_forward(
76
+ torch::Tensor input1,
77
+ torch::Tensor input2,
78
+ int kH, int kW,
79
+ int patchH, int patchW,
80
+ int padH, int padW,
81
+ int dilationH, int dilationW,
82
+ int dilation_patchH, int dilation_patchW,
83
+ int dH, int dW) {
84
+
85
+ const auto batch_size = input1.size(0);
86
+ const auto iH = input1.size(2);
87
+ const auto iW = input1.size(3);
88
+ const int patchRadH = (patchH - 1) / 2;
89
+ const int patchRadW = (patchW - 1) / 2;
90
+ const int dilatedKH = (kH - 1) * dilationH + 1;
91
+ const int dilatedKW = (kW - 1) * dilationW + 1;
92
+
93
+ const auto oH = (iH + 2 * padH - dilatedKH) / dH + 1;
94
+ const auto oW = (iW + 2 * padW - dilatedKW) / dW + 1;
95
+ auto output = at::zeros({batch_size, patchH, patchW, oH, oW}, input1.options());
96
+
97
+ int n, ph, pw, h, w;
98
+ #pragma omp parallel for private(n, ph, pw, h, w) collapse(2)
99
+ for (n = 0; n < batch_size; ++n) {
100
+ for(ph = 0; ph < patchH; ++ph){
101
+ for(pw = 0; pw < patchW; ++pw){
102
+ AT_DISPATCH_FLOATING_TYPES(input1.scalar_type(), "correlation_forward_cpp", ([&] {
103
+ auto input1_acc = input1.accessor<scalar_t, 4>();
104
+ auto input2_acc = input2.accessor<scalar_t, 4>();
105
+ auto output_acc = output.accessor<scalar_t, 5>();
106
+ for (h = 0; h < oH; ++h) {
107
+ for (w = 0; w < oW; ++w) {
108
+ correlate_patch(input1_acc[n],
109
+ input2_acc[n],
110
+ &output_acc[n][ph][pw][h][w],
111
+ kH, kW,
112
+ dilationH, dilationW,
113
+ -padH + h * dH,
114
+ -padW + w * dW,
115
+ (ph - patchRadH) * dilation_patchH,
116
+ (pw - patchRadW) * dilation_patchW);
117
+ }
118
+ }
119
+ }));
120
+ }
121
+ }
122
+ }
123
+ return output;
124
+ }
125
+
126
+ std::vector<torch::Tensor> correlation_cpp_backward(
127
+ torch::Tensor input1,
128
+ torch::Tensor input2,
129
+ torch::Tensor gradOutput,
130
+ int kH, int kW,
131
+ int patchH, int patchW,
132
+ int padH, int padW,
133
+ int dilationH, int dilationW,
134
+ int dilation_patchH, int dilation_patchW,
135
+ int dH, int dW) {
136
+
137
+ const int batch_size = input1.size(0);
138
+ const int patchRadH = (patchH - 1) / 2;
139
+ const int patchRadW = (patchW - 1) / 2;
140
+ const int oH = gradOutput.size(3);
141
+ const int oW = gradOutput.size(4);
142
+
143
+ auto gradInput1 = torch::zeros_like(input1);
144
+
145
+ auto gradInput2 = torch::zeros_like(input2);
146
+
147
+ int n, ph, pw, h, w;
148
+ #pragma omp parallel for private(n, ph, pw, h, w)
149
+ for (n = 0; n < batch_size; ++n) {
150
+ AT_DISPATCH_FLOATING_TYPES(input1.scalar_type(), "correlation_backward_cpp", ([&] {
151
+ auto input1_acc = input1.accessor<scalar_t, 4>();
152
+ auto gradInput1_acc = gradInput1.accessor<scalar_t, 4>();
153
+ auto input2_acc = input2.accessor<scalar_t, 4>();
154
+ auto gradInput2_acc = gradInput2.accessor<scalar_t, 4>();
155
+ auto gradOutput_acc = gradOutput.accessor<scalar_t, 5>();
156
+
157
+ for(ph = 0; ph < patchH; ++ph){
158
+ for(pw = 0; pw < patchW; ++pw){
159
+ for (h = 0; h < oH; ++h) {
160
+ for (w = 0; w < oW; ++w) {
161
+ correlate_patch_grad(input1_acc[n], gradInput1_acc[n],
162
+ input2_acc[n], gradInput2_acc[n],
163
+ gradOutput_acc[n][ph][pw][h][w],
164
+ kH, kW,
165
+ dilationH, dilationW,
166
+ -padH + h * dH,
167
+ -padW + w * dW,
168
+ (ph - patchRadH) * dilation_patchH,
169
+ (pw - patchRadW) * dilation_patchW);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }));
175
+ }
176
+
177
+ return {gradInput1, gradInput2};
178
+ }
Pytorch-Correlation-extension/Correlation_Module/correlation_cuda_kernel.cu ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <torch/types.h>
2
+ using namespace torch;
3
+
4
+ #include <cuda.h>
5
+ #include <cuda_runtime.h>
6
+
7
+ #include <vector>
8
+ #include <iostream>
9
+
10
+ // Cuda tensor accessor definitions
11
+ // restrict pointer traits piroritize speed over memory consumption
12
+ #define TensorAcc4R PackedTensorAccessor32<scalar_t,4,RestrictPtrTraits>
13
+ #define TensorAcc5R PackedTensorAccessor32<scalar_t,5,RestrictPtrTraits>
14
+ #define WITHIN_BOUNDS(x, y, H, W) (x >= 0 && x < H && y >= 0 && y < W)
15
+
16
+ #define THREADS_FORWARD 32
17
+ #define THREADS_BACKWARD 5
18
+
19
+
20
+ namespace corr {
21
+ template <typename scalar_t>
22
+ __global__ void correlation_cuda_forward_kernel(
23
+ const TensorAcc4R rInput1,
24
+ const TensorAcc4R rInput2,
25
+ TensorAcc5R output,
26
+ int kH, int kW,
27
+ int patchH, int patchW,
28
+ int padH, int padW,
29
+ int dilationH, int dilationW,
30
+ int dilation_patchH, int dilation_patchW,
31
+ int dH, int dW) {
32
+
33
+ const int iH = rInput1.size(1);
34
+ const int iW = rInput1.size(2);
35
+ const int C = rInput1.size(3);
36
+
37
+ const int n = blockIdx.x;
38
+ const int h = blockIdx.y;
39
+ const int w = blockIdx.z;
40
+ const int thread = threadIdx.x;
41
+
42
+ const int start_i = -padH + h * dH;
43
+ const int start_j = -padW + w * dW;
44
+
45
+ const int patchRadH = dilation_patchH * (patchH - 1) / 2;
46
+ const int patchRadW = dilation_patchW * (patchW - 1) / 2;
47
+
48
+ __shared__ scalar_t prod_sum[THREADS_FORWARD];
49
+
50
+ for(int ph = 0; ph < patchH; ++ph){
51
+ int ph_dilated = ph * dilation_patchH - patchRadH;
52
+ for(int pw = 0; pw < patchW; ++pw){
53
+ int pw_dilated = pw * dilation_patchW - patchRadW;
54
+ prod_sum[thread] = 0;
55
+ for (int i=0; i<kH; ++i){
56
+ int i1 = start_i + i * dilationH;
57
+ int i2 = i1 + ph_dilated;
58
+ if WITHIN_BOUNDS(i1, i2, iH, iH){
59
+ for (int j=0; j<kW; ++j){
60
+ int j1 = start_j + j * dilationW;
61
+ int j2 = j1 + pw_dilated;
62
+ if WITHIN_BOUNDS(j1, j2, iW, iW){
63
+ for (int c=thread; c<C; c += THREADS_FORWARD){
64
+ scalar_t v1 = rInput1[n][i1][j1][c];
65
+ scalar_t v2 = rInput2[n][i2][j2][c];
66
+ prod_sum[thread] += v1 * v2;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ // accumulate
73
+ __syncthreads();
74
+ if (thread == 0) {
75
+ scalar_t reduce_sum = 0;
76
+ for (int index = 0; index < THREADS_FORWARD; ++index) {
77
+ reduce_sum += prod_sum[index];
78
+ }
79
+ output[n][ph][pw][h][w] = reduce_sum;
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+
86
+ template <typename scalar_t>
87
+ __global__ void correlation_cuda_backward_kernel_input1(
88
+ const TensorAcc5R gradOutput,
89
+ const TensorAcc4R input2,
90
+ TensorAcc4R gradInput1,
91
+ const int kH, const int kW,
92
+ const int patchH, const int patchW,
93
+ const int padH, const int padW,
94
+ const int dilationH, const int dilationW,
95
+ const int dilation_patchH, const int dilation_patchW,
96
+ const int dH, const int dW,
97
+ const int batch) {
98
+ const int iH = input2.size(2);
99
+ const int iW = input2.size(3);
100
+
101
+ const int H = gradOutput.size(3);
102
+ const int W = gradOutput.size(4);
103
+
104
+ const int patchRadH = (patchH - 1) / 2;
105
+ const int patchRadW = (patchW - 1) / 2;
106
+
107
+ const int n = batch;
108
+ const int c = blockIdx.x;
109
+ const int h = blockIdx.y;
110
+ const int w = blockIdx.z;
111
+ const int ph_off = threadIdx.x;
112
+ const int pw_off = threadIdx.y;
113
+
114
+ const int h_2 = h + padH;
115
+ const int w_2 = w + padW;
116
+ const int min_h = h_2 - kH * dilationH;
117
+ const int min_w = w_2 - kW * dilationW;
118
+
119
+ __shared__ scalar_t prod_sum[THREADS_BACKWARD][THREADS_BACKWARD];
120
+ prod_sum[ph_off][pw_off] = 0;
121
+
122
+ for (int ph = ph_off; ph < patchH; ph += THREADS_BACKWARD) {
123
+ int i1 = h + dilation_patchH * (ph - patchRadH);
124
+ for (int pw = pw_off; pw < patchW; pw += THREADS_BACKWARD) {
125
+ int j1 = w + dilation_patchW * (pw - patchRadW);
126
+ if (WITHIN_BOUNDS(i1, j1, iH, iW)){
127
+ scalar_t val = input2[n][c][i1][j1];
128
+ for(int h_3 = h_2; h_3 > min_h; h_3 -= dilationH) {
129
+ int i2 = (h_3)/dH;
130
+ if (i2 * dH != h_3)
131
+ continue;
132
+ for(int w_3 = w_2; w_3 > min_w; w_3 -= dilationW) {
133
+ int j2 = (w_3) / dW;
134
+ if(j2 * dW != w_3)
135
+ continue;
136
+ if WITHIN_BOUNDS(i2, j2, H, W) {
137
+ prod_sum[ph_off][pw_off] += gradOutput[n][ph][pw][i2][j2] * val;
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ __syncthreads();
146
+
147
+ if (ph_off == 0 && pw_off == 0){
148
+ scalar_t reduce_sum =0;
149
+ for (int ph = 0; ph < THREADS_BACKWARD; ++ph){
150
+ for (int pw = 0; pw < THREADS_BACKWARD; ++pw){
151
+ reduce_sum += prod_sum[ph][pw];
152
+ }
153
+ }
154
+ gradInput1[n][c][h][w] = reduce_sum;
155
+ }
156
+ }
157
+
158
+
159
+ template <typename scalar_t>
160
+ __global__ void correlation_cuda_backward_kernel_input2(
161
+ const TensorAcc5R gradOutput,
162
+ const TensorAcc4R input1,
163
+ TensorAcc4R gradInput2,
164
+ int kH, int kW,
165
+ int patchH, int patchW,
166
+ int padH, int padW,
167
+ int dilationH, int dilationW,
168
+ int dilation_patchH, int dilation_patchW,
169
+ int dH, int dW,
170
+ int batch) {
171
+ const int iH = input1.size(2);
172
+ const int iW = input1.size(3);
173
+
174
+ const int patchRadH = (patchH - 1) / 2;
175
+ const int patchRadW = (patchW - 1) / 2;
176
+
177
+ const int H = gradOutput.size(3);
178
+ const int W = gradOutput.size(4);
179
+
180
+ const int dilatedKH = kH * dilationH;
181
+ const int dilatedKW = kW * dilationW;
182
+
183
+ const int n = batch;
184
+ const int c = blockIdx.x;
185
+ const int h = blockIdx.y;
186
+ const int w = blockIdx.z;
187
+ const int ph_off = threadIdx.x;
188
+ const int pw_off = threadIdx.y;
189
+
190
+ __shared__ scalar_t prod_sum[THREADS_BACKWARD][THREADS_BACKWARD];
191
+ prod_sum[ph_off][pw_off] = 0;
192
+
193
+ for (int ph = ph_off; ph < patchH; ph += THREADS_BACKWARD) {
194
+ int i1 = h - dilation_patchH * (ph - patchRadH);
195
+ for (int pw = pw_off; pw < patchW; pw += THREADS_BACKWARD) {
196
+ int j1 = w - dilation_patchW * (pw - patchRadW);
197
+ if WITHIN_BOUNDS(i1, j1, iH, iW) {
198
+ scalar_t val = input1[n][c][i1][j1];
199
+
200
+ const int h_2 = i1 + padH;
201
+ const int w_2 = j1 + padW;
202
+ const int min_h = h_2 - dilatedKH;
203
+ const int min_w = w_2 - dilatedKW;
204
+
205
+ for(int h_3 = h_2; h_3 > min_h; h_3 -= dilationH) {
206
+ int i2 = (h_3)/dH;
207
+ if (i2 * dH != h_3)
208
+ continue;
209
+ for(int w_3 = w_2; w_3 > min_w; w_3 -= dilationW) {
210
+ int j2 = (w_3) / dW;
211
+ if(j2 * dW != w_3)
212
+ continue;
213
+ if WITHIN_BOUNDS(i2, j2, H, W) {
214
+ prod_sum[ph_off][pw_off] += gradOutput[n][ph][pw][i2][j2] * val;
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ __syncthreads();
223
+
224
+ if (ph_off == 0 && pw_off == 0){
225
+ scalar_t reduce_sum =0;
226
+ for (int ph = 0; ph < THREADS_BACKWARD; ++ph){
227
+ for (int pw = 0; pw < THREADS_BACKWARD; ++pw){
228
+ reduce_sum += prod_sum[ph][pw];
229
+ }
230
+ }
231
+ gradInput2[n][c][h][w] = reduce_sum;
232
+ }
233
+ }
234
+ } // namsepace corr
235
+
236
+ torch::Tensor correlation_cuda_forward(
237
+ torch::Tensor input1,
238
+ torch::Tensor input2,
239
+ int kH, int kW,
240
+ int patchH, int patchW,
241
+ int padH, int padW,
242
+ int dilationH, int dilationW,
243
+ int dilation_patchH, int dilation_patchW,
244
+ int dH, int dW) {
245
+
246
+ const int batch_size = input1.size(0);
247
+ const int iH = input1.size(2);
248
+ const int iW = input1.size(3);
249
+ const int dilatedKH = (kH - 1) * dilationH + 1;
250
+ const int dilatedKW = (kW - 1) * dilationW + 1;
251
+
252
+ const auto oH = (iH + 2 * padH - dilatedKH) / dH + 1;
253
+ const auto oW = (iW + 2 * padW - dilatedKW) / dW + 1;
254
+ auto output = torch::zeros({batch_size, patchH, patchW, oH, oW}, input1.options());
255
+
256
+ auto trInput1 = input1.permute({0, 2, 3, 1}).contiguous();
257
+ auto trInput2 = input2.permute({0, 2, 3, 1}).contiguous();
258
+
259
+ const int threads = THREADS_FORWARD;
260
+ const dim3 blocks(batch_size, oH, oW);
261
+
262
+ AT_DISPATCH_FLOATING_TYPES_AND_HALF(input1.scalar_type(), "correlation_forward_cuda", ([&] {
263
+ TensorAcc4R trInput1_acc = trInput1.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
264
+ TensorAcc4R trInput2_acc = trInput2.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
265
+ TensorAcc5R output_acc = output.packed_accessor32<scalar_t,5,RestrictPtrTraits>();
266
+ corr::correlation_cuda_forward_kernel<scalar_t><<<blocks, threads>>>(
267
+ trInput1_acc, trInput2_acc, output_acc,
268
+ kH, kW, patchH, patchW, padH, padW, dilationH, dilationW,
269
+ dilation_patchH, dilation_patchW, dH, dW);
270
+ }));
271
+
272
+ return output;
273
+ }
274
+
275
+ std::vector<torch::Tensor> correlation_cuda_backward(
276
+ torch::Tensor input1,
277
+ torch::Tensor input2,
278
+ torch::Tensor gradOutput,
279
+ int kH, int kW,
280
+ int patchH, int patchW,
281
+ int padH, int padW,
282
+ int dilationH, int dilationW,
283
+ int dilation_patchH, int dilation_patchW,
284
+ int dH, int dW) {
285
+
286
+ auto gradInput1 = torch::zeros_like(input1);
287
+ auto gradInput2 = torch::zeros_like(input2);
288
+
289
+ const int batch_size = input1.size(0);
290
+ const int iH = input1.size(2);
291
+ const int iW = input1.size(3);
292
+ const int C = input1.size(1);
293
+
294
+ const dim3 blocks(C, iH, iW);
295
+ const dim3 threads(THREADS_BACKWARD, THREADS_BACKWARD);
296
+
297
+ AT_DISPATCH_FLOATING_TYPES_AND_HALF(input1.scalar_type(), "correlation_backward_cuda", ([&] {
298
+ TensorAcc4R input1_acc = input1.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
299
+ TensorAcc4R input2_acc = input2.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
300
+ TensorAcc4R gradInput1_acc = gradInput1.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
301
+ TensorAcc4R gradInput2_acc = gradInput2.packed_accessor32<scalar_t,4,RestrictPtrTraits>();
302
+ TensorAcc5R gradOutput_acc = gradOutput.packed_accessor32<scalar_t,5,RestrictPtrTraits>();
303
+
304
+
305
+ for (int n = 0; n < batch_size; ++n){
306
+ corr::correlation_cuda_backward_kernel_input1<scalar_t><<<blocks, threads>>>(
307
+ gradOutput_acc, input2_acc, gradInput1_acc,
308
+ kH, kW, patchH, patchW, padH, padW,
309
+ dilationH, dilationW,
310
+ dilation_patchH, dilation_patchW,
311
+ dH, dW,
312
+ n);
313
+ }
314
+
315
+ for (int n = 0; n < batch_size; ++n){
316
+ corr::correlation_cuda_backward_kernel_input2<scalar_t><<<blocks, threads>>>(
317
+ gradOutput_acc, input1_acc, gradInput2_acc,
318
+ kH, kW, patchH, patchW, padH, padW,
319
+ dilationH, dilationW,
320
+ dilation_patchH, dilation_patchW,
321
+ dH, dW,
322
+ n);
323
+ }
324
+ }));
325
+
326
+ return {gradInput1, gradInput2};
327
+ }
Pytorch-Correlation-extension/Correlation_Module/correlation_sampler.cpp ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <torch/extension.h>
2
+ #include <c10/cuda/CUDAGuard.h>
3
+ #include <vector>
4
+ #include <iostream>
5
+
6
+ // declarations
7
+
8
+ torch::Tensor correlation_cpp_forward(
9
+ torch::Tensor input1,
10
+ torch::Tensor input2,
11
+ int kH, int kW,
12
+ int patchH, int patchW,
13
+ int padH, int padW,
14
+ int dilationH, int dilationW,
15
+ int dilation_patchH, int dilation_patchW,
16
+ int dH, int dW);
17
+
18
+ std::vector<torch::Tensor> correlation_cpp_backward(
19
+ torch::Tensor grad_output,
20
+ torch::Tensor input1,
21
+ torch::Tensor input2,
22
+ int kH, int kW,
23
+ int patchH, int patchW,
24
+ int padH, int padW,
25
+ int dilationH, int dilationW,
26
+ int dilation_patchH, int dilation_patchW,
27
+ int dH, int dW);
28
+
29
+ #ifdef USE_CUDA
30
+
31
+ #define CHECK_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x, " must be a CUDA tensor")
32
+ #define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x, " must be contiguous")
33
+ #define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
34
+ #define CHECK_SAME_DEVICE(x, y) TORCH_CHECK(x.device() == y.device(), #x " is not on same device as " #y)
35
+
36
+ torch::Tensor correlation_cuda_forward(
37
+ torch::Tensor input1,
38
+ torch::Tensor input2,
39
+ int kH, int kW,
40
+ int patchH, int patchW,
41
+ int padH, int padW,
42
+ int dilationH, int dilationW,
43
+ int dilation_patchH, int dilation_patchW,
44
+ int dH, int dW);
45
+
46
+ std::vector<torch::Tensor> correlation_cuda_backward(
47
+ torch::Tensor grad_output,
48
+ torch::Tensor input1,
49
+ torch::Tensor input2,
50
+ int kH, int kW,
51
+ int patchH, int patchW,
52
+ int padH, int padW,
53
+ int dilationH, int dilationW,
54
+ int dilation_patchH, int dilation_patchW,
55
+ int dH, int dW);
56
+
57
+ // C++ interface
58
+
59
+ torch::Tensor correlation_sample_forward(
60
+ torch::Tensor input1,
61
+ torch::Tensor input2,
62
+ int kH, int kW,
63
+ int patchH, int patchW,
64
+ int padH, int padW,
65
+ int dilationH, int dilationW,
66
+ int dilation_patchH, int dilation_patchW,
67
+ int dH, int dW) {
68
+ if (input1.device().is_cuda()){
69
+ CHECK_INPUT(input1);
70
+ CHECK_INPUT(input2);
71
+
72
+ // set device of input1 as default CUDA device
73
+ // https://pytorch.org/cppdocs/api/structc10_1_1cuda_1_1_optional_c_u_d_a_guard.html
74
+ const at::cuda::OptionalCUDAGuard guard_input1(device_of(input1));
75
+ CHECK_SAME_DEVICE(input1, input2);
76
+
77
+ return correlation_cuda_forward(input1, input2, kH, kW, patchH, patchW,
78
+ padH, padW, dilationH, dilationW,
79
+ dilation_patchH, dilation_patchW,
80
+ dH, dW);
81
+ }else{
82
+ return correlation_cpp_forward(input1, input2, kH, kW, patchH, patchW,
83
+ padH, padW, dilationH, dilationW,
84
+ dilation_patchH, dilation_patchW,
85
+ dH, dW);
86
+ }
87
+ }
88
+
89
+ std::vector<torch::Tensor> correlation_sample_backward(
90
+ torch::Tensor input1,
91
+ torch::Tensor input2,
92
+ torch::Tensor grad_output,
93
+ int kH, int kW,
94
+ int patchH, int patchW,
95
+ int padH, int padW,
96
+ int dilationH, int dilationW,
97
+ int dilation_patchH, int dilation_patchW,
98
+ int dH, int dW) {
99
+
100
+ if(grad_output.device().is_cuda()){
101
+ CHECK_INPUT(input1);
102
+ CHECK_INPUT(input2);
103
+
104
+ // set device of input1 as default CUDA device
105
+ const at::cuda::OptionalCUDAGuard guard_input1(device_of(input1));
106
+ CHECK_SAME_DEVICE(input1, input2);
107
+ CHECK_SAME_DEVICE(input1, grad_output);
108
+
109
+ return correlation_cuda_backward(input1, input2, grad_output,
110
+ kH, kW, patchH, patchW,
111
+ padH, padW,
112
+ dilationH, dilationW,
113
+ dilation_patchH, dilation_patchW,
114
+ dH, dW);
115
+ }else{
116
+ return correlation_cpp_backward(
117
+ input1, input2, grad_output,
118
+ kH, kW, patchH, patchW,
119
+ padH, padW,
120
+ dilationH, dilationW,
121
+ dilation_patchH, dilation_patchW,
122
+ dH, dW);
123
+ }
124
+ }
125
+
126
+ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
127
+ m.def("forward", &correlation_sample_forward, "Spatial Correlation Sampler Forward");
128
+ m.def("backward", &correlation_sample_backward, "Spatial Correlation Sampler backward");
129
+ }
130
+
131
+ #else
132
+
133
+ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
134
+ m.def("forward", &correlation_cpp_forward, "Spatial Correlation Sampler Forward");
135
+ m.def("backward", &correlation_cpp_backward, "Spatial Correlation Sampler backward");
136
+ }
137
+
138
+ #endif
Pytorch-Correlation-extension/Correlation_Module/spatial_correlation_sampler/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .spatial_correlation_sampler import SpatialCorrelationSampler, spatial_correlation_sample
Pytorch-Correlation-extension/Correlation_Module/spatial_correlation_sampler/spatial_correlation_sampler.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch import nn
2
+ from torch.autograd import Function
3
+ from torch.autograd.function import once_differentiable
4
+ from torch.nn.modules.utils import _pair
5
+
6
+ import spatial_correlation_sampler_backend as correlation
7
+
8
+
9
+ def spatial_correlation_sample(input1,
10
+ input2,
11
+ kernel_size=1,
12
+ patch_size=1,
13
+ stride=1,
14
+ padding=0,
15
+ dilation=1,
16
+ dilation_patch=1):
17
+ """Apply spatial correlation sampling on from input1 to input2,
18
+
19
+ Every parameter except input1 and input2 can be either single int
20
+ or a pair of int. For more information about Spatial Correlation
21
+ Sampling, see this page.
22
+ https://lmb.informatik.uni-freiburg.de/Publications/2015/DFIB15/
23
+
24
+ Args:
25
+ input1 : The first parameter.
26
+ input2 : The second parameter.
27
+ kernel_size : total size of your correlation kernel, in pixels
28
+ patch_size : total size of your patch, determining how many
29
+ different shifts will be applied
30
+ stride : stride of the spatial sampler, will modify output
31
+ height and width
32
+ padding : padding applied to input1 and input2 before applying
33
+ the correlation sampling, will modify output height and width
34
+ dilation_patch : step for every shift in patch
35
+
36
+ Returns:
37
+ Tensor: Result of correlation sampling
38
+
39
+ """
40
+ return SpatialCorrelationSamplerFunction.apply(input1, input2,
41
+ kernel_size, patch_size,
42
+ stride, padding, dilation, dilation_patch)
43
+
44
+
45
+ class SpatialCorrelationSamplerFunction(Function):
46
+
47
+ @staticmethod
48
+ def forward(ctx,
49
+ input1,
50
+ input2,
51
+ kernel_size=1,
52
+ patch_size=1,
53
+ stride=1,
54
+ padding=0,
55
+ dilation=1,
56
+ dilation_patch=1):
57
+
58
+ ctx.save_for_backward(input1, input2)
59
+ kH, kW = ctx.kernel_size = _pair(kernel_size)
60
+ patchH, patchW = ctx.patch_size = _pair(patch_size)
61
+ padH, padW = ctx.padding = _pair(padding)
62
+ dilationH, dilationW = ctx.dilation = _pair(dilation)
63
+ dilation_patchH, dilation_patchW = ctx.dilation_patch = _pair(dilation_patch)
64
+ dH, dW = ctx.stride = _pair(stride)
65
+
66
+ output = correlation.forward(input1, input2,
67
+ kH, kW, patchH, patchW,
68
+ padH, padW, dilationH, dilationW,
69
+ dilation_patchH, dilation_patchW,
70
+ dH, dW)
71
+
72
+ return output
73
+
74
+ @staticmethod
75
+ @once_differentiable
76
+ def backward(ctx, grad_output):
77
+ input1, input2 = ctx.saved_variables
78
+
79
+ kH, kW = ctx.kernel_size
80
+ patchH, patchW = ctx.patch_size
81
+ padH, padW = ctx.padding
82
+ dilationH, dilationW = ctx.dilation
83
+ dilation_patchH, dilation_patchW = ctx.dilation_patch
84
+ dH, dW = ctx.stride
85
+
86
+ grad_input1, grad_input2 = correlation.backward(input1, input2, grad_output,
87
+ kH, kW, patchH, patchW,
88
+ padH, padW, dilationH, dilationW,
89
+ dilation_patchH, dilation_patchW,
90
+ dH, dW)
91
+ return grad_input1, grad_input2, None, None, None, None, None, None
92
+
93
+
94
+ class SpatialCorrelationSampler(nn.Module):
95
+ def __init__(self, kernel_size=1, patch_size=1, stride=1, padding=0, dilation=1, dilation_patch=1):
96
+ super(SpatialCorrelationSampler, self).__init__()
97
+ self.kernel_size = kernel_size
98
+ self.patch_size = patch_size
99
+ self.stride = stride
100
+ self.padding = padding
101
+ self.dilation = dilation
102
+ self.dilation_patch = dilation_patch
103
+
104
+ def forward(self, input1, input2):
105
+ return SpatialCorrelationSamplerFunction.apply(input1, input2, self.kernel_size,
106
+ self.patch_size, self.stride,
107
+ self.padding, self.dilation, self.dilation_patch)
Pytorch-Correlation-extension/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Pytorch-Correlation-extension/README.md ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ [![PyPI](https://img.shields.io/pypi/v/spatial-correlation-sampler.svg)](https://pypi.org/project/spatial-correlation-sampler/)
3
+
4
+
5
+ # Pytorch Correlation module
6
+
7
+ this is a custom C++/Cuda implementation of Correlation module, used e.g. in [FlowNetC](https://arxiv.org/abs/1504.06852)
8
+
9
+ This [tutorial](http://pytorch.org/tutorials/advanced/cpp_extension.html) was used as a basis for implementation, as well as
10
+ [NVIDIA's cuda code](https://github.com/NVIDIA/flownet2-pytorch/tree/master/networks/correlation_package)
11
+
12
+ - Build and Install C++ and CUDA extensions by executing `python setup.py install`,
13
+ - Benchmark C++ vs. CUDA by running `python benchmark.py {cpu, cuda}`,
14
+ - Run gradient checks on the code by running `python grad_check.py --backend {cpu, cuda}`.
15
+
16
+ # Requirements
17
+
18
+ This module is expected to compile for Pytorch `1.6`.
19
+
20
+ # Installation
21
+
22
+ this module is available on pip
23
+
24
+ `pip install spatial-correlation-sampler`
25
+
26
+ For a cpu-only version, you can install from source with
27
+
28
+ `python setup_cpu.py install`
29
+
30
+ # Known Problems
31
+
32
+ This module needs compatible gcc version and CUDA to be compiled.
33
+ Namely, CUDA 9.1 and below will need gcc5, while CUDA 9.2 and 10.0 will need gcc7
34
+ See [this issue](https://github.com/ClementPinard/Pytorch-Correlation-extension/issues/1) for more information
35
+
36
+ # Usage
37
+
38
+ API has a few difference with NVIDIA's module
39
+ * output is now a 5D tensor, which reflects the shifts horizontal and vertical.
40
+ ```
41
+ input (B x C x H x W) -> output (B x PatchH x PatchW x oH x oW)
42
+ ```
43
+ * Output sizes `oH` and `oW` are no longer dependant of patch size, but only of kernel size and padding
44
+ * Patch size `patch_size` is now the whole patch, and not only the radii.
45
+ * `stride1` is now `stride` and`stride2` is `dilation_patch`, which behave like dilated convolutions
46
+ * equivalent `max_displacement` is then `dilation_patch * (patch_size - 1) / 2`.
47
+ * `dilation` is a new parameter, it acts the same way as dilated convolution regarding the correlation kernel
48
+ * to get the right parameters for FlowNetC, you would have
49
+ ```
50
+ kernel_size=1
51
+ patch_size=21,
52
+ stride=1,
53
+ padding=0,
54
+ dilation=1
55
+ dilation_patch=2
56
+ ```
57
+
58
+
59
+ ## Example
60
+ ```python
61
+ import torch
62
+ from spatial_correlation_sampler import SpatialCorrelationSampler,
63
+
64
+ device = "cuda"
65
+ batch_size = 1
66
+ channel = 1
67
+ H = 10
68
+ W = 10
69
+ dtype = torch.float32
70
+
71
+ input1 = torch.randint(1, 4, (batch_size, channel, H, W), dtype=dtype, device=device, requires_grad=True)
72
+ input2 = torch.randint_like(input1, 1, 4).requires_grad_(True)
73
+
74
+ #You can either use the function or the module. Note that the module doesn't contain any parameter tensor.
75
+
76
+ #function
77
+
78
+ out = spatial_correlation_sample(input1,
79
+ input2,
80
+ kernel_size=3,
81
+ patch_size=1,
82
+ stride=2,
83
+ padding=0,
84
+ dilation=2,
85
+ dilation_patch=1)
86
+
87
+ #module
88
+
89
+ correlation_sampler = SpatialCorrelationSampler(
90
+ kernel_size=3,
91
+ patch_size=1,
92
+ stride=2,
93
+ padding=0,
94
+ dilation=2,
95
+ dilation_patch=1)
96
+ out = correlation_sampler(input1, input2)
97
+
98
+ ```
99
+
100
+ # Benchmark
101
+
102
+ * default parameters are from `benchmark.py`, FlowNetC parameters are same as use in `FlowNetC` with a batch size of 4, described in [this paper](https://arxiv.org/abs/1504.06852), implemented [here](https://github.com/lmb-freiburg/flownet2) and [here](https://github.com/NVIDIA/flownet2-pytorch/blob/master/networks/FlowNetC.py).
103
+ * Feel free to file an issue to add entries to this with your hardware !
104
+
105
+ ## CUDA Benchmark
106
+
107
+ * See [here](https://gist.github.com/ClementPinard/270e910147119831014932f67fb1b5ea) for a benchmark script working with [NVIDIA](https://github.com/NVIDIA/flownet2-pytorch/tree/master/networks/correlation_package)'s code, and Pytorch.
108
+ * Benchmark are launched with environment variable `CUDA_LAUNCH_BLOCKING` set to `1`.
109
+ * Only `float32` is benchmarked.
110
+ * FlowNetC correlation parameters where launched with the following command:
111
+
112
+ ```bash
113
+ CUDA_LAUNCH_BLOCKING=1 python benchmark.py --scale ms -k1 --patch 21 -s1 -p0 --patch_dilation 2 -b4 --height 48 --width 64 -c256 cuda -d float
114
+
115
+ CUDA_LAUNCH_BLOCKING=1 python NV_correlation_benchmark.py --scale ms -k1 --patch 21 -s1 -p0 --patch_dilation 2 -b4 --height 48 --width 64 -c256
116
+ ```
117
+
118
+ | implementation | Correlation parameters | device | pass | min time | avg time |
119
+ | -------------- | ---------------------- | ------- | -------- | ------------: | ------------: |
120
+ | ours | default | 980 GTX | forward | **5.745 ms** | **5.851 ms** |
121
+ | ours | default | 980 GTX | backward | 77.694 ms | 77.957 ms |
122
+ | NVIDIA | default | 980 GTX | forward | 13.779 ms | 13.853 ms |
123
+ | NVIDIA | default | 980 GTX | backward | **73.383 ms** | **73.708 ms** |
124
+ | | | | | | |
125
+ | ours | FlowNetC | 980 GTX | forward | **26.102 ms** | **26.179 ms** |
126
+ | ours | FlowNetC | 980 GTX | backward | **208.091 ms** | **208.510 ms** |
127
+ | NVIDIA | FlowNetC | 980 GTX | forward | 35.363 ms | 35.550 ms |
128
+ | NVIDIA | FlowNetC | 980 GTX | backward | 283.748 ms | 284.346 ms |
129
+
130
+ ### Notes
131
+ * The overhead of our implementation regarding `kernel_size` > 1 during backward needs some investigation, feel free to
132
+ dive in the code to improve it !
133
+ * The backward pass of NVIDIA is not entirely correct when stride1 > 1 and kernel_size > 1, because not everything
134
+ is computed, see [here](https://github.com/NVIDIA/flownet2-pytorch/blob/master/networks/correlation_package/src/correlation_cuda_kernel.cu#L120).
135
+
136
+ ## CPU Benchmark
137
+
138
+ * No other implementation is avalaible on CPU.
139
+ * It is obviously not recommended to run it on CPU if you have a GPU.
140
+
141
+ | Correlation parameters | device | pass | min time | avg time |
142
+ | ---------------------- | -------------------- | -------- | ----------: | ----------: |
143
+ | default | E5-2630 v3 @ 2.40GHz | forward | 159.616 ms | 188.727 ms |
144
+ | default | E5-2630 v3 @ 2.40GHz | backward | 282.641 ms | 294.194 ms |
145
+ | FlowNetC | E5-2630 v3 @ 2.40GHz | forward | 2.138 s | 2.144 s |
146
+ | FlowNetC | E5-2630 v3 @ 2.40GHz | backward | 7.006 s | 7.075 s |
Pytorch-Correlation-extension/benchmark.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import division
2
+ from __future__ import print_function
3
+
4
+ import argparse
5
+ import time
6
+
7
+ import torch
8
+ from spatial_correlation_sampler import SpatialCorrelationSampler
9
+ from tqdm import trange
10
+
11
+ TIME_SCALES = {'s': 1, 'ms': 1000, 'us': 1000000}
12
+
13
+ parser = argparse.ArgumentParser()
14
+ parser.add_argument('backend', choices=['cpu', 'cuda'], default='cuda')
15
+ parser.add_argument('-b', '--batch-size', type=int, default=16)
16
+ parser.add_argument('-k', '--kernel-size', type=int, default=3)
17
+ parser.add_argument('--patch', type=int, default=3)
18
+ parser.add_argument('--patch_dilation', type=int, default=2)
19
+ parser.add_argument('-c', '--channel', type=int, default=64)
20
+ parser.add_argument('--height', type=int, default=100)
21
+ parser.add_argument('-w', '--width', type=int, default=100)
22
+ parser.add_argument('-s', '--stride', type=int, default=2)
23
+ parser.add_argument('-p', '--pad', type=int, default=1)
24
+ parser.add_argument('--scale', choices=['s', 'ms', 'us'], default='us')
25
+ parser.add_argument('-r', '--runs', type=int, default=100)
26
+ parser.add_argument('--dilation', type=int, default=2)
27
+ parser.add_argument('-d', '--dtype', choices=['half', 'float', 'double'])
28
+
29
+ args = parser.parse_args()
30
+
31
+ device = torch.device(args.backend)
32
+
33
+ if args.dtype == 'half':
34
+ dtype = torch.float16
35
+ elif args.dtype == 'float':
36
+ dtype = torch.float32
37
+ else:
38
+ dtype = torch.float64
39
+
40
+
41
+ input1 = torch.randn(args.batch_size,
42
+ args.channel,
43
+ args.height,
44
+ args.width,
45
+ dtype=dtype,
46
+ device=device,
47
+ requires_grad=True)
48
+ input2 = torch.randn_like(input1)
49
+
50
+ correlation_sampler = SpatialCorrelationSampler(
51
+ args.kernel_size,
52
+ args.patch,
53
+ args.stride,
54
+ args.pad,
55
+ args.dilation,
56
+ args.patch_dilation)
57
+
58
+ # Force CUDA initialization
59
+ output = correlation_sampler(input1, input2)
60
+ print(output.size())
61
+ output.mean().backward()
62
+ forward_min = float('inf')
63
+ forward_time = 0
64
+ backward_min = float('inf')
65
+ backward_time = 0
66
+ for _ in trange(args.runs):
67
+ correlation_sampler.zero_grad()
68
+
69
+ start = time.time()
70
+ output = correlation_sampler(input1, input2)
71
+ elapsed = time.time() - start
72
+ forward_min = min(forward_min, elapsed)
73
+ forward_time += elapsed
74
+ output = output.mean()
75
+
76
+ start = time.time()
77
+ (output.mean()).backward()
78
+ elapsed = time.time() - start
79
+ backward_min = min(backward_min, elapsed)
80
+ backward_time += elapsed
81
+
82
+ scale = TIME_SCALES[args.scale]
83
+ forward_min *= scale
84
+ backward_min *= scale
85
+ forward_average = forward_time / args.runs * scale
86
+ backward_average = backward_time / args.runs * scale
87
+
88
+ print('Forward: {0:.3f}/{1:.3f} {4} | Backward {2:.3f}/{3:.3f} {4}'.format(
89
+ forward_min, forward_average, backward_min, backward_average,
90
+ args.scale))
Pytorch-Correlation-extension/check.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import division
2
+ from __future__ import print_function
3
+
4
+ import argparse
5
+ import numpy as np
6
+ import torch
7
+
8
+ from spatial_correlation_sampler import SpatialCorrelationSampler
9
+
10
+
11
+ def check_equal(first, second, verbose):
12
+ if verbose:
13
+ print()
14
+ for i, (x, y) in enumerate(zip(first, second)):
15
+ x = x.cpu().detach().numpy()
16
+ y = y.cpu().detach().numpy()
17
+ if verbose:
18
+ print("x = {}".format(x.flatten()))
19
+ print("y = {}".format(y.flatten()))
20
+ print('-' * 80)
21
+ np.testing.assert_allclose(x, y, err_msg="Index: {}".format(i))
22
+
23
+
24
+ def zero_grad(variables):
25
+ for variable in variables:
26
+ if variable.grad is not None: variable.grad.zero_()
27
+
28
+
29
+ def get_grads(variables):
30
+ return [var.grad.clone() for var in variables]
31
+
32
+
33
+ def check_forward(input1, input2, correlation_sampler, verbose, gpu_index=0):
34
+ device = torch.device(f"cuda:{gpu_index}")
35
+
36
+ cpu_values = correlation_sampler(input1, input2)
37
+ cuda_values = correlation_sampler(input1.to(device), input2.to(device))
38
+
39
+ print(f"Forward: CPU vs. CUDA device:{gpu_index} ... ", end='')
40
+ check_equal(cpu_values, cuda_values, verbose)
41
+ print('Ok')
42
+
43
+
44
+ def check_backward(input1, input2, correlation_sampler, verbose, gpu_index=0):
45
+ device = torch.device(f"cuda:{gpu_index}")
46
+
47
+ zero_grad([input1, input2])
48
+
49
+ cpu_values = correlation_sampler(input1, input2)
50
+ cpu_values.sum().backward()
51
+ grad_cpu = get_grads([input1, input2])
52
+
53
+ zero_grad([input1, input2])
54
+
55
+ cuda_values = correlation_sampler(input1.to(device), input2.to(device))
56
+ cuda_values.sum().backward()
57
+ grad_cuda = get_grads([input1, input2])
58
+
59
+ print(f"Backward: CPU vs. CUDA device:{gpu_index} ... ", end='')
60
+ check_equal(grad_cpu, grad_cuda, verbose)
61
+ print('Ok')
62
+
63
+
64
+ def check_multi_gpu_forward(correlation_sampler, verbose):
65
+ print("Multi-GPU forward")
66
+ total_gpus = torch.cuda.device_count()
67
+ for gpu in range(total_gpus):
68
+ check_forward(input1, input2, correlation_sampler, verbose, gpu_index=gpu)
69
+
70
+ def check_multi_gpu_backward(correlation_sampler, verbose):
71
+ print("Multi-GPU backward")
72
+ total_gpus = torch.cuda.device_count()
73
+ for gpu in range(total_gpus):
74
+ check_backward(input1, input2, correlation_sampler, verbose, gpu_index=gpu)
75
+
76
+
77
+ parser = argparse.ArgumentParser()
78
+ parser.add_argument('direction', choices=['forward', 'backward'], nargs='+')
79
+ parser.add_argument('-b', '--batch-size', type=int, default=1)
80
+ parser.add_argument('-k', '--kernel-size', type=int, default=3)
81
+ parser.add_argument('--patch', type=int, default=3)
82
+ parser.add_argument('--patch_dilation', type=int, default=2)
83
+ parser.add_argument('-c', '--channel', type=int, default=10)
84
+ parser.add_argument('--height', type=int, default=10)
85
+ parser.add_argument('-w', '--width', type=int, default=10)
86
+ parser.add_argument('-s', '--stride', type=int, default=2)
87
+ parser.add_argument('-p', '--pad', type=int, default=5)
88
+ parser.add_argument('-v', '--verbose', action='store_true', default=False)
89
+ parser.add_argument('-d', '--dilation', type=int, default=2)
90
+ args = parser.parse_args()
91
+ print(args)
92
+
93
+ assert(torch.cuda.is_available()), "no comparison to make"
94
+ input1 = torch.randn(args.batch_size,
95
+ args.channel,
96
+ args.height,
97
+ args.width).double()
98
+ input2 = torch.randn(args.batch_size,
99
+ args.channel,
100
+ args.height,
101
+ args.width).double()
102
+ input1.requires_grad = True
103
+ input2.requires_grad = True
104
+
105
+ correlation_sampler = SpatialCorrelationSampler(
106
+ args.kernel_size,
107
+ args.patch,
108
+ args.stride,
109
+ args.pad,
110
+ args.dilation,
111
+ args.patch_dilation)
112
+
113
+ if 'forward' in args.direction:
114
+ check_forward(input1, input2, correlation_sampler, args.verbose)
115
+ if torch.cuda.device_count() > 1: check_multi_gpu_forward(correlation_sampler, args.verbose)
116
+
117
+ if 'backward' in args.direction:
118
+ check_backward(input1, input2, correlation_sampler, args.verbose)
119
+ if torch.cuda.device_count() > 1: check_multi_gpu_backward(correlation_sampler, args.verbose)
Pytorch-Correlation-extension/grad_check.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import torch
3
+ # torch.set_printoptions(precision=1, threshold=10000)
4
+ from torch.autograd import gradcheck
5
+ from spatial_correlation_sampler import SpatialCorrelationSampler
6
+
7
+ parser = argparse.ArgumentParser()
8
+ parser.add_argument('backend', choices=['cpu', 'cuda'], default='cuda')
9
+ parser.add_argument('-b', '--batch-size', type=int, default=2)
10
+ parser.add_argument('-k', '--kernel-size', type=int, default=3)
11
+ parser.add_argument('--patch', type=int, default=3)
12
+ parser.add_argument('--patch_dilation', type=int, default=2)
13
+ parser.add_argument('-c', '--channel', type=int, default=2)
14
+ parser.add_argument('--height', type=int, default=10)
15
+ parser.add_argument('-w', '--width', type=int, default=10)
16
+ parser.add_argument('-s', '--stride', type=int, default=2)
17
+ parser.add_argument('-p', '--pad', type=int, default=1)
18
+ parser.add_argument('-d', '--dilation', type=int, default=2)
19
+
20
+ args = parser.parse_args()
21
+
22
+ input1 = torch.randn(args.batch_size,
23
+ args.channel,
24
+ args.height,
25
+ args.width,
26
+ dtype=torch.float64,
27
+ device=torch.device(args.backend))
28
+ input2 = torch.randn(args.batch_size,
29
+ args.channel,
30
+ args.height,
31
+ args.width,
32
+ dtype=torch.float64,
33
+ device=torch.device(args.backend))
34
+
35
+ input1.requires_grad = True
36
+ input2.requires_grad = True
37
+
38
+ correlation_sampler = SpatialCorrelationSampler(args.kernel_size,
39
+ args.patch,
40
+ args.stride,
41
+ args.pad,
42
+ args.dilation,
43
+ args.patch_dilation)
44
+
45
+
46
+ if gradcheck(correlation_sampler, [input1, input2]):
47
+ print('Ok')
Pytorch-Correlation-extension/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch>=1.0.1
2
+ numpy
Pytorch-Correlation-extension/setup.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from setuptools import setup
3
+ from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
4
+ from os.path import join
5
+
6
+ CPU_ONLY = False
7
+ project_root = 'Correlation_Module'
8
+
9
+ source_files = ['correlation.cpp', 'correlation_sampler.cpp']
10
+
11
+ cxx_args = ['-std=c++14', '-fopenmp']
12
+
13
+ def generate_nvcc_args(gpu_archs):
14
+ nvcc_args = []
15
+ for arch in gpu_archs:
16
+ nvcc_args.extend(['-gencode', f'arch=compute_{arch},code=sm_{arch}'])
17
+ return nvcc_args
18
+
19
+ gpu_arch = os.environ.get('GPU_ARCH', '').split()
20
+ nvcc_args = generate_nvcc_args(gpu_arch)
21
+
22
+ with open("README.md", "r") as fh:
23
+ long_description = fh.read()
24
+
25
+
26
+ def launch_setup():
27
+ if CPU_ONLY:
28
+ Extension = CppExtension
29
+ macro = []
30
+ else:
31
+ Extension = CUDAExtension
32
+ source_files.append('correlation_cuda_kernel.cu')
33
+ macro = [("USE_CUDA", None)]
34
+
35
+ sources = [join(project_root, file) for file in source_files]
36
+
37
+ setup(
38
+ name='spatial_correlation_sampler',
39
+ version="0.4.0",
40
+ author="Clément Pinard",
41
+ author_email="[email protected]",
42
+ description="Correlation module for pytorch",
43
+ long_description=long_description,
44
+ long_description_content_type="text/markdown",
45
+ url="https://github.com/ClementPinard/Pytorch-Correlation-extension",
46
+ install_requires=['torch>=1.1', 'numpy'],
47
+ ext_modules=[
48
+ Extension('spatial_correlation_sampler_backend',
49
+ sources,
50
+ define_macros=macro,
51
+ extra_compile_args={'cxx': cxx_args, 'nvcc': nvcc_args},
52
+ extra_link_args=['-lgomp'])
53
+ ],
54
+ package_dir={'': project_root},
55
+ packages=['spatial_correlation_sampler'],
56
+ cmdclass={
57
+ 'build_ext': BuildExtension
58
+ },
59
+ classifiers=[
60
+ "Programming Language :: Python :: 3",
61
+ "License :: OSI Approved :: MIT License",
62
+ "Operating System :: POSIX :: Linux",
63
+ "Intended Audience :: Science/Research",
64
+ "Topic :: Scientific/Engineering :: Artificial Intelligence"
65
+ ])
66
+
67
+
68
+ if __name__ == '__main__':
69
+ launch_setup()
Pytorch-Correlation-extension/setup_cpu.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ import setup
2
+
3
+ setup.CPU_ONLY = True
4
+ setup.launch_setup()
README.md CHANGED
@@ -1,12 +1,217 @@
1
  ---
2
- title: Segment And Track Anything
3
- emoji: 🐨
4
- colorFrom: indigo
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 3.44.3
8
  app_file: app.py
9
- pinned: false
 
10
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Segment_and_track_Anything
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 3.35.2
6
  ---
7
+ # Segment and Track Anything (SAM-Track)
8
+ **Online Demo:** [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1R10N70AJaslzADFqb-a5OihYkllWEVxB?usp=sharing)
9
+ **Technical Report**: [![](https://img.shields.io/badge/Report-arXiv:2305.06558-green)](https://arxiv.org/abs/2305.06558)
10
+
11
+ **Tutorial:** [tutorial-v1.5 (Text)](./tutorial/tutorial%20for%20WebUI-1.5-Version.md), [tutorial-v1.0 (Click & Brush)](./tutorial/tutorial%20for%20WebUI-1.0-Version.md)
12
+
13
+ <p align="center">
14
+ <img src="./assets/top.gif" width="880">
15
+ </p>
16
+
17
+ **Segment and Track Anything** is an open-source project that focuses on the segmentation and tracking of any objects in videos, utilizing both automatic and interactive methods. The primary algorithms utilized include the [**SAM** (Segment Anything Models)](https://github.com/facebookresearch/segment-anything) for automatic/interactive key-frame segmentation and the [**DeAOT** (Decoupling features in Associating Objects with Transformers)](https://github.com/yoxu515/aot-benchmark) (NeurIPS2022) for efficient multi-object tracking and propagation. The SAM-Track pipeline enables dynamic and automatic detection and segmentation of new objects by SAM, while DeAOT is responsible for tracking all identified objects.
18
+
19
+ ## :loudspeaker:New Features
20
+ - [2023/5/12] We have authored a technical report for SAM-Track.
21
+ - [2023/5/7] We have added `demo_instseg.ipynb`, which uses Grounding-DINO to detect new objects in the key frames of a video. It can be applied in the fields of smart cities and autonomous driving.
22
+ - [2023/4/29] We have added advanced arguments for AOT-L: `long_term_memory_gap` and `max_len_long_term`.
23
+ - `long_term_memory_gap` controls the frequency at which the AOT model adds new reference frames to its long-term memory. During mask propagation, AOT matches the current frame with the reference frames stored in the long-term memory.
24
+ - Setting the gap value to a proper value helps to obtain better performance. To avoid memory explosion in long videos, we set a `max_len_long_term` value for the long-term memory storage, i.e. when the number of memory frames reaches the `max_len_long_term value`, the oldest memory frame will be discarded and a new frame will be added.
25
+
26
+ - [2023/4/26] **Interactive WebUI 1.5-Version**: We have added new features based on Interactive WebUI-1.0 Version.
27
+ - We have added a new form of interactivity—text prompts—to SAMTrack.
28
+ - From now on, multiple objects that need to be tracked can be interactively added.
29
+ - Check out [tutorial](./tutorial/tutorial%20for%20WebUI-1.5-Version.md) for Interactive WebUI 1.5-Version. More demos will be released in the next few days.
30
+ - [2023/4/26] **Image-Sequence input**: The WebUI now has a new feature that allows for input of image sequences, which can be used to test video segmentation datasets. Get started with the [tutorial](./tutorial/tutorial%20for%20Image-Sequence%20input.md) for Image-Sequence input.
31
+ - [2023/4/25] **Online Demo:** You can easily use SAMTrack in [Colab](https://colab.research.google.com/drive/1R10N70AJaslzADFqb-a5OihYkllWEVxB?usp=sharing) for visual tracking tasks.
32
+
33
+ - [2023/4/23] **Interactive WebUI:** We have introduced a new WebUI that allows interactive user segmentation through strokes and clicks. Feel free to explore and have fun with the [tutorial](./tutorial/tutorial%20for%20WebUI-1.0-Version.md)!
34
+ - [2023/4/24] **Tutorial V1.0:** Check out our new video tutorials!
35
+ - YouTube-Link: [Tutorial for Interactively modify single-object mask for first frame of video](https://www.youtube.com/watch?v=DF0iFSsX8KY)、[Tutorial for Interactively add object by click](https://www.youtube.com/watch?v=UJvKPng9_DA)、[Tutorial for Interactively add object by stroke](https://www.youtube.com/watch?v=m1oFavjIaCM).
36
+ - Bilibili Video Link:[Tutorial for Interactively modify single-object mask for first frame of video](https://www.bilibili.com/video/BV1tM4115791/?spm_id_from=333.999.0.0)、[Tutorial for Interactively add object by click](https://www.bilibili.com/video/BV1Qs4y1A7d1/)、[Tutorial for Interactively add object by stroke](https://www.bilibili.com/video/BV1Lm4y117J4/?spm_id_from=333.999.0.0).
37
+ - 1.0-Version is a developer version, please feel free to contact us if you encounter any bugs :bug:.
38
+
39
+ - [2023/4/17] **SAMTrack**: Automatically segment and track anything in video!
40
+
41
+ ## :fire:Demos
42
+ <div align=center>
43
+
44
+ [![Segment-and-Track-Anything Versatile Demo](https://res.cloudinary.com/marcomontalbano/image/upload/v1681713095/video_to_markdown/images/youtube--UPhtpf1k6HA-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://youtu.be/UPhtpf1k6HA "Segment-and-Track-Anything Versatile Demo")
45
+ </div>
46
+
47
+ This video showcases the segmentation and tracking capabilities of SAM-Track in various scenarios, such as street views, AR, cells, animations, aerial shots, and more.
48
+
49
+ ## :calendar:TODO
50
+ - [x] Colab notebook: Completed on April 25th, 2023.
51
+ - [x] 1.0-Version Interactive WebUI: Completed on April 23rd, 2023.
52
+ - We will create a feature that enables users to interactively modify the mask for the initial video frame according to their needs. The interactive segmentation capabilities of Segment-and-Track-Anything is demonstrated in [Demo8](https://www.youtube.com/watch?v=Xyd54AngvV8&feature=youtu.be) and [Demo9](https://www.youtube.com/watch?v=eZrdna8JkoQ).
53
+ - Bilibili Video Link: [Demo8](https://www.bilibili.com/video/BV1JL411v7uE/), [Demo9](https://www.bilibili.com/video/BV1Qs4y1w763/).
54
+ - [x] 1.5-Version Interactive WebUI: Completed on April 26th, 2023.
55
+ - We will develop a function that allows interactive modification of multi-object masks for the first frame of a video. This function will be based on Version 1.0. YouTube: [Demo4](https://www.youtube.com/watch?v=UFtwFaOfx2I&feature=youtu.be), [Demo5](https://www.youtube.com/watch?v=cK5MPFdJdSY&feature=youtu.be); Bilibili: [Demo4](https://www.bilibili.com/video/BV17X4y127mJ/), [Demo5](https://www.bilibili.com/video/BV1Pz4y1a7mC/)
56
+ - Furthermore, we plan to include text prompts as an additional form of interaction. YouTube: [Demo1](https://www.youtube.com/watch?v=5oieHqFIJPc&feature=youtu.be), [Demo2](https://www.youtube.com/watch?v=nXfq17X6ohk); Bilibili: [Demo1](https://www.bilibili.com/video/BV1hg4y157yd/?vd_source=fe3b5c0215d05cc44c8eb3d94abae3ca), [Demo2](https://www.bilibili.com/video/BV1RV4y1k7i5/)
57
+ - [ ] 2.x-Version Interactive WebUI
58
+ - In version 2.x, the segmentation model will offer two options: SAM and SEEM.
59
+ - We will develop a new function where the fixed-category object detection result can be displayed as a prompt.
60
+ - We will enable SAM-Track to add and modify objects during tracking. YouTube: [Demo6](https://www.youtube.com/watch?v=l7hXM1a3nEA&feature=youtu.be
61
+ ), [Demo7](https://www.youtube.com/watch?v=hPjw28Ul4cw&feature=youtu.be); Bilibili: [Demo6](https://www.bilibili.com/video/BV1nk4y1j7Am), [Demo7](https://www.bilibili.com/video/BV1mk4y1E78s/?vd_source=fe3b5c0215d05cc44c8eb3d94abae3ca)
62
+
63
+ **Demo1** showcases SAM-Track's ability to take the class of objects as prompt. The user gives the category text 'panda' to enable instance-level segmentation and tracking of all objects belonging to this category.
64
+ <div align=center>
65
+
66
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683347297/video_to_markdown/images/youtube--5oieHqFIJPc-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=5oieHqFIJPc&feature=youtu.be "demo1")
67
+ </div>
68
+
69
+ **Demo2** showcases SAM-Track's ability to take the text description as prompt. SAM-Track could segment and track target objects given the input that 'panda on the far left'.
70
+ <div align=center>
71
+
72
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683347643/video_to_markdown/images/youtube--nXfq17X6ohk-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=nXfq17X6ohk "demo1")
73
+ </div>
74
+
75
+
76
+ **Demo3** showcases SAM-Track's ability to track numerous objects at the same time. SAM-Track is capable of automatically detecting newly appearing objects.
77
+ <div align=center>
78
+
79
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683347961/video_to_markdown/images/youtube--jMqFMq0tRP0-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=jMqFMq0tRP0 "demo1")
80
+ </div>
81
+
82
+ **Demo4** showcases SAM-Track's ability to take multiple modes of interactions as prompt. The user specified human and skateboard with click and brushstroke, respectively.
83
+ <div align=center>
84
+
85
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683348115/video_to_markdown/images/youtube--UFtwFaOfx2I-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=UFtwFaOfx2I&feature=youtu.be "demo1")
86
+ </div>
87
+
88
+
89
+ **Demo5** showcases SAM-Track's ability to refine the results of segment-everything. The user merges the tram as a whole with a single click.
90
+ <div align=center>
91
+
92
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683348276/video_to_markdown/images/youtube--cK5MPFdJdSY-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=cK5MPFdJdSY&feature=youtu.be "demo1")
93
+ </div>
94
+
95
+ **Demo6** showcases SAM-Track's ability to add new objects during tracking. The user annotates another car by rolling back to an intermediate frame.
96
+ <div align=center>
97
+
98
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683348411/video_to_markdown/images/youtube--l7hXM1a3nEA-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=l7hXM1a3nEA "demo1")
99
+ </div>
100
+
101
+ **Demo7** showcases SAM-Track's ability to refine the prediction during tracking. This feature is highly advantageous for segmentation and tracking under complex environments.
102
+ <div align=center>
103
+
104
+ [![demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1683348621/video_to_markdown/images/youtube--hPjw28Ul4cw-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=hPjw28Ul4cw&feature=youtu.be "demo1")
105
+ </div>
106
+
107
+ **Demo8** showcases SAM-Track's ability to interactively segment and track individual objects. The user specified that SAM-Track tracked a man playing street basketball.
108
+ <div align=center>
109
+
110
+ [![Interactive Segment-and-Track-Anything Demo1](https://res.cloudinary.com/marcomontalbano/image/upload/v1681712022/video_to_markdown/images/youtube--Xyd54AngvV8-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=Xyd54AngvV8 "Interactive Segment-and-Track-Anything Demo1")
111
+ </div>
112
+
113
+ **Demo9** showcases SAM-Track's ability to interactively add specified objects for tracking.The user customized the addition of objects to be tracked on top of the segmentation of everything in the scene using SAM-Track.
114
+ <div align=center>
115
+
116
+ [![Interactive Segment-and-Track-Anything Demo2](https://res.cloudinary.com/marcomontalbano/image/upload/v1681712071/video_to_markdown/images/youtube--eZrdna8JkoQ-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=eZrdna8JkoQ "Interactive Segment-and-Track-Anything Demo2")
117
+ </div>
118
+
119
+ ## :computer:Getting Started
120
+ ### :bookmark_tabs:Requirements
121
+
122
+ The [Segment-Anything](https://github.com/facebookresearch/segment-anything) repository has been cloned and renamed as sam, and the [aot-benchmark](https://github.com/yoxu515/aot-benchmark) repository has been cloned and renamed as aot.
123
+
124
+ Please check the dependency requirements in [SAM](https://github.com/facebookresearch/segment-anything) and [DeAOT](https://github.com/yoxu515/aot-benchmark).
125
+
126
+ The implementation is tested under python 3.9, as well as pytorch 1.10 and torchvision 0.11. **We recommend equivalent or higher pytorch version**.
127
+
128
+ Use the `install.sh` to install the necessary libs for SAM-Track
129
+ ```
130
+ bash script/install.sh
131
+ ```
132
+
133
+ ### :star:Model Preparation
134
+ Download SAM model to ckpt, the default model is SAM-VIT-B ([sam_vit_b_01ec64.pth](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth)).
135
+
136
+ Download DeAOT/AOT model to ckpt, the default model is R50-DeAOT-L ([R50_DeAOTL_PRE_YTB_DAV.pth](https://drive.google.com/file/d/1QoChMkTVxdYZ_eBlZhK2acq9KMQZccPJ/view)).
137
+
138
+ Download Grounding-Dino model to ckpt, the default model is GroundingDINO-T ([groundingdino_swint_ogc](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swint_ogc.pth)).
139
+
140
+ You can download the default weights using the command line as shown below.
141
+ ```
142
+ bash script/download_ckpt.sh
143
+ ```
144
+
145
+ ### :heart:Run Demo
146
+ - The video to be processed can be put in ./assets.
147
+ - Then run **demo.ipynb** step by step to generate results.
148
+ - The results will be saved as masks for each frame and a gif file for visualization.
149
+
150
+ The arguments for SAM-Track, DeAOT and SAM can be manually modified in model_args.py for purpose of using other models or controling the behavior of each model.
151
+
152
+ ### :muscle:WebUI App
153
+ Our user-friendly visual interface allows you to easily obtain the results of your experiments. Simply initiate it using the command line.
154
+
155
+ ```
156
+ python app.py
157
+ ```
158
+ Users can upload the video directly on the UI and use SegTracker to automatically/interactively track objects within that video. We use a video of a man playing basketball as an example.
159
+
160
+ ![Interactive WebUI](./assets/interactive_webui.jpg)
161
+
162
+ SegTracker-Parameters:
163
+ - **aot_model**: used to select which version of DeAOT/AOT to use for tracking and propagation.
164
+ - **sam_gap**: used to control how often SAM is used to add newly appearing objects at specified frame intervals. Increase to decrease the frequency of discovering new targets, but significantly improve speed of inference.
165
+ - **points_per_side**: used to control the number of points per side used for generating masks by sampling a grid over the image. Increasing the size enhances the ability to detect small objects, but larger targets may be segmented into finer granularity.
166
+ - **max_obj_num**: used to limit the maximum number of objects that SAM-Track can detect and track. A larger number of objects necessitates a greater utilization of memory, with approximately 16GB of memory capable of processing a maximum of 255 objects.
167
+
168
+ Usage: To see the details, please refer to the [tutorial for 1.0-Version WebUI](./tutorial/tutorial%20for%20WebUI-1.0-Version.md).
169
+
170
+ ### :school:About us
171
+ Thank you for your interest in this project. The project is supervised by the ReLER Lab at Zhejiang University’s College of Computer Science and Technology. ReLER was established by Yang Yi, a Qiu Shi Distinguished Professor at Zhejiang University. Our dedicated team of contributors includes [Yangming Cheng](https://github.com/yamy-cheng), [Yuanyou Xu](https://github.com/yoxu515), [Liulei Li](https://github.com/lingorX), Xiaodi Li, [Zongxin Yang](https://z-x-yang.github.io/), [Wenguan Wang](https://sites.google.com/view/wenguanwang) and [Yi Yang](https://scholar.google.com/citations?user=RMSuNFwAAAAJ&hl=en).
172
+
173
+ ### :full_moon_with_face:Credits
174
+ Licenses for borrowed code can be found in [licenses.md](https://github.com/z-x-yang/Segment-and-Track-Anything/blob/main/licenses.md) file.
175
+
176
+ * DeAOT/AOT - [https://github.com/yoxu515/aot-benchmark](https://github.com/yoxu515/aot-benchmark)
177
+ * SAM - [https://github.com/facebookresearch/segment-anything](https://github.com/facebookresearch/segment-anything)
178
+ * Gradio (for building WebUI) - [https://github.com/gradio-app/gradio](https://github.com/gradio-app/gradio)
179
+ * Grounding-Dino - [https://github.com/yamy-cheng/GroundingDINO](https://github.com/yamy-cheng/GroundingDINO)
180
+
181
+ ### License
182
+ The project is licensed under the [AGPL-3.0 license](https://github.com/z-x-yang/Segment-and-Track-Anything/blob/main/LICENSE.txt). To utilize or further develop this project for commercial purposes through proprietary means, permission must be granted by us (as well as the owners of any borrowed code).
183
 
184
+ ### Citations
185
+ Please consider citing the related paper(s) in your publications if it helps your research.
186
+ ```
187
+ @article{cheng2023segment,
188
+ title={Segment and Track Anything},
189
+ author={Cheng, Yangming and Li, Liulei and Xu, Yuanyou and Li, Xiaodi and Yang, Zongxin and Wang, Wenguan and Yang, Yi},
190
+ journal={arXiv preprint arXiv:2305.06558},
191
+ year={2023}
192
+ }
193
+ @article{kirillov2023segment,
194
+ title={Segment anything},
195
+ author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C and Lo, Wan-Yen and others},
196
+ journal={arXiv preprint arXiv:2304.02643},
197
+ year={2023}
198
+ }
199
+ @inproceedings{yang2022deaot,
200
+ title={Decoupling Features in Hierarchical Propagation for Video Object Segmentation},
201
+ author={Yang, Zongxin and Yang, Yi},
202
+ booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
203
+ year={2022}
204
+ }
205
+ @inproceedings{yang2021aot,
206
+ title={Associating Objects with Transformers for Video Object Segmentation},
207
+ author={Yang, Zongxin and Wei, Yunchao and Yang, Yi},
208
+ booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
209
+ year={2021}
210
+ }
211
+ @article{liu2023grounding,
212
+ title={Grounding dino: Marrying dino with grounded pre-training for open-set object detection},
213
+ author={Liu, Shilong and Zeng, Zhaoyang and Ren, Tianhe and Li, Feng and Zhang, Hao and Yang, Jie and Li, Chunyuan and Yang, Jianwei and Su, Hang and Zhu, Jun and others},
214
+ journal={arXiv preprint arXiv:2303.05499},
215
+ year={2023}
216
+ }
217
+ ```
SegTracker.py ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ sys.path.append("..")
3
+ sys.path.append("./sam")
4
+ from sam.segment_anything import sam_model_registry, SamAutomaticMaskGenerator
5
+ from aot_tracker import get_aot
6
+ import numpy as np
7
+ from tool.segmentor import Segmentor
8
+ from tool.detector import Detector
9
+ from tool.transfer_tools import draw_outline, draw_points
10
+ import cv2
11
+ from seg_track_anything import draw_mask
12
+
13
+
14
+ class SegTracker():
15
+ def __init__(self,segtracker_args, sam_args, aot_args) -> None:
16
+ """
17
+ Initialize SAM and AOT.
18
+ """
19
+ self.sam = Segmentor(sam_args)
20
+ self.tracker = get_aot(aot_args)
21
+ self.detector = Detector(self.sam.device)
22
+ self.sam_gap = segtracker_args['sam_gap']
23
+ self.min_area = segtracker_args['min_area']
24
+ self.max_obj_num = segtracker_args['max_obj_num']
25
+ self.min_new_obj_iou = segtracker_args['min_new_obj_iou']
26
+ self.reference_objs_list = []
27
+ self.object_idx = 1
28
+ self.curr_idx = 1
29
+ self.origin_merged_mask = None # init by segment-everything or update
30
+ self.first_frame_mask = None
31
+
32
+ # debug
33
+ self.everything_points = []
34
+ self.everything_labels = []
35
+ print("SegTracker has been initialized")
36
+
37
+ def seg(self,frame):
38
+ '''
39
+ Arguments:
40
+ frame: numpy array (h,w,3)
41
+ Return:
42
+ origin_merged_mask: numpy array (h,w)
43
+ '''
44
+ frame = frame[:, :, ::-1]
45
+ anns = self.sam.everything_generator.generate(frame)
46
+
47
+ # anns is a list recording all predictions in an image
48
+ if len(anns) == 0:
49
+ return
50
+ # merge all predictions into one mask (h,w)
51
+ # note that the merged mask may lost some objects due to the overlapping
52
+ self.origin_merged_mask = np.zeros(anns[0]['segmentation'].shape,dtype=np.uint8)
53
+ idx = 1
54
+ for ann in anns:
55
+ if ann['area'] > self.min_area:
56
+ m = ann['segmentation']
57
+ self.origin_merged_mask[m==1] = idx
58
+ idx += 1
59
+ self.everything_points.append(ann["point_coords"][0])
60
+ self.everything_labels.append(1)
61
+
62
+ obj_ids = np.unique(self.origin_merged_mask)
63
+ obj_ids = obj_ids[obj_ids!=0]
64
+
65
+ self.object_idx = 1
66
+ for id in obj_ids:
67
+ if np.sum(self.origin_merged_mask==id) < self.min_area or self.object_idx > self.max_obj_num:
68
+ self.origin_merged_mask[self.origin_merged_mask==id] = 0
69
+ else:
70
+ self.origin_merged_mask[self.origin_merged_mask==id] = self.object_idx
71
+ self.object_idx += 1
72
+
73
+ self.first_frame_mask = self.origin_merged_mask
74
+ return self.origin_merged_mask
75
+
76
+ def update_origin_merged_mask(self, updated_merged_mask):
77
+ self.origin_merged_mask = updated_merged_mask
78
+ # obj_ids = np.unique(updated_merged_mask)
79
+ # obj_ids = obj_ids[obj_ids!=0]
80
+ # self.object_idx = int(max(obj_ids)) + 1
81
+
82
+ def reset_origin_merged_mask(self, mask, id):
83
+ self.origin_merged_mask = mask
84
+ self.curr_idx = id
85
+
86
+ def add_reference(self,frame,mask,frame_step=0):
87
+ '''
88
+ Add objects in a mask for tracking.
89
+ Arguments:
90
+ frame: numpy array (h,w,3)
91
+ mask: numpy array (h,w)
92
+ '''
93
+ self.reference_objs_list.append(np.unique(mask))
94
+ self.curr_idx = self.get_obj_num() + 1
95
+ self.tracker.add_reference_frame(frame,mask, self.curr_idx - 1, frame_step)
96
+
97
+ def track(self,frame,update_memory=False):
98
+ '''
99
+ Track all known objects.
100
+ Arguments:
101
+ frame: numpy array (h,w,3)
102
+ Return:
103
+ origin_merged_mask: numpy array (h,w)
104
+ '''
105
+ pred_mask = self.tracker.track(frame)
106
+ if update_memory:
107
+ self.tracker.update_memory(pred_mask)
108
+ return pred_mask.squeeze(0).squeeze(0).detach().cpu().numpy().astype(np.uint8)
109
+
110
+ def get_tracking_objs(self):
111
+ objs = set()
112
+ for ref in self.reference_objs_list:
113
+ objs.update(set(ref))
114
+ objs = list(sorted(list(objs)))
115
+ objs = [i for i in objs if i!=0]
116
+ return objs
117
+
118
+ def get_obj_num(self):
119
+ objs = self.get_tracking_objs()
120
+ if len(objs) == 0: return 0
121
+ return int(max(objs))
122
+
123
+ def find_new_objs(self, track_mask, seg_mask):
124
+ '''
125
+ Compare tracked results from AOT with segmented results from SAM. Select objects from background if they are not tracked.
126
+ Arguments:
127
+ track_mask: numpy array (h,w)
128
+ seg_mask: numpy array (h,w)
129
+ Return:
130
+ new_obj_mask: numpy array (h,w)
131
+ '''
132
+ new_obj_mask = (track_mask==0) * seg_mask
133
+ new_obj_ids = np.unique(new_obj_mask)
134
+ new_obj_ids = new_obj_ids[new_obj_ids!=0]
135
+ # obj_num = self.get_obj_num() + 1
136
+ obj_num = self.curr_idx
137
+ for idx in new_obj_ids:
138
+ new_obj_area = np.sum(new_obj_mask==idx)
139
+ obj_area = np.sum(seg_mask==idx)
140
+ if new_obj_area/obj_area < self.min_new_obj_iou or new_obj_area < self.min_area\
141
+ or obj_num > self.max_obj_num:
142
+ new_obj_mask[new_obj_mask==idx] = 0
143
+ else:
144
+ new_obj_mask[new_obj_mask==idx] = obj_num
145
+ obj_num += 1
146
+ return new_obj_mask
147
+
148
+ def restart_tracker(self):
149
+ self.tracker.restart()
150
+
151
+ def seg_acc_bbox(self, origin_frame: np.ndarray, bbox: np.ndarray,):
152
+ ''''
153
+ Use bbox-prompt to get mask
154
+ Parameters:
155
+ origin_frame: H, W, C
156
+ bbox: [[x0, y0], [x1, y1]]
157
+ Return:
158
+ refined_merged_mask: numpy array (h, w)
159
+ masked_frame: numpy array (h, w, c)
160
+ '''
161
+ # get interactive_mask
162
+ interactive_mask = self.sam.segment_with_box(origin_frame, bbox)[0]
163
+ refined_merged_mask = self.add_mask(interactive_mask)
164
+
165
+ # draw mask
166
+ masked_frame = draw_mask(origin_frame.copy(), refined_merged_mask)
167
+
168
+ # draw bbox
169
+ masked_frame = cv2.rectangle(masked_frame, bbox[0], bbox[1], (0, 0, 255))
170
+
171
+ return refined_merged_mask, masked_frame
172
+
173
+ def seg_acc_click(self, origin_frame: np.ndarray, coords: np.ndarray, modes: np.ndarray, multimask=True):
174
+ '''
175
+ Use point-prompt to get mask
176
+ Parameters:
177
+ origin_frame: H, W, C
178
+ coords: nd.array [[x, y]]
179
+ modes: nd.array [[1]]
180
+ Return:
181
+ refined_merged_mask: numpy array (h, w)
182
+ masked_frame: numpy array (h, w, c)
183
+ '''
184
+ # get interactive_mask
185
+ interactive_mask = self.sam.segment_with_click(origin_frame, coords, modes, multimask)
186
+
187
+ refined_merged_mask = self.add_mask(interactive_mask)
188
+
189
+ # draw mask
190
+ masked_frame = draw_mask(origin_frame.copy(), refined_merged_mask)
191
+
192
+ # draw points
193
+ # self.everything_labels = np.array(self.everything_labels).astype(np.int64)
194
+ # self.everything_points = np.array(self.everything_points).astype(np.int64)
195
+
196
+ masked_frame = draw_points(coords, modes, masked_frame)
197
+
198
+ # draw outline
199
+ masked_frame = draw_outline(interactive_mask, masked_frame)
200
+
201
+ return refined_merged_mask, masked_frame
202
+
203
+ def add_mask(self, interactive_mask: np.ndarray):
204
+ '''
205
+ Merge interactive mask with self.origin_merged_mask
206
+ Parameters:
207
+ interactive_mask: numpy array (h, w)
208
+ Return:
209
+ refined_merged_mask: numpy array (h, w)
210
+ '''
211
+ if self.origin_merged_mask is None:
212
+ self.origin_merged_mask = np.zeros(interactive_mask.shape,dtype=np.uint8)
213
+
214
+ refined_merged_mask = self.origin_merged_mask.copy()
215
+ refined_merged_mask[interactive_mask > 0] = self.curr_idx
216
+
217
+ return refined_merged_mask
218
+
219
+ def detect_and_seg(self, origin_frame: np.ndarray, grounding_caption, box_threshold, text_threshold, box_size_threshold=1, reset_image=False):
220
+ '''
221
+ Using Grounding-DINO to detect object acc Text-prompts
222
+ Retrun:
223
+ refined_merged_mask: numpy array (h, w)
224
+ annotated_frame: numpy array (h, w, 3)
225
+ '''
226
+ # backup id and origin-merged-mask
227
+ bc_id = self.curr_idx
228
+ bc_mask = self.origin_merged_mask
229
+
230
+ # get annotated_frame and boxes
231
+ annotated_frame, boxes = self.detector.run_grounding(origin_frame, grounding_caption, box_threshold, text_threshold)
232
+ for i in range(len(boxes)):
233
+ bbox = boxes[i]
234
+ if (bbox[1][0] - bbox[0][0]) * (bbox[1][1] - bbox[0][1]) > annotated_frame.shape[0] * annotated_frame.shape[1] * box_size_threshold:
235
+ continue
236
+ interactive_mask = self.sam.segment_with_box(origin_frame, bbox, reset_image)[0]
237
+ refined_merged_mask = self.add_mask(interactive_mask)
238
+ self.update_origin_merged_mask(refined_merged_mask)
239
+ self.curr_idx += 1
240
+
241
+ # reset origin_mask
242
+ self.reset_origin_merged_mask(bc_mask, bc_id)
243
+
244
+ return refined_merged_mask, annotated_frame
245
+
246
+ if __name__ == '__main__':
247
+ from model_args import segtracker_args,sam_args,aot_args
248
+
249
+ Seg_Tracker = SegTracker(segtracker_args, sam_args, aot_args)
250
+
251
+ # ------------------ detect test ----------------------
252
+
253
+ origin_frame = cv2.imread('/data2/cym/Seg_Tra_any/Segment-and-Track-Anything/debug/point.png')
254
+ origin_frame = cv2.cvtColor(origin_frame, cv2.COLOR_BGR2RGB)
255
+ grounding_caption = "swan.water"
256
+ box_threshold = 0.25
257
+ text_threshold = 0.25
258
+
259
+ predicted_mask, annotated_frame = Seg_Tracker.detect_and_seg(origin_frame, grounding_caption, box_threshold, text_threshold)
260
+ masked_frame = draw_mask(annotated_frame, predicted_mask)
261
+ origin_frame = cv2.cvtColor(origin_frame, cv2.COLOR_RGB2BGR)
262
+
263
+ cv2.imwrite('./debug/masked_frame.png', masked_frame)
264
+ cv2.imwrite('./debug/x.png', annotated_frame)
__pycache__/SegTracker.cpython-310.pyc ADDED
Binary file (8.02 kB). View file
 
__pycache__/aot_tracker.cpython-310.pyc ADDED
Binary file (5.69 kB). View file
 
__pycache__/model_args.cpython-310.pyc ADDED
Binary file (748 Bytes). View file
 
__pycache__/seg_track_anything.cpython-310.pyc ADDED
Binary file (6.48 kB). View file
 
aot/LICENSE ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, z-x-yang
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
aot/MODEL_ZOO.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Model Zoo and Results
2
+
3
+ ### Environment and Settings
4
+ - 4/1 NVIDIA V100 GPUs for training/evaluation.
5
+ - Auto-mixed precision was enabled in training but disabled in evaluation.
6
+ - Test-time augmentations were not used.
7
+ - The inference resolution of DAVIS/YouTube-VOS was 480p/1.3x480p as [CFBI](https://github.com/z-x-yang/CFBI).
8
+ - Fully online inference. We passed all the modules frame by frame.
9
+ - Multi-object FPS was recorded instead of single-object one.
10
+
11
+ ### Pre-trained Models
12
+ Stages:
13
+
14
+ - `PRE`: the pre-training stage with static images.
15
+
16
+ - `PRE_YTB_DAV`: the main-training stage with YouTube-VOS and DAVIS. All the kinds of evaluation share an **identical** model and the **same** parameters.
17
+
18
+
19
+ | Model | Param (M) | PRE | PRE_YTB_DAV |
20
+ |:---------- |:---------:|:--------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------:|
21
+ | AOTT | 5.7 | [gdrive](https://drive.google.com/file/d/1_513h8Hok9ySQPMs_dHgX5sPexUhyCmy/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1owPmwV4owd_ll6GuilzklqTyAd0ZvbCu/view?usp=sharing) |
22
+ | AOTS | 7.0 | [gdrive](https://drive.google.com/file/d/1QUP0-VED-lOF1oX_ppYWnXyBjvUzJJB7/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1beU5E6Mdnr_pPrgjWvdWurKAIwJSz1xf/view?usp=sharing) |
23
+ | AOTB | 8.3 | [gdrive](https://drive.google.com/file/d/11Bx8n_INAha1IdpHjueGpf7BrKmCJDvK/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1hH-GOn4GAxHkV8ARcQzsUy8Ax6ndot-A/view?usp=sharing) |
24
+ | AOTL | 8.3 | [gdrive](https://drive.google.com/file/d/1WL6QCsYeT7Bt-Gain9ZIrNNXpR2Hgh29/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1L1N2hkSPqrwGgnW9GyFHuG59_EYYfTG4/view?usp=sharing) |
25
+ | R50-AOTL | 14.9 | [gdrive](https://drive.google.com/file/d/1hS4JIvOXeqvbs-CokwV6PwZV-EvzE6x8/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1qJDYn3Ibpquu4ffYoQmVjg1YCbr2JQep/view?usp=sharing) |
26
+ | SwinB-AOTL | 65.4 | [gdrive](https://drive.google.com/file/d/1LlhKQiXD8JyZGGs3hZiNzcaCLqyvL9tj/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/192jCGQZdnuTsvX-CVra-KVZl2q1ZR0vW/view?usp=sharing) |
27
+
28
+ | Model | Param (M) | PRE | PRE_YTB_DAV |
29
+ |:---------- |:---------:|:--------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------:|
30
+ | DeAOTT | 7.2 | [gdrive](https://drive.google.com/file/d/11C1ZBoFpL3ztKtINS8qqwPSldfYXexFK/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1ThWIZQS03cYWx1EKNN8MIMnJS5eRowzr/view?usp=sharing) |
31
+ | DeAOTS | 10.2 | [gdrive](https://drive.google.com/file/d/1uUidrWVoaP9A5B5-EzQLbielUnRLRF3j/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1YwIAV5tBtn5spSFxKLBQBEQGwPHyQlHi/view?usp=sharing) |
32
+ | DeAOTB | 13.2 | [gdrive](https://drive.google.com/file/d/1bEQr6vIgQMVITrSOtxWTMgycKpS0cor9/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1BHxsonnvJXylqHlZ1zJHHc-ymKyq-CFf/view?usp=sharing) |
33
+ | DeAOTL | 13.2 | [gdrive](https://drive.google.com/file/d/1_vBL4KJlmBy0oBE4YFDOvsYL1ZtpEL32/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/18elNz_wi9JyVBcIUYKhRdL08MA-FqHD5/view?usp=sharing) |
34
+ | R50-DeAOTL | 19.8 | [gdrive](https://drive.google.com/file/d/1sTRQ1g0WCpqVCdavv7uJiZNkXunBt3-R/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1QoChMkTVxdYZ_eBlZhK2acq9KMQZccPJ/view?usp=sharing) |
35
+ | SwinB-DeAOTL | 70.3 | [gdrive](https://drive.google.com/file/d/16BZEE53no8CxT-pPLDC2q1d6Xlg8mWPU/view?usp=sharing) | [gdrive](https://drive.google.com/file/d/1g4E-F0RPOx9Nd6J7tU9AE1TjsouL4oZq/view?usp=sharing) |
36
+
37
+ To use our pre-trained model to infer, a simple way is to set `--model` and `--ckpt_path` to your downloaded checkpoint's model type and file path when running `eval.py`.
38
+
39
+ ### YouTube-VOS 2018 val
40
+ `ALL-F`: all frames. The default evaluation setting of YouTube-VOS is 6fps, but 30fps sequences (all the frames) are also supplied by the dataset organizers. We noticed that many VOS methods prefer to evaluate with 30fps videos. Thus, we also supply our results here. Denser video sequences can significantly improve VOS performance when using the memory reading strategy (like AOTL, R50-AOTL, and SwinB-AOTL), but the efficiency will be influenced since more memorized frames are stored for object matching.
41
+ | Model | Stage | FPS | All-F | Mean | J Seen | F Seen | J Unseen | F Unseen | Predictions |
42
+ |:------------ |:-----------:|:--------:|:-----:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------------------------------------------------------------------------------------------:|
43
+ | AOTT | PRE_YTB_DAV | 41.0 | | 80.2 | 80.4 | 85.0 | 73.6 | 81.7 | [gdrive](https://drive.google.com/file/d/1u8mvPRT08ENZHsw9Xf_4C6Sv9BoCzENR/view?usp=sharing) |
44
+ | AOTT | PRE_YTB_DAV | 41.0 | √ | 80.9 | 80.0 | 84.7 | 75.2 | 83.5 | [gdrive](https://drive.google.com/file/d/1RGMI5-29Z0odq73rt26eCxOUYUd-fvVv/view?usp=sharing) |
45
+ | DeAOTT | PRE_YTB_DAV | **53.4** | | **82.0** | **81.6** | **86.3** | **75.8** | **84.2** | - |
46
+ | AOTS | PRE_YTB_DAV | 27.1 | | 82.9 | 82.3 | 87.0 | 77.1 | 85.1 | [gdrive](https://drive.google.com/file/d/1a4-rNnxjMuPBq21IKo31WDYZXMPgS7r2/view?usp=sharing) |
47
+ | AOTS | PRE_YTB_DAV | 27.1 | √ | 83.0 | 82.2 | 87.0 | 77.3 | 85.7 | [gdrive](https://drive.google.com/file/d/1Z0cndyoCw5Na6u-VFRE8CyiIG2RbMIUO/view?usp=sharing) |
48
+ | DeAOTS | PRE_YTB_DAV | **38.7** | | **84.0** | **83.3** | **88.3** | **77.9** | **86.6** | - |
49
+ | AOTB | PRE_YTB_DAV | 20.5 | | 84.0 | 83.2 | 88.1 | 78.0 | 86.5 | [gdrive](https://drive.google.com/file/d/1J5nhuQbbjVLYNXViBIgo21ddQy-MiOLG/view?usp=sharing) |
50
+ | AOTB | PRE_YTB_DAV | 20.5 | √ | 84.1 | 83.6 | 88.5 | 78.0 | 86.5 | [gdrive](https://drive.google.com/file/d/1gFaweB_GTJjHzSD61v_ZsY9K7UEND30O/view?usp=sharing) |
51
+ | DeAOTB | PRE_YTB_DAV | **30.4** | | **84.6** | **83.9** | **88.9** | **78.5** | **87.0** | - |
52
+ | AOTL | PRE_YTB_DAV | 16.0 | | 84.1 | 83.2 | 88.2 | 78.2 | 86.8 | [gdrive](https://drive.google.com/file/d/1kS8KWQ2L3wzxt44ROLTxwZOT7ZpT8Igc/view?usp=sharing) |
53
+ | AOTL | PRE_YTB_DAV | 6.5 | √ | 84.5 | 83.7 | 88.8 | 78.4 | **87.1** | [gdrive](https://drive.google.com/file/d/1Rpm3e215kJOUvb562lJ2kYg2I3hkrxiM/view?usp=sharing) |
54
+ | DeAOTL | PRE_YTB_DAV | **24.7** | | **84.8** | **84.2** | **89.4** | **78.6** | 87.0 | - |
55
+ | R50-AOTL | PRE_YTB_DAV | 14.9 | | 84.6 | 83.7 | 88.5 | 78.8 | 87.3 | [gdrive](https://drive.google.com/file/d/1nbJZ1bbmEgyK-bg6HQ8LwCz5gVJ6wzIZ/view?usp=sharing) |
56
+ | R50-AOTL | PRE_YTB_DAV | 6.4 | √ | 85.5 | 84.5 | 89.5 | 79.6 | 88.2 | [gdrive](https://drive.google.com/file/d/1NbB54ZhYvfJh38KFOgovYYPjWopd-2TE/view?usp=sharing) |
57
+ | R50-DeAOTL | PRE_YTB_DAV | **22.4** | | **86.0** | **84.9** | **89.9** | **80.4** | **88.7** | - |
58
+ | SwinB-AOTL | PRE_YTB_DAV | 9.3 | | 84.7 | 84.5 | 89.5 | 78.1 | 86.7 | [gdrive](https://drive.google.com/file/d/1QFowulSY0LHfpsjUV8ZE9rYc55L9DOC7/view?usp=sharing) |
59
+ | SwinB-AOTL | PRE_YTB_DAV | 5.2 | √ | 85.1 | 85.1 | 90.1 | 78.4 | 86.9 | [gdrive](https://drive.google.com/file/d/1TulhVOhh01rkssNYbOQASeWKu7CQ5Azx/view?usp=sharing) |
60
+ | SwinB-DeAOTL | PRE_YTB_DAV | **11.9** | | **86.2** | **85.6** | **90.6** | **80.0** | **88.4** | - |
61
+
62
+ ### YouTube-VOS 2019 val
63
+ | Model | Stage | FPS | All-F | Mean | J Seen | F Seen | J Unseen | F Unseen | Predictions |
64
+ |:------------ |:-----------:|:--------:|:-----:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------------------------------------------------------------------------------------------:|
65
+ | AOTT | PRE_YTB_DAV | 41.0 | | 80.0 | 79.8 | 84.2 | 74.1 | 82.1 | [gdrive](https://drive.google.com/file/d/1zzyhN1XYtajte5nbZ7opOdfXeDJgCxC5/view?usp=sharing) |
66
+ | AOTT | PRE_YTB_DAV | 41.0 | √ | 80.9 | 79.9 | 84.4 | 75.6 | 83.8 | [gdrive](https://drive.google.com/file/d/1V_5vi9dAXOis_WrDieacSESm7OX20Bv-/view?usp=sharing) |
67
+ | DeAOTT | PRE_YTB_DAV | **53.4** | | **82.0** | **81.2** | **85.6** | **76.4** | **84.7** | - |
68
+ | AOTS | PRE_YTB_DAV | 27.1 | | 82.7 | 81.9 | 86.5 | 77.3 | 85.2 | [gdrive](https://drive.google.com/file/d/11YdkUeyjkTv8Uw7xMgPCBzJs6v5SDt6n/view?usp=sharing) |
69
+ | AOTS | PRE_YTB_DAV | 27.1 | √ | 82.8 | 81.9 | 86.5 | 77.3 | 85.6 | [gdrive](https://drive.google.com/file/d/1UhyurGTJeAw412czU3_ebzNwF8xQ4QG_/view?usp=sharing) |
70
+ | DeAOTS | PRE_YTB_DAV | **38.7** | | **83.8** | **82.8** | **87.5** | **78.1** | **86.8** | - |
71
+ | AOTB | PRE_YTB_DAV | 20.5 | | 84.0 | 83.1 | 87.7 | 78.5 | 86.8 | [gdrive](https://drive.google.com/file/d/1NeI8cT4kVqTqVWAwtwiga1rkrvksNWaO/view?usp=sharing) |
72
+ | AOTB | PRE_YTB_DAV | 20.5 | √ | 84.1 | 83.3 | 88.0 | 78.2 | 86.7 | [gdrive](https://drive.google.com/file/d/1kpYV2XFR0sOfLWD-wMhd-nUO6CFiLjlL/view?usp=sharing) |
73
+ | DeAOTB | PRE_YTB_DAV | **30.4** | | **84.6** | **83.5** | **88.3** | **79.1** | **87.5** | - |
74
+ | AOTL | PRE_YTB_DAV | 16.0 | | 84.0 | 82.8 | 87.6 | 78.6 | 87.1 | [gdrive](https://drive.google.com/file/d/1qKLlNXxmT31bW0weEHI_zAf4QwU8Lhou/view?usp=sharing) |
75
+ | AOTL | PRE_YTB_DAV | 6.5 | √ | 84.2 | 83.0 | 87.8 | 78.7 | 87.3 | [gdrive](https://drive.google.com/file/d/1o3fwZ0cH71bqHSA3bYNjhP4GGv9Vyuwa/view?usp=sharing) |
76
+ | DeAOTL | PRE_YTB_DAV | **24.7** | | **84.7** | **83.8** | **88.8** | **79.0** | **87.2** | - |
77
+ | R50-AOTL | PRE_YTB_DAV | 14.9 | | 84.4 | 83.4 | 88.1 | 78.7 | 87.2 | [gdrive](https://drive.google.com/file/d/1I7ooSp8EYfU6fvkP6QcCMaxeencA68AH/view?usp=sharing) |
78
+ | R50-AOTL | PRE_YTB_DAV | 6.4 | √ | 85.3 | 83.9 | 88.8 | 79.9 | 88.5 | [gdrive](https://drive.google.com/file/d/1OGqlkEu0uXa8QVWIVz_M5pmXXiYR2sh3/view?usp=sharing) |
79
+ | R50-DeAOTL | PRE_YTB_DAV | **22.4** | | **85.9** | **84.6** | **89.4** | **80.8** | **88.9** | - |
80
+ | SwinB-AOTL | PRE_YTB_DAV | 9.3 | | 84.7 | 84.0 | 88.8 | 78.7 | 87.1 | [gdrive](https://drive.google.com/file/d/1fPzCxi5GM7N2sLKkhoTC2yoY_oTQCHp1/view?usp=sharing) |
81
+ | SwinB-AOTL | PRE_YTB_DAV | 5.2 | √ | 85.3 | 84.6 | 89.5 | 79.3 | 87.7 | [gdrive](https://drive.google.com/file/d/1e3D22s_rJ7Y2X2MHo7x5lcNtwmHFlwYB/view?usp=sharing) |
82
+ | SwinB-DeAOTL | PRE_YTB_DAV | **11.9** | | **86.1** | **85.3** | **90.2** | **80.4** | **88.6** | - |
83
+
84
+ ### DAVIS-2017 test
85
+
86
+ | Model | Stage | FPS | Mean | J Score | F Score | Predictions |
87
+ | ---------- |:-----------:|:----:|:--------:|:--------:|:--------:|:----:|
88
+ | AOTT | PRE_YTB_DAV | **51.4** | 73.7 | 70.0 | 77.3 | [gdrive](https://drive.google.com/file/d/14Pu-6Uz4rfmJ_WyL2yl57KTx_pSSUNAf/view?usp=sharing) |
89
+ | AOTS | PRE_YTB_DAV | 40.0 | 75.2 | 71.4 | 78.9 | [gdrive](https://drive.google.com/file/d/1zzAPZCRLgnBWuAXqejPPEYLqBxu67Rj1/view?usp=sharing) |
90
+ | AOTB | PRE_YTB_DAV | 29.6 | 77.4 | 73.7 | 81.1 | [gdrive](https://drive.google.com/file/d/1WpQ-_Jrs7Ssfw0oekrejM2OVWEx_tBN1/view?usp=sharing) |
91
+ | AOTL | PRE_YTB_DAV | 18.7 | 79.3 | 75.5 | 83.2 | [gdrive](https://drive.google.com/file/d/1rP1Zdgc0N1d8RR2EaXMz3F-o5zqcNVe8/view?usp=sharing) |
92
+ | R50-AOTL | PRE_YTB_DAV | 18.0 | 79.5 | 76.0 | 83.0 | [gdrive](https://drive.google.com/file/d/1iQ5iNlvlS-In586ZNc4LIZMSdNIWDvle/view?usp=sharing) |
93
+ | SwinB-AOTL | PRE_YTB_DAV | 12.1 | **82.1** | **78.2** | **85.9** | [gdrive](https://drive.google.com/file/d/1oVt4FPcZdfVHiOxjYYKef0q7Ovy4f5Q_/view?usp=sharing) |
94
+
95
+ ### DAVIS-2017 val
96
+
97
+ | Model | Stage | FPS | Mean | J Score | F Score | Predictions |
98
+ | ---------- |:-----------:|:----:|:--------:|:--------:|:---------:|:----:|
99
+ | AOTT | PRE_YTB_DAV | **51.4** | 79.2 | 76.5 | 81.9 | [gdrive](https://drive.google.com/file/d/10OUFhK2Sz-hOJrTDoTI0mA45KO1qodZt/view?usp=sharing) |
100
+ | AOTS | PRE_YTB_DAV | 40.0 | 82.1 | 79.3 | 84.8 | [gdrive](https://drive.google.com/file/d/1T-JTYyksWlq45jxcLjnRaBvvYUhWgHFH/view?usp=sharing) |
101
+ | AOTB | PRE_YTB_DAV | 29.6 | 83.3 | 80.6 | 85.9 | [gdrive](https://drive.google.com/file/d/1EVUnxQm9TLBTuwK82QyiSKk9R9V8NwRL/view?usp=sharing) |
102
+ | AOTL | PRE_YTB_DAV | 18.7 | 83.6 | 80.8 | 86.3 | [gdrive](https://drive.google.com/file/d/1CFauSni2BxAe_fcl8W_6bFByuwJRbDYm/view?usp=sharing) |
103
+ | R50-AOTL | PRE_YTB_DAV | 18.0 | 85.2 | 82.5 | 87.9 | [gdrive](https://drive.google.com/file/d/1vjloxnP8R4PZdsH2DDizfU2CrkdRHHyo/view?usp=sharing) |
104
+ | SwinB-AOTL | PRE_YTB_DAV | 12.1 | **85.9** | **82.9** | **88.9** | [gdrive](https://drive.google.com/file/d/1tYCbKOas0i7Et2iyUAyDwaXnaD9YWxLr/view?usp=sharing) |
105
+
106
+ ### DAVIS-2016 val
107
+
108
+ | Model | Stage | FPS | Mean | J Score | F Score | Predictions |
109
+ | ---------- |:-----------:|:----:|:--------:|:--------:|:--------:|:----:|
110
+ | AOTT | PRE_YTB_DAV | **51.4** | 87.5 | 86.5 | 88.4 | [gdrive](https://drive.google.com/file/d/1LeW8WQhnylZ3umT7E379KdII92uUsGA9/view?usp=sharing) |
111
+ | AOTS | PRE_YTB_DAV | 40.0 | 89.6 | 88.6 | 90.5 | [gdrive](https://drive.google.com/file/d/1vqGei5tLu1FPVrTi5bwRAsaGy3Upf7B1/view?usp=sharing) |
112
+ | AOTB | PRE_YTB_DAV | 29.6 | 90.9 | 89.6 | 92.1 | [gdrive](https://drive.google.com/file/d/1qAppo2uOVu0FbE9t1FBUpymC3yWgw1LM/view?usp=sharing) |
113
+ | AOTL | PRE_YTB_DAV | 18.7 | 91.1 | 89.5 | 92.7 | [gdrive](https://drive.google.com/file/d/1g6cjYhgBWjMaY3RGAm31qm3SPEF3QcKV/view?usp=sharing) |
114
+ | R50-AOTL | PRE_YTB_DAV | 18.0 | 91.7 | 90.4 | 93.0 | [gdrive](https://drive.google.com/file/d/1QzxojqWKsvRf53K2AgKsK523ZVuYU4O-/view?usp=sharing) |
115
+ | SwinB-AOTL | PRE_YTB_DAV | 12.1 | **92.2** | **90.6** | **93.8** | [gdrive](https://drive.google.com/file/d/1RIqUtAyVnopeogfT520d7a0yiULg1obp/view?usp=sharing) |
aot/README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AOT Series Frameworks in PyTorch
2
+
3
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/decoupling-features-in-hierarchical/semi-supervised-video-object-segmentation-on-15)](https://paperswithcode.com/sota/semi-supervised-video-object-segmentation-on-15?p=decoupling-features-in-hierarchical)
4
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/associating-objects-with-scalable/video-object-segmentation-on-youtube-vos)](https://paperswithcode.com/sota/video-object-segmentation-on-youtube-vos?p=associating-objects-with-scalable)
5
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/associating-objects-with-scalable/semi-supervised-video-object-segmentation-on-18)](https://paperswithcode.com/sota/semi-supervised-video-object-segmentation-on-18?p=associating-objects-with-scalable)
6
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/associating-objects-with-scalable/semi-supervised-video-object-segmentation-on-1)](https://paperswithcode.com/sota/semi-supervised-video-object-segmentation-on-1?p=associating-objects-with-scalable)
7
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/associating-objects-with-scalable/visual-object-tracking-on-davis-2017)](https://paperswithcode.com/sota/visual-object-tracking-on-davis-2017?p=associating-objects-with-scalable)
8
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/associating-objects-with-scalable/visual-object-tracking-on-davis-2016)](https://paperswithcode.com/sota/visual-object-tracking-on-davis-2016?p=associating-objects-with-scalable)
9
+
10
+ A modular reference PyTorch implementation of AOT series frameworks:
11
+ - **DeAOT**: Decoupling Features in Hierachical Propagation for Video Object Segmentation (NeurIPS 2022, Spotlight) [[OpenReview](https://openreview.net/forum?id=DgM7-7eMkq0)][[PDF](https://arxiv.org/pdf/2210.09782.pdf)]
12
+ <img src="source/overview_deaot.png" width="90%"/>
13
+
14
+ - **AOT**: Associating Objects with Transformers for Video Object Segmentation (NeurIPS 2021, Score 8/8/7/8) [[OpenReview](https://openreview.net/forum?id=hl3v8io3ZYt)][[PDF](https://arxiv.org/abs/2106.02638)]
15
+ <img src="source/overview.png" width="90%"/>
16
+
17
+ An extension of AOT, [AOST](https://arxiv.org/abs/2203.11442) (under review), is available now. AOST is a more robust and flexible framework, supporting run-time speed-accuracy trade-offs.
18
+
19
+ ## Examples
20
+ Benchmark examples:
21
+
22
+ <img src="source/some_results.png" width="81%"/>
23
+
24
+ General examples (Messi and Kobe):
25
+
26
+ <img src="source/messi.gif" width="45%"/> <img src="source/kobe.gif" width="45%"/>
27
+
28
+ ## Highlights
29
+ - **High performance:** up to **85.5%** ([R50-AOTL](MODEL_ZOO.md#youtube-vos-2018-val)) on YouTube-VOS 2018 and **82.1%** ([SwinB-AOTL]((MODEL_ZOO.md#youtube-vos-2018-val))) on DAVIS-2017 Test-dev under standard settings (without any test-time augmentation and post processing).
30
+ - **High efficiency:** up to **51fps** ([AOTT](MODEL_ZOO.md#davis-2017-test)) on DAVIS-2017 (480p) even with **10** objects and **41fps** on YouTube-VOS (1.3x480p). AOT can process multiple objects (less than a pre-defined number, 10 is the default) as efficiently as processing a single object. This project also supports inferring any number of objects together within a video by automatic separation and aggregation.
31
+ - **Multi-GPU training and inference**
32
+ - **Mixed precision training and inference**
33
+ - **Test-time augmentation:** multi-scale and flipping augmentations are supported.
34
+
35
+ ## Requirements
36
+ * Python3
37
+ * pytorch >= 1.7.0 and torchvision
38
+ * opencv-python
39
+ * Pillow
40
+ * Pytorch Correlation (Recommend to install from [source](https://github.com/ClementPinard/Pytorch-Correlation-extension) instead of using `pip`. **The project can also work without this module but will lose some efficiency of the short-term attention**.)
41
+
42
+ Optional:
43
+ * scikit-image (if you want to run our **Demo**, please install)
44
+
45
+ ## Model Zoo and Results
46
+ Pre-trained models, benckmark scores, and pre-computed results reproduced by this project can be found in [MODEL_ZOO.md](MODEL_ZOO.md).
47
+
48
+ ## Demo - Panoptic Propagation
49
+ We provide a simple demo to demonstrate AOT's effectiveness. The demo will propagate more than **40** objects, including semantic regions (like sky) and instances (like person), together within a single complex scenario and predict its video panoptic segmentation.
50
+
51
+ To run the demo, download the [checkpoint](https://drive.google.com/file/d/1qJDYn3Ibpquu4ffYoQmVjg1YCbr2JQep/view?usp=sharing) of R50-AOTL into [pretrain_models](pretrain_models), and then run:
52
+ ```bash
53
+ python tools/demo.py
54
+ ```
55
+ which will predict the given scenarios in the resolution of 1.3x480p. You can also run this demo with other AOTs ([MODEL_ZOO.md](MODEL_ZOO.md)) by setting `--model` (model type) and `--ckpt_path` (checkpoint path).
56
+
57
+ Two scenarios from [VSPW](https://www.vspwdataset.com/home) are supplied in [datasets/Demo](datasets/Demo):
58
+
59
+ - 1001_3iEIq5HBY1s: 44 objects. 1080P.
60
+ - 1007_YCTBBdbKSSg: 43 objects. 1080P.
61
+
62
+ Results:
63
+
64
+ <img src="source/1001_3iEIq5HBY1s.gif" width="45%"/> <img src="source/1007_YCTBBdbKSSg.gif" width="45%"/>
65
+
66
+
67
+ ## Getting Started
68
+ 0. Prepare a valid environment follow the [requirements](#requirements).
69
+
70
+ 1. Prepare datasets:
71
+
72
+ Please follow the below instruction to prepare datasets in each corresponding folder.
73
+ * **Static**
74
+
75
+ [datasets/Static](datasets/Static): pre-training dataset with static images. Guidance can be found in [AFB-URR](https://github.com/xmlyqing00/AFB-URR), which we referred to in the implementation of the pre-training.
76
+ * **YouTube-VOS**
77
+
78
+ A commonly-used large-scale VOS dataset.
79
+
80
+ [datasets/YTB/2019](datasets/YTB/2019): version 2019, download [link](https://drive.google.com/drive/folders/1BWzrCWyPEmBEKm0lOHe5KLuBuQxUSwqz?usp=sharing). `train` is required for training. `valid` (6fps) and `valid_all_frames` (30fps, optional) are used for evaluation.
81
+
82
+ [datasets/YTB/2018](datasets/YTB/2018): version 2018, download [link](https://drive.google.com/drive/folders/1bI5J1H3mxsIGo7Kp-pPZU8i6rnykOw7f?usp=sharing). Only `valid` (6fps) and `valid_all_frames` (30fps, optional) are required for this project and used for evaluation.
83
+
84
+ * **DAVIS**
85
+
86
+ A commonly-used small-scale VOS dataset.
87
+
88
+ [datasets/DAVIS](datasets/DAVIS): [TrainVal](https://data.vision.ee.ethz.ch/csergi/share/davis/DAVIS-2017-trainval-480p.zip) (480p) contains both the training and validation split. [Test-Dev](https://data.vision.ee.ethz.ch/csergi/share/davis/DAVIS-2017-test-dev-480p.zip) (480p) contains the Test-dev split. The [full-resolution version](https://davischallenge.org/davis2017/code.html) is also supported for training and evaluation but not required.
89
+
90
+
91
+ 2. Prepare ImageNet pre-trained encoders
92
+
93
+ Select and download below checkpoints into [pretrain_models](pretrain_models):
94
+
95
+ - [MobileNet-V2](https://download.pytorch.org/models/mobilenet_v2-b0353104.pth) (default encoder)
96
+ - [MobileNet-V3](https://download.pytorch.org/models/mobilenet_v3_large-8738ca79.pth)
97
+ - [ResNet-50](https://download.pytorch.org/models/resnet50-0676ba61.pth)
98
+ - [ResNet-101](https://download.pytorch.org/models/resnet101-63fe2227.pth)
99
+ - [ResNeSt-50](https://github.com/zhanghang1989/ResNeSt/releases/download/weights_step1/resnest50-528c19ca.pth)
100
+ - [ResNeSt-101](https://github.com/zhanghang1989/ResNeSt/releases/download/weights_step1/resnest101-22405ba7.pth)
101
+ - [Swin-Base](https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window7_224_22k.pth)
102
+
103
+ The current default training configs are not optimized for encoders larger than ResNet-50. If you want to use larger encoders, we recommend early stopping the main-training stage at 80,000 iterations (100,000 in default) to avoid over-fitting on the seen classes of YouTube-VOS.
104
+
105
+
106
+
107
+ 3. Training and Evaluation
108
+
109
+ The [example script](train_eval.sh) will train AOTT with 2 stages using 4 GPUs and auto-mixed precision (`--amp`). The first stage is a pre-training stage using `Static` dataset, and the second stage is a main-training stage, which uses both `YouTube-VOS 2019 train` and `DAVIS-2017 train` for training, resulting in a model that can generalize to different domains (YouTube-VOS and DAVIS) and different frame rates (6fps, 24fps, and 30fps).
110
+
111
+ Notably, you can use only the `YouTube-VOS 2019 train` split in the second stage by changing `pre_ytb_dav` to `pre_ytb`, which leads to better YouTube-VOS performance on unseen classes. Besides, if you don't want to do the first stage, you can start the training from stage `ytb`, but the performance will drop about 1~2% absolutely.
112
+
113
+ After the training is finished (about 0.6 days for each stage with 4 Tesla V100 GPUs), the [example script](train_eval.sh) will evaluate the model on YouTube-VOS and DAVIS, and the results will be packed into Zip files. For calculating scores, please use official YouTube-VOS servers ([2018 server](https://competitions.codalab.org/competitions/19544) and [2019 server](https://competitions.codalab.org/competitions/20127)), official [DAVIS toolkit](https://github.com/davisvideochallenge/davis-2017) (for Val), and official [DAVIS server](https://competitions.codalab.org/competitions/20516#learn_the_details) (for Test-dev).
114
+
115
+ ## Adding your own dataset
116
+ Coming
117
+
118
+ ## Troubleshooting
119
+ Waiting
120
+
121
+ ## TODO
122
+ - [ ] Code documentation
123
+ - [ ] Adding your own dataset
124
+ - [ ] Results with test-time augmentations in Model Zoo
125
+ - [ ] Support gradient accumulation
126
+ - [x] Demo tool
127
+
128
+ ## Citations
129
+ Please consider citing the related paper(s) in your publications if it helps your research.
130
+ ```
131
+ @inproceedings{yang2022deaot,
132
+ title={Decoupling Features in Hierarchical Propagation for Video Object Segmentation},
133
+ author={Yang, Zongxin and Yang, Yi},
134
+ booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
135
+ year={2022}
136
+ }
137
+ @article{yang2021aost,
138
+ title={Scalable Multi-object Identification for Video Object Segmentation},
139
+ author={Yang, Zongxin and Miao, Jiaxu and Wang, Xiaohan and Wei, Yunchao and Yang, Yi},
140
+ journal={arXiv preprint arXiv:2203.11442},
141
+ year={2022}
142
+ }
143
+ @inproceedings{yang2021aot,
144
+ title={Associating Objects with Transformers for Video Object Segmentation},
145
+ author={Yang, Zongxin and Wei, Yunchao and Yang, Yi},
146
+ booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
147
+ year={2021}
148
+ }
149
+ ```
150
+
151
+ ## License
152
+ This project is released under the BSD-3-Clause license. See [LICENSE](LICENSE) for additional details.
aot/__init__.py ADDED
File without changes
aot/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (157 Bytes). View file
 
aot/configs/default.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import importlib
3
+
4
+
5
+ class DefaultEngineConfig():
6
+ def __init__(self, exp_name='default', model='aott'):
7
+ model_cfg = importlib.import_module('configs.models.' +
8
+ model).ModelConfig()
9
+ self.__dict__.update(model_cfg.__dict__) # add model config
10
+
11
+ self.EXP_NAME = exp_name + '_' + self.MODEL_NAME
12
+
13
+ self.STAGE_NAME = 'YTB'
14
+
15
+ self.DATASETS = ['youtubevos']
16
+ self.DATA_WORKERS = 8
17
+ self.DATA_RANDOMCROP = (465,
18
+ 465) if self.MODEL_ALIGN_CORNERS else (464,
19
+ 464)
20
+ self.DATA_RANDOMFLIP = 0.5
21
+ self.DATA_MAX_CROP_STEPS = 10
22
+ self.DATA_SHORT_EDGE_LEN = 480
23
+ self.DATA_MIN_SCALE_FACTOR = 0.7
24
+ self.DATA_MAX_SCALE_FACTOR = 1.3
25
+ self.DATA_RANDOM_REVERSE_SEQ = True
26
+ self.DATA_SEQ_LEN = 5
27
+ self.DATA_DAVIS_REPEAT = 5
28
+ self.DATA_RANDOM_GAP_DAVIS = 12 # max frame interval between two sampled frames for DAVIS (24fps)
29
+ self.DATA_RANDOM_GAP_YTB = 3 # max frame interval between two sampled frames for YouTube-VOS (6fps)
30
+ self.DATA_DYNAMIC_MERGE_PROB = 0.3
31
+
32
+ self.PRETRAIN = True
33
+ self.PRETRAIN_FULL = False # if False, load encoder only
34
+ self.PRETRAIN_MODEL = './data_wd/pretrain_model/mobilenet_v2.pth'
35
+ # self.PRETRAIN_MODEL = './pretrain_models/mobilenet_v2-b0353104.pth'
36
+
37
+ self.TRAIN_TOTAL_STEPS = 100000
38
+ self.TRAIN_START_STEP = 0
39
+ self.TRAIN_WEIGHT_DECAY = 0.07
40
+ self.TRAIN_WEIGHT_DECAY_EXCLUSIVE = {
41
+ # 'encoder.': 0.01
42
+ }
43
+ self.TRAIN_WEIGHT_DECAY_EXEMPTION = [
44
+ 'absolute_pos_embed', 'relative_position_bias_table',
45
+ 'relative_emb_v', 'conv_out'
46
+ ]
47
+ self.TRAIN_LR = 2e-4
48
+ self.TRAIN_LR_MIN = 2e-5 if 'mobilenetv2' in self.MODEL_ENCODER else 1e-5
49
+ self.TRAIN_LR_POWER = 0.9
50
+ self.TRAIN_LR_ENCODER_RATIO = 0.1
51
+ self.TRAIN_LR_WARM_UP_RATIO = 0.05
52
+ self.TRAIN_LR_COSINE_DECAY = False
53
+ self.TRAIN_LR_RESTART = 1
54
+ self.TRAIN_LR_UPDATE_STEP = 1
55
+ self.TRAIN_AUX_LOSS_WEIGHT = 1.0
56
+ self.TRAIN_AUX_LOSS_RATIO = 1.0
57
+ self.TRAIN_OPT = 'adamw'
58
+ self.TRAIN_SGD_MOMENTUM = 0.9
59
+ self.TRAIN_GPUS = 4
60
+ self.TRAIN_BATCH_SIZE = 16
61
+ self.TRAIN_TBLOG = False
62
+ self.TRAIN_TBLOG_STEP = 50
63
+ self.TRAIN_LOG_STEP = 20
64
+ self.TRAIN_IMG_LOG = True
65
+ self.TRAIN_TOP_K_PERCENT_PIXELS = 0.15
66
+ self.TRAIN_SEQ_TRAINING_FREEZE_PARAMS = ['patch_wise_id_bank']
67
+ self.TRAIN_SEQ_TRAINING_START_RATIO = 0.5
68
+ self.TRAIN_HARD_MINING_RATIO = 0.5
69
+ self.TRAIN_EMA_RATIO = 0.1
70
+ self.TRAIN_CLIP_GRAD_NORM = 5.
71
+ self.TRAIN_SAVE_STEP = 5000
72
+ self.TRAIN_MAX_KEEP_CKPT = 8
73
+ self.TRAIN_RESUME = False
74
+ self.TRAIN_RESUME_CKPT = None
75
+ self.TRAIN_RESUME_STEP = 0
76
+ self.TRAIN_AUTO_RESUME = True
77
+ self.TRAIN_DATASET_FULL_RESOLUTION = False
78
+ self.TRAIN_ENABLE_PREV_FRAME = False
79
+ self.TRAIN_ENCODER_FREEZE_AT = 2
80
+ self.TRAIN_LSTT_EMB_DROPOUT = 0.
81
+ self.TRAIN_LSTT_ID_DROPOUT = 0.
82
+ self.TRAIN_LSTT_DROPPATH = 0.1
83
+ self.TRAIN_LSTT_DROPPATH_SCALING = False
84
+ self.TRAIN_LSTT_DROPPATH_LST = False
85
+ self.TRAIN_LSTT_LT_DROPOUT = 0.
86
+ self.TRAIN_LSTT_ST_DROPOUT = 0.
87
+
88
+ self.TEST_GPU_ID = 0
89
+ self.TEST_GPU_NUM = 1
90
+ self.TEST_FRAME_LOG = False
91
+ self.TEST_DATASET = 'youtubevos'
92
+ self.TEST_DATASET_FULL_RESOLUTION = False
93
+ self.TEST_DATASET_SPLIT = 'val'
94
+ self.TEST_CKPT_PATH = None
95
+ # if "None", evaluate the latest checkpoint.
96
+ self.TEST_CKPT_STEP = None
97
+ self.TEST_FLIP = False
98
+ self.TEST_MULTISCALE = [1]
99
+ self.TEST_MAX_SHORT_EDGE = None
100
+ self.TEST_MAX_LONG_EDGE = 800 * 1.3
101
+ self.TEST_WORKERS = 4
102
+
103
+ # GPU distribution
104
+ self.DIST_ENABLE = True
105
+ self.DIST_BACKEND = "nccl" # "gloo"
106
+ self.DIST_URL = "tcp://127.0.0.1:13241"
107
+ self.DIST_START_GPU = 0
108
+
109
+ def init_dir(self):
110
+ self.DIR_DATA = '../VOS02/datasets'#'./datasets'
111
+ self.DIR_DAVIS = os.path.join(self.DIR_DATA, 'DAVIS')
112
+ self.DIR_YTB = os.path.join(self.DIR_DATA, 'YTB')
113
+ self.DIR_STATIC = os.path.join(self.DIR_DATA, 'Static')
114
+
115
+ self.DIR_ROOT = './'#'./data_wd/youtube_vos_jobs'
116
+
117
+ self.DIR_RESULT = os.path.join(self.DIR_ROOT, 'result', self.EXP_NAME,
118
+ self.STAGE_NAME)
119
+ self.DIR_CKPT = os.path.join(self.DIR_RESULT, 'ckpt')
120
+ self.DIR_EMA_CKPT = os.path.join(self.DIR_RESULT, 'ema_ckpt')
121
+ self.DIR_LOG = os.path.join(self.DIR_RESULT, 'log')
122
+ self.DIR_TB_LOG = os.path.join(self.DIR_RESULT, 'log', 'tensorboard')
123
+ # self.DIR_IMG_LOG = os.path.join(self.DIR_RESULT, 'log', 'img')
124
+ # self.DIR_EVALUATION = os.path.join(self.DIR_RESULT, 'eval')
125
+ self.DIR_IMG_LOG = './img_logs'
126
+ self.DIR_EVALUATION = './results'
127
+
128
+ for path in [
129
+ self.DIR_RESULT, self.DIR_CKPT, self.DIR_EMA_CKPT,
130
+ self.DIR_LOG, self.DIR_EVALUATION, self.DIR_IMG_LOG,
131
+ self.DIR_TB_LOG
132
+ ]:
133
+ if not os.path.isdir(path):
134
+ try:
135
+ os.makedirs(path)
136
+ except Exception as inst:
137
+ print(inst)
138
+ print('Failed to make dir: {}.'.format(path))
aot/configs/models/aotb.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultModelConfig
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'AOTB'
8
+
9
+ self.MODEL_LSTT_NUM = 3
aot/configs/models/aotl.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultModelConfig
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'AOTL'
8
+
9
+ self.MODEL_LSTT_NUM = 3
10
+
11
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
12
+
13
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/aots.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultModelConfig
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'AOTS'
8
+
9
+ self.MODEL_LSTT_NUM = 2
aot/configs/models/aott.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultModelConfig
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'AOTT'
aot/configs/models/deaotb.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'DeAOTB'
8
+
9
+ self.MODEL_LSTT_NUM = 3
aot/configs/models/deaotl.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'DeAOTL'
8
+
9
+ self.MODEL_LSTT_NUM = 3
10
+
11
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
12
+
13
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/deaots.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'DeAOTS'
8
+
9
+ self.MODEL_LSTT_NUM = 2
aot/configs/models/deaott.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'DeAOTT'
aot/configs/models/default.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class DefaultModelConfig():
2
+ def __init__(self):
3
+ self.MODEL_NAME = 'AOTDefault'
4
+
5
+ self.MODEL_VOS = 'aot'
6
+ self.MODEL_ENGINE = 'aotengine'
7
+ self.MODEL_ALIGN_CORNERS = True
8
+ self.MODEL_ENCODER = 'mobilenetv2'
9
+ self.MODEL_ENCODER_PRETRAIN = './pretrain_models/mobilenet_v2-b0353104.pth'
10
+ self.MODEL_ENCODER_DIM = [24, 32, 96, 1280] # 4x, 8x, 16x, 16x
11
+ self.MODEL_ENCODER_EMBEDDING_DIM = 256
12
+ self.MODEL_DECODER_INTERMEDIATE_LSTT = True
13
+ self.MODEL_FREEZE_BN = True
14
+ self.MODEL_FREEZE_BACKBONE = False
15
+ self.MODEL_MAX_OBJ_NUM = 10
16
+ self.MODEL_SELF_HEADS = 8
17
+ self.MODEL_ATT_HEADS = 8
18
+ self.MODEL_LSTT_NUM = 1
19
+ self.MODEL_EPSILON = 1e-5
20
+ self.MODEL_USE_PREV_PROB = False
21
+
22
+ self.TRAIN_LONG_TERM_MEM_GAP = 9999
23
+ self.TRAIN_AUG_TYPE = 'v1'
24
+
25
+ self.TEST_LONG_TERM_MEM_GAP = 9999
26
+
27
+ self.TEST_SHORT_TERM_MEM_SKIP = 1
aot/configs/models/default_deaot.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultModelConfig as BaseConfig
2
+
3
+
4
+ class DefaultModelConfig(BaseConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'DeAOTDefault'
8
+
9
+ self.MODEL_VOS = 'deaot'
10
+ self.MODEL_ENGINE = 'deaotengine'
11
+
12
+ self.MODEL_DECODER_INTERMEDIATE_LSTT = False
13
+
14
+ self.MODEL_SELF_HEADS = 1
15
+ self.MODEL_ATT_HEADS = 1
16
+
17
+ self.TRAIN_AUG_TYPE = 'v2'
aot/configs/models/r101_aotl.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'R101_AOTL'
8
+
9
+ self.MODEL_ENCODER = 'resnet101'
10
+ self.MODEL_ENCODER_PRETRAIN = './pretrain_models/resnet101-63fe2227.pth' # https://download.pytorch.org/models/resnet101-63fe2227.pth
11
+ self.MODEL_ENCODER_DIM = [256, 512, 1024, 1024] # 4x, 8x, 16x, 16x
12
+ self.MODEL_LSTT_NUM = 3
13
+
14
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
15
+
16
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/r50_aotl.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'R50_AOTL'
8
+
9
+ self.MODEL_ENCODER = 'resnet50'
10
+ self.MODEL_ENCODER_PRETRAIN = './pretrain_models/resnet50-0676ba61.pth' # https://download.pytorch.org/models/resnet50-0676ba61.pth
11
+ self.MODEL_ENCODER_DIM = [256, 512, 1024, 1024] # 4x, 8x, 16x, 16x
12
+ self.MODEL_LSTT_NUM = 3
13
+
14
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
15
+
16
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/r50_deaotl.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'R50_DeAOTL'
8
+
9
+ self.MODEL_ENCODER = 'resnet50'
10
+ self.MODEL_ENCODER_DIM = [256, 512, 1024, 1024] # 4x, 8x, 16x, 16x
11
+
12
+ self.MODEL_LSTT_NUM = 3
13
+
14
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
15
+
16
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/rs101_aotl.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'R101_AOTL'
8
+
9
+ self.MODEL_ENCODER = 'resnest101'
10
+ self.MODEL_ENCODER_PRETRAIN = './pretrain_models/resnest101-22405ba7.pth' # https://github.com/zhanghang1989/ResNeSt/releases/download/weights_step1/resnest101-22405ba7.pth
11
+ self.MODEL_ENCODER_DIM = [256, 512, 1024, 1024] # 4x, 8x, 16x, 16x
12
+ self.MODEL_LSTT_NUM = 3
13
+
14
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
15
+
16
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/swinb_aotl.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'SwinB_AOTL'
8
+
9
+ self.MODEL_ENCODER = 'swin_base'
10
+ self.MODEL_ENCODER_PRETRAIN = './pretrain_models/swin_base_patch4_window7_224_22k.pth' # https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window7_224_22k.pth
11
+ self.MODEL_ALIGN_CORNERS = False
12
+ self.MODEL_ENCODER_DIM = [128, 256, 512, 512] # 4x, 8x, 16x, 16x
13
+ self.MODEL_LSTT_NUM = 3
14
+
15
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
16
+
17
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/models/swinb_deaotl.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default_deaot import DefaultModelConfig
2
+
3
+
4
+ class ModelConfig(DefaultModelConfig):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.MODEL_NAME = 'SwinB_DeAOTL'
8
+
9
+ self.MODEL_ENCODER = 'swin_base'
10
+ self.MODEL_ALIGN_CORNERS = False
11
+ self.MODEL_ENCODER_DIM = [128, 256, 512, 512] # 4x, 8x, 16x, 16x
12
+
13
+ self.MODEL_LSTT_NUM = 3
14
+
15
+ self.TRAIN_LONG_TERM_MEM_GAP = 2
16
+
17
+ self.TEST_LONG_TERM_MEM_GAP = 5
aot/configs/pre.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .default import DefaultEngineConfig
2
+
3
+
4
+ class EngineConfig(DefaultEngineConfig):
5
+ def __init__(self, exp_name='default', model='AOTT'):
6
+ super().__init__(exp_name, model)
7
+ self.STAGE_NAME = 'PRE'
8
+
9
+ self.init_dir()
10
+
11
+ self.DATASETS = ['static']
12
+
13
+ self.DATA_DYNAMIC_MERGE_PROB = 1.0
14
+
15
+ self.TRAIN_LR = 4e-4
16
+ self.TRAIN_LR_MIN = 2e-5
17
+ self.TRAIN_WEIGHT_DECAY = 0.03
18
+ self.TRAIN_SEQ_TRAINING_START_RATIO = 1.0
19
+ self.TRAIN_AUX_LOSS_RATIO = 0.1
aot/configs/pre_dav.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultEngineConfig
3
+
4
+
5
+ class EngineConfig(DefaultEngineConfig):
6
+ def __init__(self, exp_name='default', model='AOTT'):
7
+ super().__init__(exp_name, model)
8
+ self.STAGE_NAME = 'PRE_DAV'
9
+
10
+ self.init_dir()
11
+
12
+ self.DATASETS = ['davis2017']
13
+
14
+ self.TRAIN_TOTAL_STEPS = 50000
15
+
16
+ pretrain_stage = 'PRE'
17
+ pretrain_ckpt = 'save_step_100000.pth'
18
+ self.PRETRAIN_FULL = True # if False, load encoder only
19
+ self.PRETRAIN_MODEL = os.path.join(self.DIR_ROOT, 'result',
20
+ self.EXP_NAME, pretrain_stage,
21
+ 'ema_ckpt', pretrain_ckpt)
aot/configs/pre_ytb.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultEngineConfig
3
+
4
+
5
+ class EngineConfig(DefaultEngineConfig):
6
+ def __init__(self, exp_name='default', model='AOTT'):
7
+ super().__init__(exp_name, model)
8
+ self.STAGE_NAME = 'PRE_YTB'
9
+
10
+ self.init_dir()
11
+
12
+ pretrain_stage = 'PRE'
13
+ pretrain_ckpt = 'save_step_100000.pth'
14
+ self.PRETRAIN_FULL = True # if False, load encoder only
15
+ self.PRETRAIN_MODEL = os.path.join(self.DIR_ROOT, 'result',
16
+ self.EXP_NAME, pretrain_stage,
17
+ 'ema_ckpt', pretrain_ckpt)
aot/configs/pre_ytb_dav.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultEngineConfig
3
+
4
+
5
+ class EngineConfig(DefaultEngineConfig):
6
+ def __init__(self, exp_name='default', model='AOTT'):
7
+ super().__init__(exp_name, model)
8
+ self.STAGE_NAME = 'PRE_YTB_DAV'
9
+
10
+ self.init_dir()
11
+
12
+ self.DATASETS = ['youtubevos', 'davis2017']
13
+
14
+ pretrain_stage = 'PRE'
15
+ pretrain_ckpt = 'save_step_100000.pth'
16
+ self.PRETRAIN_FULL = True # if False, load encoder only
17
+ self.PRETRAIN_MODEL = os.path.join(self.DIR_ROOT, 'result',
18
+ self.EXP_NAME, pretrain_stage,
19
+ 'ema_ckpt', pretrain_ckpt)
aot/configs/ytb.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from .default import DefaultEngineConfig
3
+
4
+
5
+ class EngineConfig(DefaultEngineConfig):
6
+ def __init__(self, exp_name='default', model='AOTT'):
7
+ super().__init__(exp_name, model)
8
+ self.STAGE_NAME = 'YTB'
9
+
10
+ self.init_dir()