Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +12 -35
- .gitignore +14 -0
- LICENSE.txt +661 -0
- README.md +212 -7
- SegTracker.py +264 -0
- __pycache__/SegTracker.cpython-310.pyc +0 -0
- __pycache__/aot_tracker.cpython-310.pyc +0 -0
- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/model_args.cpython-310.pyc +0 -0
- __pycache__/seg_track_anything.cpython-310.pyc +0 -0
- aot/LICENSE +29 -0
- aot/MODEL_ZOO.md +115 -0
- aot/README.md +152 -0
- aot/__init__.py +0 -0
- aot/__pycache__/__init__.cpython-310.pyc +0 -0
- aot/configs/default.py +138 -0
- aot/configs/models/aotb.py +9 -0
- aot/configs/models/aotl.py +13 -0
- aot/configs/models/aots.py +9 -0
- aot/configs/models/aott.py +7 -0
- aot/configs/models/deaotb.py +9 -0
- aot/configs/models/deaotl.py +13 -0
- aot/configs/models/deaots.py +9 -0
- aot/configs/models/deaott.py +7 -0
- aot/configs/models/default.py +27 -0
- aot/configs/models/default_deaot.py +17 -0
- aot/configs/models/r101_aotl.py +16 -0
- aot/configs/models/r50_aotl.py +16 -0
- aot/configs/models/r50_deaotl.py +16 -0
- aot/configs/models/rs101_aotl.py +16 -0
- aot/configs/models/swinb_aotl.py +17 -0
- aot/configs/models/swinb_deaotl.py +17 -0
- aot/configs/pre.py +19 -0
- aot/configs/pre_dav.py +21 -0
- aot/configs/pre_ytb.py +17 -0
- aot/configs/pre_ytb_dav.py +19 -0
- aot/configs/ytb.py +10 -0
- aot/dataloaders/__init__.py +0 -0
- aot/dataloaders/__pycache__/__init__.cpython-310.pyc +0 -0
- aot/dataloaders/__pycache__/image_transforms.cpython-310.pyc +0 -0
- aot/dataloaders/__pycache__/video_transforms.cpython-310.pyc +0 -0
- aot/dataloaders/eval_datasets.py +411 -0
- aot/dataloaders/image_transforms.py +530 -0
- aot/dataloaders/train_datasets.py +682 -0
- aot/dataloaders/video_transforms.py +715 -0
- aot/datasets/.DS_Store +0 -0
- aot/datasets/DAVIS/README.md +1 -0
- aot/datasets/Static/README.md +1 -0
- aot/datasets/YTB/2018/train/README.md +1 -0
- aot/datasets/YTB/2018/valid/README.md +1 -0
.gitattributes
CHANGED
@@ -1,35 +1,12 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
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 |
+
sam/assets/masks1.png filter=lfs diff=lfs merge=lfs -text
|
9 |
+
sam/assets/notebook2.png filter=lfs diff=lfs merge=lfs -text
|
10 |
+
tutorial/img/click_segment.jpg filter=lfs diff=lfs merge=lfs -text
|
11 |
+
tutorial/img/input_video.jpg filter=lfs diff=lfs merge=lfs -text
|
12 |
+
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/>.
|
README.md
CHANGED
@@ -1,12 +1,217 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.35.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: swallowing_diseases
|
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.68 kB). View file
|
|
__pycache__/app.cpython-310.pyc
ADDED
Binary file (11.5 kB). View file
|
|
__pycache__/model_args.cpython-310.pyc
ADDED
Binary file (740 Bytes). View file
|
|
__pycache__/seg_track_anything.cpython-310.pyc
ADDED
Binary file (6.47 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 (149 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()
|
aot/dataloaders/__init__.py
ADDED
File without changes
|
aot/dataloaders/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (161 Bytes). View file
|
|
aot/dataloaders/__pycache__/image_transforms.cpython-310.pyc
ADDED
Binary file (18.6 kB). View file
|
|
aot/dataloaders/__pycache__/video_transforms.cpython-310.pyc
ADDED
Binary file (15.6 kB). View file
|
|
aot/dataloaders/eval_datasets.py
ADDED
@@ -0,0 +1,411 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import division
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
import json
|
5 |
+
import cv2
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
from torch.utils.data import Dataset
|
10 |
+
|
11 |
+
from utils.image import _palette
|
12 |
+
|
13 |
+
|
14 |
+
class VOSTest(Dataset):
|
15 |
+
def __init__(self,
|
16 |
+
image_root,
|
17 |
+
label_root,
|
18 |
+
seq_name,
|
19 |
+
images,
|
20 |
+
labels,
|
21 |
+
rgb=True,
|
22 |
+
transform=None,
|
23 |
+
single_obj=False,
|
24 |
+
resolution=None):
|
25 |
+
self.image_root = image_root
|
26 |
+
self.label_root = label_root
|
27 |
+
self.seq_name = seq_name
|
28 |
+
self.images = images
|
29 |
+
self.labels = labels
|
30 |
+
self.obj_num = 1
|
31 |
+
self.num_frame = len(self.images)
|
32 |
+
self.transform = transform
|
33 |
+
self.rgb = rgb
|
34 |
+
self.single_obj = single_obj
|
35 |
+
self.resolution = resolution
|
36 |
+
|
37 |
+
self.obj_nums = []
|
38 |
+
self.obj_indices = []
|
39 |
+
|
40 |
+
curr_objs = [0]
|
41 |
+
for img_name in self.images:
|
42 |
+
self.obj_nums.append(len(curr_objs) - 1)
|
43 |
+
current_label_name = img_name.split('.')[0] + '.png'
|
44 |
+
if current_label_name in self.labels:
|
45 |
+
current_label = self.read_label(current_label_name)
|
46 |
+
curr_obj = list(np.unique(current_label))
|
47 |
+
for obj_idx in curr_obj:
|
48 |
+
if obj_idx not in curr_objs:
|
49 |
+
curr_objs.append(obj_idx)
|
50 |
+
self.obj_indices.append(curr_objs.copy())
|
51 |
+
|
52 |
+
self.obj_nums[0] = self.obj_nums[1]
|
53 |
+
|
54 |
+
def __len__(self):
|
55 |
+
return len(self.images)
|
56 |
+
|
57 |
+
def read_image(self, idx):
|
58 |
+
img_name = self.images[idx]
|
59 |
+
img_path = os.path.join(self.image_root, self.seq_name, img_name)
|
60 |
+
img = cv2.imread(img_path)
|
61 |
+
img = np.array(img, dtype=np.float32)
|
62 |
+
if self.rgb:
|
63 |
+
img = img[:, :, [2, 1, 0]]
|
64 |
+
return img
|
65 |
+
|
66 |
+
def read_label(self, label_name, squeeze_idx=None):
|
67 |
+
label_path = os.path.join(self.label_root, self.seq_name, label_name)
|
68 |
+
label = Image.open(label_path)
|
69 |
+
label = np.array(label, dtype=np.uint8)
|
70 |
+
if self.single_obj:
|
71 |
+
label = (label > 0).astype(np.uint8)
|
72 |
+
elif squeeze_idx is not None:
|
73 |
+
squeezed_label = label * 0
|
74 |
+
for idx in range(len(squeeze_idx)):
|
75 |
+
obj_id = squeeze_idx[idx]
|
76 |
+
if obj_id == 0:
|
77 |
+
continue
|
78 |
+
mask = label == obj_id
|
79 |
+
squeezed_label += (mask * idx).astype(np.uint8)
|
80 |
+
label = squeezed_label
|
81 |
+
return label
|
82 |
+
|
83 |
+
def __getitem__(self, idx):
|
84 |
+
img_name = self.images[idx]
|
85 |
+
current_img = self.read_image(idx)
|
86 |
+
height, width, channels = current_img.shape
|
87 |
+
if self.resolution is not None:
|
88 |
+
width = int(np.ceil(
|
89 |
+
float(width) * self.resolution / float(height)))
|
90 |
+
height = int(self.resolution)
|
91 |
+
|
92 |
+
current_label_name = img_name.split('.')[0] + '.png'
|
93 |
+
obj_num = self.obj_nums[idx]
|
94 |
+
obj_idx = self.obj_indices[idx]
|
95 |
+
|
96 |
+
if current_label_name in self.labels:
|
97 |
+
current_label = self.read_label(current_label_name, obj_idx)
|
98 |
+
sample = {
|
99 |
+
'current_img': current_img,
|
100 |
+
'current_label': current_label
|
101 |
+
}
|
102 |
+
else:
|
103 |
+
sample = {'current_img': current_img}
|
104 |
+
|
105 |
+
sample['meta'] = {
|
106 |
+
'seq_name': self.seq_name,
|
107 |
+
'frame_num': self.num_frame,
|
108 |
+
'obj_num': obj_num,
|
109 |
+
'current_name': img_name,
|
110 |
+
'height': height,
|
111 |
+
'width': width,
|
112 |
+
'flip': False,
|
113 |
+
'obj_idx': obj_idx
|
114 |
+
}
|
115 |
+
|
116 |
+
if self.transform is not None:
|
117 |
+
sample = self.transform(sample)
|
118 |
+
return sample
|
119 |
+
|
120 |
+
|
121 |
+
class YOUTUBEVOS_Test(object):
|
122 |
+
def __init__(self,
|
123 |
+
root='./datasets/YTB',
|
124 |
+
year=2018,
|
125 |
+
split='val',
|
126 |
+
transform=None,
|
127 |
+
rgb=True,
|
128 |
+
result_root=None):
|
129 |
+
if split == 'val':
|
130 |
+
split = 'valid'
|
131 |
+
root = os.path.join(root, str(year), split)
|
132 |
+
self.db_root_dir = root
|
133 |
+
self.result_root = result_root
|
134 |
+
self.rgb = rgb
|
135 |
+
self.transform = transform
|
136 |
+
self.seq_list_file = os.path.join(self.db_root_dir, 'meta.json')
|
137 |
+
self._check_preprocess()
|
138 |
+
self.seqs = list(self.ann_f.keys())
|
139 |
+
self.image_root = os.path.join(root, 'JPEGImages')
|
140 |
+
self.label_root = os.path.join(root, 'Annotations')
|
141 |
+
|
142 |
+
def __len__(self):
|
143 |
+
return len(self.seqs)
|
144 |
+
|
145 |
+
def __getitem__(self, idx):
|
146 |
+
seq_name = self.seqs[idx]
|
147 |
+
data = self.ann_f[seq_name]['objects']
|
148 |
+
obj_names = list(data.keys())
|
149 |
+
images = []
|
150 |
+
labels = []
|
151 |
+
for obj_n in obj_names:
|
152 |
+
images += map(lambda x: x + '.jpg', list(data[obj_n]["frames"]))
|
153 |
+
labels.append(data[obj_n]["frames"][0] + '.png')
|
154 |
+
images = np.sort(np.unique(images))
|
155 |
+
labels = np.sort(np.unique(labels))
|
156 |
+
|
157 |
+
try:
|
158 |
+
if not os.path.isfile(
|
159 |
+
os.path.join(self.result_root, seq_name, labels[0])):
|
160 |
+
if not os.path.exists(os.path.join(self.result_root,
|
161 |
+
seq_name)):
|
162 |
+
os.makedirs(os.path.join(self.result_root, seq_name))
|
163 |
+
shutil.copy(
|
164 |
+
os.path.join(self.label_root, seq_name, labels[0]),
|
165 |
+
os.path.join(self.result_root, seq_name, labels[0]))
|
166 |
+
except Exception as inst:
|
167 |
+
print(inst)
|
168 |
+
print('Failed to create a result folder for sequence {}.'.format(
|
169 |
+
seq_name))
|
170 |
+
|
171 |
+
seq_dataset = VOSTest(self.image_root,
|
172 |
+
self.label_root,
|
173 |
+
seq_name,
|
174 |
+
images,
|
175 |
+
labels,
|
176 |
+
transform=self.transform,
|
177 |
+
rgb=self.rgb)
|
178 |
+
return seq_dataset
|
179 |
+
|
180 |
+
def _check_preprocess(self):
|
181 |
+
_seq_list_file = self.seq_list_file
|
182 |
+
if not os.path.isfile(_seq_list_file):
|
183 |
+
print(_seq_list_file)
|
184 |
+
return False
|
185 |
+
else:
|
186 |
+
self.ann_f = json.load(open(self.seq_list_file, 'r'))['videos']
|
187 |
+
return True
|
188 |
+
|
189 |
+
|
190 |
+
class YOUTUBEVOS_DenseTest(object):
|
191 |
+
def __init__(self,
|
192 |
+
root='./datasets/YTB',
|
193 |
+
year=2018,
|
194 |
+
split='val',
|
195 |
+
transform=None,
|
196 |
+
rgb=True,
|
197 |
+
result_root=None):
|
198 |
+
if split == 'val':
|
199 |
+
split = 'valid'
|
200 |
+
root_sparse = os.path.join(root, str(year), split)
|
201 |
+
root_dense = root_sparse + '_all_frames'
|
202 |
+
self.db_root_dir = root_dense
|
203 |
+
self.result_root = result_root
|
204 |
+
self.rgb = rgb
|
205 |
+
self.transform = transform
|
206 |
+
self.seq_list_file = os.path.join(root_sparse, 'meta.json')
|
207 |
+
self._check_preprocess()
|
208 |
+
self.seqs = list(self.ann_f.keys())
|
209 |
+
self.image_root = os.path.join(root_dense, 'JPEGImages')
|
210 |
+
self.label_root = os.path.join(root_sparse, 'Annotations')
|
211 |
+
|
212 |
+
def __len__(self):
|
213 |
+
return len(self.seqs)
|
214 |
+
|
215 |
+
def __getitem__(self, idx):
|
216 |
+
seq_name = self.seqs[idx]
|
217 |
+
|
218 |
+
data = self.ann_f[seq_name]['objects']
|
219 |
+
obj_names = list(data.keys())
|
220 |
+
images_sparse = []
|
221 |
+
for obj_n in obj_names:
|
222 |
+
images_sparse += map(lambda x: x + '.jpg',
|
223 |
+
list(data[obj_n]["frames"]))
|
224 |
+
images_sparse = np.sort(np.unique(images_sparse))
|
225 |
+
|
226 |
+
images = np.sort(
|
227 |
+
list(os.listdir(os.path.join(self.image_root, seq_name))))
|
228 |
+
start_img = images_sparse[0]
|
229 |
+
end_img = images_sparse[-1]
|
230 |
+
for start_idx in range(len(images)):
|
231 |
+
if start_img in images[start_idx]:
|
232 |
+
break
|
233 |
+
for end_idx in range(len(images))[::-1]:
|
234 |
+
if end_img in images[end_idx]:
|
235 |
+
break
|
236 |
+
images = images[start_idx:(end_idx + 1)]
|
237 |
+
labels = np.sort(
|
238 |
+
list(os.listdir(os.path.join(self.label_root, seq_name))))
|
239 |
+
|
240 |
+
try:
|
241 |
+
if not os.path.isfile(
|
242 |
+
os.path.join(self.result_root, seq_name, labels[0])):
|
243 |
+
if not os.path.exists(os.path.join(self.result_root,
|
244 |
+
seq_name)):
|
245 |
+
os.makedirs(os.path.join(self.result_root, seq_name))
|
246 |
+
shutil.copy(
|
247 |
+
os.path.join(self.label_root, seq_name, labels[0]),
|
248 |
+
os.path.join(self.result_root, seq_name, labels[0]))
|
249 |
+
except Exception as inst:
|
250 |
+
print(inst)
|
251 |
+
print('Failed to create a result folder for sequence {}.'.format(
|
252 |
+
seq_name))
|
253 |
+
|
254 |
+
seq_dataset = VOSTest(self.image_root,
|
255 |
+
self.label_root,
|
256 |
+
seq_name,
|
257 |
+
images,
|
258 |
+
labels,
|
259 |
+
transform=self.transform,
|
260 |
+
rgb=self.rgb)
|
261 |
+
seq_dataset.images_sparse = images_sparse
|
262 |
+
|
263 |
+
return seq_dataset
|
264 |
+
|
265 |
+
def _check_preprocess(self):
|
266 |
+
_seq_list_file = self.seq_list_file
|
267 |
+
if not os.path.isfile(_seq_list_file):
|
268 |
+
print(_seq_list_file)
|
269 |
+
return False
|
270 |
+
else:
|
271 |
+
self.ann_f = json.load(open(self.seq_list_file, 'r'))['videos']
|
272 |
+
return True
|
273 |
+
|
274 |
+
|
275 |
+
class DAVIS_Test(object):
|
276 |
+
def __init__(self,
|
277 |
+
split=['val'],
|
278 |
+
root='./DAVIS',
|
279 |
+
year=2017,
|
280 |
+
transform=None,
|
281 |
+
rgb=True,
|
282 |
+
full_resolution=False,
|
283 |
+
result_root=None):
|
284 |
+
self.transform = transform
|
285 |
+
self.rgb = rgb
|
286 |
+
self.result_root = result_root
|
287 |
+
if year == 2016:
|
288 |
+
self.single_obj = True
|
289 |
+
else:
|
290 |
+
self.single_obj = False
|
291 |
+
if full_resolution:
|
292 |
+
resolution = 'Full-Resolution'
|
293 |
+
else:
|
294 |
+
resolution = '480p'
|
295 |
+
self.image_root = os.path.join(root, 'JPEGImages', resolution)
|
296 |
+
self.label_root = os.path.join(root, 'Annotations', resolution)
|
297 |
+
seq_names = []
|
298 |
+
for spt in split:
|
299 |
+
if spt == 'test':
|
300 |
+
spt = 'test-dev'
|
301 |
+
with open(os.path.join(root, 'ImageSets', str(year),
|
302 |
+
spt + '.txt')) as f:
|
303 |
+
seqs_tmp = f.readlines()
|
304 |
+
seqs_tmp = list(map(lambda elem: elem.strip(), seqs_tmp))
|
305 |
+
seq_names.extend(seqs_tmp)
|
306 |
+
self.seqs = list(np.unique(seq_names))
|
307 |
+
|
308 |
+
def __len__(self):
|
309 |
+
return len(self.seqs)
|
310 |
+
|
311 |
+
def __getitem__(self, idx):
|
312 |
+
seq_name = self.seqs[idx]
|
313 |
+
images = list(
|
314 |
+
np.sort(os.listdir(os.path.join(self.image_root, seq_name))))
|
315 |
+
labels = [images[0].replace('jpg', 'png')]
|
316 |
+
|
317 |
+
if not os.path.isfile(
|
318 |
+
os.path.join(self.result_root, seq_name, labels[0])):
|
319 |
+
seq_result_folder = os.path.join(self.result_root, seq_name)
|
320 |
+
try:
|
321 |
+
if not os.path.exists(seq_result_folder):
|
322 |
+
os.makedirs(seq_result_folder)
|
323 |
+
except Exception as inst:
|
324 |
+
print(inst)
|
325 |
+
print(
|
326 |
+
'Failed to create a result folder for sequence {}.'.format(
|
327 |
+
seq_name))
|
328 |
+
source_label_path = os.path.join(self.label_root, seq_name,
|
329 |
+
labels[0])
|
330 |
+
result_label_path = os.path.join(self.result_root, seq_name,
|
331 |
+
labels[0])
|
332 |
+
if self.single_obj:
|
333 |
+
label = Image.open(source_label_path)
|
334 |
+
label = np.array(label, dtype=np.uint8)
|
335 |
+
label = (label > 0).astype(np.uint8)
|
336 |
+
label = Image.fromarray(label).convert('P')
|
337 |
+
label.putpalette(_palette)
|
338 |
+
label.save(result_label_path)
|
339 |
+
else:
|
340 |
+
shutil.copy(source_label_path, result_label_path)
|
341 |
+
|
342 |
+
seq_dataset = VOSTest(self.image_root,
|
343 |
+
self.label_root,
|
344 |
+
seq_name,
|
345 |
+
images,
|
346 |
+
labels,
|
347 |
+
transform=self.transform,
|
348 |
+
rgb=self.rgb,
|
349 |
+
single_obj=self.single_obj,
|
350 |
+
resolution=480)
|
351 |
+
return seq_dataset
|
352 |
+
|
353 |
+
|
354 |
+
class _EVAL_TEST(Dataset):
|
355 |
+
def __init__(self, transform, seq_name):
|
356 |
+
self.seq_name = seq_name
|
357 |
+
self.num_frame = 10
|
358 |
+
self.transform = transform
|
359 |
+
|
360 |
+
def __len__(self):
|
361 |
+
return self.num_frame
|
362 |
+
|
363 |
+
def __getitem__(self, idx):
|
364 |
+
current_frame_obj_num = 2
|
365 |
+
height = 400
|
366 |
+
width = 400
|
367 |
+
img_name = 'test{}.jpg'.format(idx)
|
368 |
+
current_img = np.zeros((height, width, 3)).astype(np.float32)
|
369 |
+
if idx == 0:
|
370 |
+
current_label = (current_frame_obj_num * np.ones(
|
371 |
+
(height, width))).astype(np.uint8)
|
372 |
+
sample = {
|
373 |
+
'current_img': current_img,
|
374 |
+
'current_label': current_label
|
375 |
+
}
|
376 |
+
else:
|
377 |
+
sample = {'current_img': current_img}
|
378 |
+
|
379 |
+
sample['meta'] = {
|
380 |
+
'seq_name': self.seq_name,
|
381 |
+
'frame_num': self.num_frame,
|
382 |
+
'obj_num': current_frame_obj_num,
|
383 |
+
'current_name': img_name,
|
384 |
+
'height': height,
|
385 |
+
'width': width,
|
386 |
+
'flip': False
|
387 |
+
}
|
388 |
+
|
389 |
+
if self.transform is not None:
|
390 |
+
sample = self.transform(sample)
|
391 |
+
return sample
|
392 |
+
|
393 |
+
|
394 |
+
class EVAL_TEST(object):
|
395 |
+
def __init__(self, transform=None, result_root=None):
|
396 |
+
self.transform = transform
|
397 |
+
self.result_root = result_root
|
398 |
+
|
399 |
+
self.seqs = ['test1', 'test2', 'test3']
|
400 |
+
|
401 |
+
def __len__(self):
|
402 |
+
return len(self.seqs)
|
403 |
+
|
404 |
+
def __getitem__(self, idx):
|
405 |
+
seq_name = self.seqs[idx]
|
406 |
+
|
407 |
+
if not os.path.exists(os.path.join(self.result_root, seq_name)):
|
408 |
+
os.makedirs(os.path.join(self.result_root, seq_name))
|
409 |
+
|
410 |
+
seq_dataset = _EVAL_TEST(self.transform, seq_name)
|
411 |
+
return seq_dataset
|
aot/dataloaders/image_transforms.py
ADDED
@@ -0,0 +1,530 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import warnings
|
3 |
+
import random
|
4 |
+
import numbers
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image, ImageFilter
|
7 |
+
from collections.abc import Sequence
|
8 |
+
|
9 |
+
import torch
|
10 |
+
import torchvision.transforms.functional as TF
|
11 |
+
|
12 |
+
_pil_interpolation_to_str = {
|
13 |
+
Image.NEAREST: 'PIL.Image.NEAREST',
|
14 |
+
Image.BILINEAR: 'PIL.Image.BILINEAR',
|
15 |
+
Image.BICUBIC: 'PIL.Image.BICUBIC',
|
16 |
+
Image.LANCZOS: 'PIL.Image.LANCZOS',
|
17 |
+
Image.HAMMING: 'PIL.Image.HAMMING',
|
18 |
+
Image.BOX: 'PIL.Image.BOX',
|
19 |
+
}
|
20 |
+
|
21 |
+
|
22 |
+
def _get_image_size(img):
|
23 |
+
if TF._is_pil_image(img):
|
24 |
+
return img.size
|
25 |
+
elif isinstance(img, torch.Tensor) and img.dim() > 2:
|
26 |
+
return img.shape[-2:][::-1]
|
27 |
+
else:
|
28 |
+
raise TypeError("Unexpected type {}".format(type(img)))
|
29 |
+
|
30 |
+
|
31 |
+
class RandomHorizontalFlip(object):
|
32 |
+
"""Horizontal flip the given PIL Image randomly with a given probability.
|
33 |
+
|
34 |
+
Args:
|
35 |
+
p (float): probability of the image being flipped. Default value is 0.5
|
36 |
+
"""
|
37 |
+
def __init__(self, p=0.5):
|
38 |
+
self.p = p
|
39 |
+
|
40 |
+
def __call__(self, img, mask):
|
41 |
+
"""
|
42 |
+
Args:
|
43 |
+
img (PIL Image): Image to be flipped.
|
44 |
+
|
45 |
+
Returns:
|
46 |
+
PIL Image: Randomly flipped image.
|
47 |
+
"""
|
48 |
+
if random.random() < self.p:
|
49 |
+
img = TF.hflip(img)
|
50 |
+
mask = TF.hflip(mask)
|
51 |
+
return img, mask
|
52 |
+
|
53 |
+
def __repr__(self):
|
54 |
+
return self.__class__.__name__ + '(p={})'.format(self.p)
|
55 |
+
|
56 |
+
|
57 |
+
class RandomVerticalFlip(object):
|
58 |
+
"""Vertical flip the given PIL Image randomly with a given probability.
|
59 |
+
|
60 |
+
Args:
|
61 |
+
p (float): probability of the image being flipped. Default value is 0.5
|
62 |
+
"""
|
63 |
+
def __init__(self, p=0.5):
|
64 |
+
self.p = p
|
65 |
+
|
66 |
+
def __call__(self, img, mask):
|
67 |
+
"""
|
68 |
+
Args:
|
69 |
+
img (PIL Image): Image to be flipped.
|
70 |
+
|
71 |
+
Returns:
|
72 |
+
PIL Image: Randomly flipped image.
|
73 |
+
"""
|
74 |
+
if random.random() < self.p:
|
75 |
+
img = TF.vflip(img)
|
76 |
+
mask = TF.vflip(mask)
|
77 |
+
return img, mask
|
78 |
+
|
79 |
+
def __repr__(self):
|
80 |
+
return self.__class__.__name__ + '(p={})'.format(self.p)
|
81 |
+
|
82 |
+
|
83 |
+
class GaussianBlur(object):
|
84 |
+
"""Gaussian blur augmentation from SimCLR: https://arxiv.org/abs/2002.05709"""
|
85 |
+
def __init__(self, sigma=[.1, 2.]):
|
86 |
+
self.sigma = sigma
|
87 |
+
|
88 |
+
def __call__(self, x):
|
89 |
+
sigma = random.uniform(self.sigma[0], self.sigma[1])
|
90 |
+
x = x.filter(ImageFilter.GaussianBlur(radius=sigma))
|
91 |
+
return x
|
92 |
+
|
93 |
+
|
94 |
+
class RandomAffine(object):
|
95 |
+
"""Random affine transformation of the image keeping center invariant
|
96 |
+
|
97 |
+
Args:
|
98 |
+
degrees (sequence or float or int): Range of degrees to select from.
|
99 |
+
If degrees is a number instead of sequence like (min, max), the range of degrees
|
100 |
+
will be (-degrees, +degrees). Set to 0 to deactivate rotations.
|
101 |
+
translate (tuple, optional): tuple of maximum absolute fraction for horizontal
|
102 |
+
and vertical translations. For example translate=(a, b), then horizontal shift
|
103 |
+
is randomly sampled in the range -img_width * a < dx < img_width * a and vertical shift is
|
104 |
+
randomly sampled in the range -img_height * b < dy < img_height * b. Will not translate by default.
|
105 |
+
scale (tuple, optional): scaling factor interval, e.g (a, b), then scale is
|
106 |
+
randomly sampled from the range a <= scale <= b. Will keep original scale by default.
|
107 |
+
shear (sequence or float or int, optional): Range of degrees to select from.
|
108 |
+
If shear is a number, a shear parallel to the x axis in the range (-shear, +shear)
|
109 |
+
will be apllied. Else if shear is a tuple or list of 2 values a shear parallel to the x axis in the
|
110 |
+
range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values,
|
111 |
+
a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
|
112 |
+
Will not apply shear by default
|
113 |
+
resample ({PIL.Image.NEAREST, PIL.Image.BILINEAR, PIL.Image.BICUBIC}, optional):
|
114 |
+
An optional resampling filter. See `filters`_ for more information.
|
115 |
+
If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST.
|
116 |
+
fillcolor (tuple or int): Optional fill color (Tuple for RGB Image And int for grayscale) for the area
|
117 |
+
outside the transform in the output image.(Pillow>=5.0.0)
|
118 |
+
|
119 |
+
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
|
120 |
+
|
121 |
+
"""
|
122 |
+
def __init__(self,
|
123 |
+
degrees,
|
124 |
+
translate=None,
|
125 |
+
scale=None,
|
126 |
+
shear=None,
|
127 |
+
resample=False,
|
128 |
+
fillcolor=0):
|
129 |
+
if isinstance(degrees, numbers.Number):
|
130 |
+
if degrees < 0:
|
131 |
+
raise ValueError(
|
132 |
+
"If degrees is a single number, it must be positive.")
|
133 |
+
self.degrees = (-degrees, degrees)
|
134 |
+
else:
|
135 |
+
assert isinstance(degrees, (tuple, list)) and len(degrees) == 2, \
|
136 |
+
"degrees should be a list or tuple and it must be of length 2."
|
137 |
+
self.degrees = degrees
|
138 |
+
|
139 |
+
if translate is not None:
|
140 |
+
assert isinstance(translate, (tuple, list)) and len(translate) == 2, \
|
141 |
+
"translate should be a list or tuple and it must be of length 2."
|
142 |
+
for t in translate:
|
143 |
+
if not (0.0 <= t <= 1.0):
|
144 |
+
raise ValueError(
|
145 |
+
"translation values should be between 0 and 1")
|
146 |
+
self.translate = translate
|
147 |
+
|
148 |
+
if scale is not None:
|
149 |
+
assert isinstance(scale, (tuple, list)) and len(scale) == 2, \
|
150 |
+
"scale should be a list or tuple and it must be of length 2."
|
151 |
+
for s in scale:
|
152 |
+
if s <= 0:
|
153 |
+
raise ValueError("scale values should be positive")
|
154 |
+
self.scale = scale
|
155 |
+
|
156 |
+
if shear is not None:
|
157 |
+
if isinstance(shear, numbers.Number):
|
158 |
+
if shear < 0:
|
159 |
+
raise ValueError(
|
160 |
+
"If shear is a single number, it must be positive.")
|
161 |
+
self.shear = (-shear, shear)
|
162 |
+
else:
|
163 |
+
assert isinstance(shear, (tuple, list)) and \
|
164 |
+
(len(shear) == 2 or len(shear) == 4), \
|
165 |
+
"shear should be a list or tuple and it must be of length 2 or 4."
|
166 |
+
# X-Axis shear with [min, max]
|
167 |
+
if len(shear) == 2:
|
168 |
+
self.shear = [shear[0], shear[1], 0., 0.]
|
169 |
+
elif len(shear) == 4:
|
170 |
+
self.shear = [s for s in shear]
|
171 |
+
else:
|
172 |
+
self.shear = shear
|
173 |
+
|
174 |
+
self.resample = resample
|
175 |
+
self.fillcolor = fillcolor
|
176 |
+
|
177 |
+
@staticmethod
|
178 |
+
def get_params(degrees, translate, scale_ranges, shears, img_size):
|
179 |
+
"""Get parameters for affine transformation
|
180 |
+
|
181 |
+
Returns:
|
182 |
+
sequence: params to be passed to the affine transformation
|
183 |
+
"""
|
184 |
+
angle = random.uniform(degrees[0], degrees[1])
|
185 |
+
if translate is not None:
|
186 |
+
max_dx = translate[0] * img_size[0]
|
187 |
+
max_dy = translate[1] * img_size[1]
|
188 |
+
translations = (np.round(random.uniform(-max_dx, max_dx)),
|
189 |
+
np.round(random.uniform(-max_dy, max_dy)))
|
190 |
+
else:
|
191 |
+
translations = (0, 0)
|
192 |
+
|
193 |
+
if scale_ranges is not None:
|
194 |
+
scale = random.uniform(scale_ranges[0], scale_ranges[1])
|
195 |
+
else:
|
196 |
+
scale = 1.0
|
197 |
+
|
198 |
+
if shears is not None:
|
199 |
+
if len(shears) == 2:
|
200 |
+
shear = [random.uniform(shears[0], shears[1]), 0.]
|
201 |
+
elif len(shears) == 4:
|
202 |
+
shear = [
|
203 |
+
random.uniform(shears[0], shears[1]),
|
204 |
+
random.uniform(shears[2], shears[3])
|
205 |
+
]
|
206 |
+
else:
|
207 |
+
shear = 0.0
|
208 |
+
|
209 |
+
return angle, translations, scale, shear
|
210 |
+
|
211 |
+
def __call__(self, img, mask):
|
212 |
+
"""
|
213 |
+
img (PIL Image): Image to be transformed.
|
214 |
+
|
215 |
+
Returns:
|
216 |
+
PIL Image: Affine transformed image.
|
217 |
+
"""
|
218 |
+
ret = self.get_params(self.degrees, self.translate, self.scale,
|
219 |
+
self.shear, img.size)
|
220 |
+
img = TF.affine(img,
|
221 |
+
*ret,
|
222 |
+
resample=self.resample,
|
223 |
+
fillcolor=self.fillcolor)
|
224 |
+
mask = TF.affine(mask, *ret, resample=Image.NEAREST, fillcolor=0)
|
225 |
+
return img, mask
|
226 |
+
|
227 |
+
def __repr__(self):
|
228 |
+
s = '{name}(degrees={degrees}'
|
229 |
+
if self.translate is not None:
|
230 |
+
s += ', translate={translate}'
|
231 |
+
if self.scale is not None:
|
232 |
+
s += ', scale={scale}'
|
233 |
+
if self.shear is not None:
|
234 |
+
s += ', shear={shear}'
|
235 |
+
if self.resample > 0:
|
236 |
+
s += ', resample={resample}'
|
237 |
+
if self.fillcolor != 0:
|
238 |
+
s += ', fillcolor={fillcolor}'
|
239 |
+
s += ')'
|
240 |
+
d = dict(self.__dict__)
|
241 |
+
d['resample'] = _pil_interpolation_to_str[d['resample']]
|
242 |
+
return s.format(name=self.__class__.__name__, **d)
|
243 |
+
|
244 |
+
|
245 |
+
class RandomCrop(object):
|
246 |
+
"""Crop the given PIL Image at a random location.
|
247 |
+
|
248 |
+
Args:
|
249 |
+
size (sequence or int): Desired output size of the crop. If size is an
|
250 |
+
int instead of sequence like (h, w), a square crop (size, size) is
|
251 |
+
made.
|
252 |
+
padding (int or sequence, optional): Optional padding on each border
|
253 |
+
of the image. Default is None, i.e no padding. If a sequence of length
|
254 |
+
4 is provided, it is used to pad left, top, right, bottom borders
|
255 |
+
respectively. If a sequence of length 2 is provided, it is used to
|
256 |
+
pad left/right, top/bottom borders, respectively.
|
257 |
+
pad_if_needed (boolean): It will pad the image if smaller than the
|
258 |
+
desired size to avoid raising an exception. Since cropping is done
|
259 |
+
after padding, the padding seems to be done at a random offset.
|
260 |
+
fill: Pixel fill value for constant fill. Default is 0. If a tuple of
|
261 |
+
length 3, it is used to fill R, G, B channels respectively.
|
262 |
+
This value is only used when the padding_mode is constant
|
263 |
+
padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
|
264 |
+
|
265 |
+
- constant: pads with a constant value, this value is specified with fill
|
266 |
+
|
267 |
+
- edge: pads with the last value on the edge of the image
|
268 |
+
|
269 |
+
- reflect: pads with reflection of image (without repeating the last value on the edge)
|
270 |
+
|
271 |
+
padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
|
272 |
+
will result in [3, 2, 1, 2, 3, 4, 3, 2]
|
273 |
+
|
274 |
+
- symmetric: pads with reflection of image (repeating the last value on the edge)
|
275 |
+
|
276 |
+
padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
|
277 |
+
will result in [2, 1, 1, 2, 3, 4, 4, 3]
|
278 |
+
|
279 |
+
"""
|
280 |
+
def __init__(self,
|
281 |
+
size,
|
282 |
+
padding=None,
|
283 |
+
pad_if_needed=False,
|
284 |
+
fill=0,
|
285 |
+
padding_mode='constant'):
|
286 |
+
if isinstance(size, numbers.Number):
|
287 |
+
self.size = (int(size), int(size))
|
288 |
+
else:
|
289 |
+
self.size = size
|
290 |
+
self.padding = padding
|
291 |
+
self.pad_if_needed = pad_if_needed
|
292 |
+
self.fill = fill
|
293 |
+
self.padding_mode = padding_mode
|
294 |
+
|
295 |
+
@staticmethod
|
296 |
+
def get_params(img, output_size):
|
297 |
+
"""Get parameters for ``crop`` for a random crop.
|
298 |
+
|
299 |
+
Args:
|
300 |
+
img (PIL Image): Image to be cropped.
|
301 |
+
output_size (tuple): Expected output size of the crop.
|
302 |
+
|
303 |
+
Returns:
|
304 |
+
tuple: params (i, j, h, w) to be passed to ``crop`` for random crop.
|
305 |
+
"""
|
306 |
+
w, h = _get_image_size(img)
|
307 |
+
th, tw = output_size
|
308 |
+
if w == tw and h == th:
|
309 |
+
return 0, 0, h, w
|
310 |
+
|
311 |
+
i = random.randint(0, h - th)
|
312 |
+
j = random.randint(0, w - tw)
|
313 |
+
return i, j, th, tw
|
314 |
+
|
315 |
+
def __call__(self, img, mask):
|
316 |
+
"""
|
317 |
+
Args:
|
318 |
+
img (PIL Image): Image to be cropped.
|
319 |
+
|
320 |
+
Returns:
|
321 |
+
PIL Image: Cropped image.
|
322 |
+
"""
|
323 |
+
# if self.padding is not None:
|
324 |
+
# img = TF.pad(img, self.padding, self.fill, self.padding_mode)
|
325 |
+
#
|
326 |
+
# # pad the width if needed
|
327 |
+
# if self.pad_if_needed and img.size[0] < self.size[1]:
|
328 |
+
# img = TF.pad(img, (self.size[1] - img.size[0], 0), self.fill, self.padding_mode)
|
329 |
+
# # pad the height if needed
|
330 |
+
# if self.pad_if_needed and img.size[1] < self.size[0]:
|
331 |
+
# img = TF.pad(img, (0, self.size[0] - img.size[1]), self.fill, self.padding_mode)
|
332 |
+
|
333 |
+
i, j, h, w = self.get_params(img, self.size)
|
334 |
+
img = TF.crop(img, i, j, h, w)
|
335 |
+
mask = TF.crop(mask, i, j, h, w)
|
336 |
+
|
337 |
+
return img, mask
|
338 |
+
|
339 |
+
def __repr__(self):
|
340 |
+
return self.__class__.__name__ + '(size={0}, padding={1})'.format(
|
341 |
+
self.size, self.padding)
|
342 |
+
|
343 |
+
|
344 |
+
class RandomResizedCrop(object):
|
345 |
+
"""Crop the given PIL Image to random size and aspect ratio.
|
346 |
+
|
347 |
+
A crop of random size (default: of 0.08 to 1.0) of the original size and a random
|
348 |
+
aspect ratio (default: of 3/4 to 4/3) of the original aspect ratio is made. This crop
|
349 |
+
is finally resized to given size.
|
350 |
+
This is popularly used to train the Inception networks.
|
351 |
+
|
352 |
+
Args:
|
353 |
+
size: expected output size of each edge
|
354 |
+
scale: range of size of the origin size cropped
|
355 |
+
ratio: range of aspect ratio of the origin aspect ratio cropped
|
356 |
+
interpolation: Default: PIL.Image.BILINEAR
|
357 |
+
"""
|
358 |
+
def __init__(self,
|
359 |
+
size,
|
360 |
+
scale=(0.08, 1.0),
|
361 |
+
ratio=(3. / 4., 4. / 3.),
|
362 |
+
interpolation=Image.BILINEAR):
|
363 |
+
if isinstance(size, (tuple, list)):
|
364 |
+
self.size = size
|
365 |
+
else:
|
366 |
+
self.size = (size, size)
|
367 |
+
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
|
368 |
+
warnings.warn("range should be of kind (min, max)")
|
369 |
+
|
370 |
+
self.interpolation = interpolation
|
371 |
+
self.scale = scale
|
372 |
+
self.ratio = ratio
|
373 |
+
|
374 |
+
@staticmethod
|
375 |
+
def get_params(img, scale, ratio):
|
376 |
+
"""Get parameters for ``crop`` for a random sized crop.
|
377 |
+
|
378 |
+
Args:
|
379 |
+
img (PIL Image): Image to be cropped.
|
380 |
+
scale (tuple): range of size of the origin size cropped
|
381 |
+
ratio (tuple): range of aspect ratio of the origin aspect ratio cropped
|
382 |
+
|
383 |
+
Returns:
|
384 |
+
tuple: params (i, j, h, w) to be passed to ``crop`` for a random
|
385 |
+
sized crop.
|
386 |
+
"""
|
387 |
+
width, height = _get_image_size(img)
|
388 |
+
area = height * width
|
389 |
+
|
390 |
+
for _ in range(10):
|
391 |
+
target_area = random.uniform(*scale) * area
|
392 |
+
log_ratio = (math.log(ratio[0]), math.log(ratio[1]))
|
393 |
+
aspect_ratio = math.exp(random.uniform(*log_ratio))
|
394 |
+
|
395 |
+
w = int(round(math.sqrt(target_area * aspect_ratio)))
|
396 |
+
h = int(round(math.sqrt(target_area / aspect_ratio)))
|
397 |
+
|
398 |
+
if 0 < w <= width and 0 < h <= height:
|
399 |
+
i = random.randint(0, height - h)
|
400 |
+
j = random.randint(0, width - w)
|
401 |
+
return i, j, h, w
|
402 |
+
|
403 |
+
# Fallback to central crop
|
404 |
+
in_ratio = float(width) / float(height)
|
405 |
+
if (in_ratio < min(ratio)):
|
406 |
+
w = width
|
407 |
+
h = int(round(w / min(ratio)))
|
408 |
+
elif (in_ratio > max(ratio)):
|
409 |
+
h = height
|
410 |
+
w = int(round(h * max(ratio)))
|
411 |
+
else: # whole image
|
412 |
+
w = width
|
413 |
+
h = height
|
414 |
+
i = (height - h) // 2
|
415 |
+
j = (width - w) // 2
|
416 |
+
return i, j, h, w
|
417 |
+
|
418 |
+
def __call__(self, img, mask):
|
419 |
+
"""
|
420 |
+
Args:
|
421 |
+
img (PIL Image): Image to be cropped and resized.
|
422 |
+
|
423 |
+
Returns:
|
424 |
+
PIL Image: Randomly cropped and resized image.
|
425 |
+
"""
|
426 |
+
i, j, h, w = self.get_params(img, self.scale, self.ratio)
|
427 |
+
# print(i, j, h, w)
|
428 |
+
img = TF.resized_crop(img, i, j, h, w, self.size, self.interpolation)
|
429 |
+
mask = TF.resized_crop(mask, i, j, h, w, self.size, Image.NEAREST)
|
430 |
+
return img, mask
|
431 |
+
|
432 |
+
def __repr__(self):
|
433 |
+
interpolate_str = _pil_interpolation_to_str[self.interpolation]
|
434 |
+
format_string = self.__class__.__name__ + '(size={0}'.format(self.size)
|
435 |
+
format_string += ', scale={0}'.format(
|
436 |
+
tuple(round(s, 4) for s in self.scale))
|
437 |
+
format_string += ', ratio={0}'.format(
|
438 |
+
tuple(round(r, 4) for r in self.ratio))
|
439 |
+
format_string += ', interpolation={0})'.format(interpolate_str)
|
440 |
+
return format_string
|
441 |
+
|
442 |
+
|
443 |
+
class ToOnehot(object):
|
444 |
+
"""To oneshot tensor
|
445 |
+
|
446 |
+
Args:
|
447 |
+
max_obj_n (float): Maximum number of the objects
|
448 |
+
"""
|
449 |
+
def __init__(self, max_obj_n, shuffle):
|
450 |
+
self.max_obj_n = max_obj_n
|
451 |
+
self.shuffle = shuffle
|
452 |
+
|
453 |
+
def __call__(self, mask, obj_list=None):
|
454 |
+
"""
|
455 |
+
Args:
|
456 |
+
mask (Mask in Numpy): Mask to be converted.
|
457 |
+
|
458 |
+
Returns:
|
459 |
+
Tensor: Converted mask in onehot format.
|
460 |
+
"""
|
461 |
+
|
462 |
+
new_mask = np.zeros((self.max_obj_n + 1, *mask.shape), np.uint8)
|
463 |
+
|
464 |
+
if not obj_list:
|
465 |
+
obj_list = list()
|
466 |
+
obj_max = mask.max() + 1
|
467 |
+
for i in range(1, obj_max):
|
468 |
+
tmp = (mask == i).astype(np.uint8)
|
469 |
+
if tmp.max() > 0:
|
470 |
+
obj_list.append(i)
|
471 |
+
|
472 |
+
if self.shuffle:
|
473 |
+
random.shuffle(obj_list)
|
474 |
+
obj_list = obj_list[:self.max_obj_n]
|
475 |
+
|
476 |
+
for i in range(len(obj_list)):
|
477 |
+
new_mask[i + 1] = (mask == obj_list[i]).astype(np.uint8)
|
478 |
+
new_mask[0] = 1 - np.sum(new_mask, axis=0)
|
479 |
+
|
480 |
+
return torch.from_numpy(new_mask), obj_list
|
481 |
+
|
482 |
+
def __repr__(self):
|
483 |
+
return self.__class__.__name__ + '(max_obj_n={})'.format(
|
484 |
+
self.max_obj_n)
|
485 |
+
|
486 |
+
|
487 |
+
class Resize(torch.nn.Module):
|
488 |
+
"""Resize the input image to the given size.
|
489 |
+
The image can be a PIL Image or a torch Tensor, in which case it is expected
|
490 |
+
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
|
491 |
+
|
492 |
+
Args:
|
493 |
+
size (sequence or int): Desired output size. If size is a sequence like
|
494 |
+
(h, w), output size will be matched to this. If size is an int,
|
495 |
+
smaller edge of the image will be matched to this number.
|
496 |
+
i.e, if height > width, then image will be rescaled to
|
497 |
+
(size * height / width, size).
|
498 |
+
In torchscript mode padding as single int is not supported, use a tuple or
|
499 |
+
list of length 1: ``[size, ]``.
|
500 |
+
interpolation (int, optional): Desired interpolation enum defined by `filters`_.
|
501 |
+
Default is ``PIL.Image.BILINEAR``. If input is Tensor, only ``PIL.Image.NEAREST``, ``PIL.Image.BILINEAR``
|
502 |
+
and ``PIL.Image.BICUBIC`` are supported.
|
503 |
+
"""
|
504 |
+
def __init__(self, size, interpolation=Image.BILINEAR):
|
505 |
+
super().__init__()
|
506 |
+
if not isinstance(size, (int, Sequence)):
|
507 |
+
raise TypeError("Size should be int or sequence. Got {}".format(
|
508 |
+
type(size)))
|
509 |
+
if isinstance(size, Sequence) and len(size) not in (1, 2):
|
510 |
+
raise ValueError(
|
511 |
+
"If size is a sequence, it should have 1 or 2 values")
|
512 |
+
self.size = size
|
513 |
+
self.interpolation = interpolation
|
514 |
+
|
515 |
+
def forward(self, img, mask):
|
516 |
+
"""
|
517 |
+
Args:
|
518 |
+
img (PIL Image or Tensor): Image to be scaled.
|
519 |
+
|
520 |
+
Returns:
|
521 |
+
PIL Image or Tensor: Rescaled image.
|
522 |
+
"""
|
523 |
+
img = TF.resize(img, self.size, self.interpolation)
|
524 |
+
mask = TF.resize(mask, self.size, Image.NEAREST)
|
525 |
+
return img, mask
|
526 |
+
|
527 |
+
def __repr__(self):
|
528 |
+
interpolate_str = _pil_interpolation_to_str[self.interpolation]
|
529 |
+
return self.__class__.__name__ + '(size={0}, interpolation={1})'.format(
|
530 |
+
self.size, interpolate_str)
|
aot/dataloaders/train_datasets.py
ADDED
@@ -0,0 +1,682 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import division
|
2 |
+
import os
|
3 |
+
from glob import glob
|
4 |
+
import json
|
5 |
+
import random
|
6 |
+
import cv2
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
import numpy as np
|
10 |
+
import torch
|
11 |
+
from torch.utils.data import Dataset
|
12 |
+
import torchvision.transforms as TF
|
13 |
+
|
14 |
+
import dataloaders.image_transforms as IT
|
15 |
+
|
16 |
+
cv2.setNumThreads(0)
|
17 |
+
|
18 |
+
|
19 |
+
def _get_images(sample):
|
20 |
+
return [sample['ref_img'], sample['prev_img']] + sample['curr_img']
|
21 |
+
|
22 |
+
|
23 |
+
def _get_labels(sample):
|
24 |
+
return [sample['ref_label'], sample['prev_label']] + sample['curr_label']
|
25 |
+
|
26 |
+
|
27 |
+
def _merge_sample(sample1, sample2, min_obj_pixels=100, max_obj_n=10):
|
28 |
+
|
29 |
+
sample1_images = _get_images(sample1)
|
30 |
+
sample2_images = _get_images(sample2)
|
31 |
+
|
32 |
+
sample1_labels = _get_labels(sample1)
|
33 |
+
sample2_labels = _get_labels(sample2)
|
34 |
+
|
35 |
+
obj_idx = torch.arange(0, max_obj_n * 2 + 1).view(max_obj_n * 2 + 1, 1, 1)
|
36 |
+
selected_idx = None
|
37 |
+
selected_obj = None
|
38 |
+
|
39 |
+
all_img = []
|
40 |
+
all_mask = []
|
41 |
+
for idx, (s1_img, s2_img, s1_label, s2_label) in enumerate(
|
42 |
+
zip(sample1_images, sample2_images, sample1_labels,
|
43 |
+
sample2_labels)):
|
44 |
+
s2_fg = (s2_label > 0).float()
|
45 |
+
s2_bg = 1 - s2_fg
|
46 |
+
merged_img = s1_img * s2_bg + s2_img * s2_fg
|
47 |
+
merged_mask = s1_label * s2_bg.long() + (
|
48 |
+
(s2_label + max_obj_n) * s2_fg.long())
|
49 |
+
merged_mask = (merged_mask == obj_idx).float()
|
50 |
+
if idx == 0:
|
51 |
+
after_merge_pixels = merged_mask.sum(dim=(1, 2), keepdim=True)
|
52 |
+
selected_idx = after_merge_pixels > min_obj_pixels
|
53 |
+
selected_idx[0] = True
|
54 |
+
obj_num = selected_idx.sum().int().item() - 1
|
55 |
+
selected_idx = selected_idx.expand(-1,
|
56 |
+
s1_label.size()[1],
|
57 |
+
s1_label.size()[2])
|
58 |
+
if obj_num > max_obj_n:
|
59 |
+
selected_obj = list(range(1, obj_num + 1))
|
60 |
+
random.shuffle(selected_obj)
|
61 |
+
selected_obj = [0] + selected_obj[:max_obj_n]
|
62 |
+
|
63 |
+
merged_mask = merged_mask[selected_idx].view(obj_num + 1,
|
64 |
+
s1_label.size()[1],
|
65 |
+
s1_label.size()[2])
|
66 |
+
if obj_num > max_obj_n:
|
67 |
+
merged_mask = merged_mask[selected_obj]
|
68 |
+
merged_mask[0] += 0.1
|
69 |
+
merged_mask = torch.argmax(merged_mask, dim=0, keepdim=True).long()
|
70 |
+
|
71 |
+
all_img.append(merged_img)
|
72 |
+
all_mask.append(merged_mask)
|
73 |
+
|
74 |
+
sample = {
|
75 |
+
'ref_img': all_img[0],
|
76 |
+
'prev_img': all_img[1],
|
77 |
+
'curr_img': all_img[2:],
|
78 |
+
'ref_label': all_mask[0],
|
79 |
+
'prev_label': all_mask[1],
|
80 |
+
'curr_label': all_mask[2:]
|
81 |
+
}
|
82 |
+
sample['meta'] = sample1['meta']
|
83 |
+
sample['meta']['obj_num'] = min(obj_num, max_obj_n)
|
84 |
+
return sample
|
85 |
+
|
86 |
+
|
87 |
+
class StaticTrain(Dataset):
|
88 |
+
def __init__(self,
|
89 |
+
root,
|
90 |
+
output_size,
|
91 |
+
seq_len=5,
|
92 |
+
max_obj_n=10,
|
93 |
+
dynamic_merge=True,
|
94 |
+
merge_prob=1.0,
|
95 |
+
aug_type='v1'):
|
96 |
+
self.root = root
|
97 |
+
self.clip_n = seq_len
|
98 |
+
self.output_size = output_size
|
99 |
+
self.max_obj_n = max_obj_n
|
100 |
+
|
101 |
+
self.dynamic_merge = dynamic_merge
|
102 |
+
self.merge_prob = merge_prob
|
103 |
+
|
104 |
+
self.img_list = list()
|
105 |
+
self.mask_list = list()
|
106 |
+
|
107 |
+
dataset_list = list()
|
108 |
+
lines = ['COCO', 'ECSSD', 'MSRA10K', 'PASCAL-S', 'PASCALVOC2012']
|
109 |
+
for line in lines:
|
110 |
+
dataset_name = line.strip()
|
111 |
+
|
112 |
+
img_dir = os.path.join(root, 'JPEGImages', dataset_name)
|
113 |
+
mask_dir = os.path.join(root, 'Annotations', dataset_name)
|
114 |
+
|
115 |
+
img_list = sorted(glob(os.path.join(img_dir, '*.jpg'))) + \
|
116 |
+
sorted(glob(os.path.join(img_dir, '*.png')))
|
117 |
+
mask_list = sorted(glob(os.path.join(mask_dir, '*.png')))
|
118 |
+
|
119 |
+
if len(img_list) > 0:
|
120 |
+
if len(img_list) == len(mask_list):
|
121 |
+
dataset_list.append(dataset_name)
|
122 |
+
self.img_list += img_list
|
123 |
+
self.mask_list += mask_list
|
124 |
+
print(f'\t{dataset_name}: {len(img_list)} imgs.')
|
125 |
+
else:
|
126 |
+
print(
|
127 |
+
f'\tPreTrain dataset {dataset_name} has {len(img_list)} imgs and {len(mask_list)} annots. Not match! Skip.'
|
128 |
+
)
|
129 |
+
else:
|
130 |
+
print(
|
131 |
+
f'\tPreTrain dataset {dataset_name} doesn\'t exist. Skip.')
|
132 |
+
|
133 |
+
print(
|
134 |
+
f'{len(self.img_list)} imgs are used for PreTrain. They are from {dataset_list}.'
|
135 |
+
)
|
136 |
+
|
137 |
+
self.aug_type = aug_type
|
138 |
+
|
139 |
+
self.pre_random_horizontal_flip = IT.RandomHorizontalFlip(0.5)
|
140 |
+
|
141 |
+
self.random_horizontal_flip = IT.RandomHorizontalFlip(0.3)
|
142 |
+
|
143 |
+
if self.aug_type == 'v1':
|
144 |
+
self.color_jitter = TF.ColorJitter(0.1, 0.1, 0.1, 0.03)
|
145 |
+
elif self.aug_type == 'v2':
|
146 |
+
self.color_jitter = TF.RandomApply(
|
147 |
+
[TF.ColorJitter(0.4, 0.4, 0.2, 0.1)], p=0.8)
|
148 |
+
self.gray_scale = TF.RandomGrayscale(p=0.2)
|
149 |
+
self.blur = TF.RandomApply([IT.GaussianBlur([.1, 2.])], p=0.3)
|
150 |
+
else:
|
151 |
+
assert NotImplementedError
|
152 |
+
|
153 |
+
self.random_affine = IT.RandomAffine(degrees=20,
|
154 |
+
translate=(0.1, 0.1),
|
155 |
+
scale=(0.9, 1.1),
|
156 |
+
shear=10,
|
157 |
+
resample=Image.BICUBIC,
|
158 |
+
fillcolor=(124, 116, 104))
|
159 |
+
base_ratio = float(output_size[1]) / output_size[0]
|
160 |
+
self.random_resize_crop = IT.RandomResizedCrop(
|
161 |
+
output_size, (0.8, 1),
|
162 |
+
ratio=(base_ratio * 3. / 4., base_ratio * 4. / 3.),
|
163 |
+
interpolation=Image.BICUBIC)
|
164 |
+
self.to_tensor = TF.ToTensor()
|
165 |
+
self.to_onehot = IT.ToOnehot(max_obj_n, shuffle=True)
|
166 |
+
self.normalize = TF.Normalize((0.485, 0.456, 0.406),
|
167 |
+
(0.229, 0.224, 0.225))
|
168 |
+
|
169 |
+
def __len__(self):
|
170 |
+
return len(self.img_list)
|
171 |
+
|
172 |
+
def load_image_in_PIL(self, path, mode='RGB'):
|
173 |
+
img = Image.open(path)
|
174 |
+
img.load() # Very important for loading large image
|
175 |
+
return img.convert(mode)
|
176 |
+
|
177 |
+
def sample_sequence(self, idx):
|
178 |
+
img_pil = self.load_image_in_PIL(self.img_list[idx], 'RGB')
|
179 |
+
mask_pil = self.load_image_in_PIL(self.mask_list[idx], 'P')
|
180 |
+
|
181 |
+
frames = []
|
182 |
+
masks = []
|
183 |
+
|
184 |
+
img_pil, mask_pil = self.pre_random_horizontal_flip(img_pil, mask_pil)
|
185 |
+
# img_pil, mask_pil = self.pre_random_vertical_flip(img_pil, mask_pil)
|
186 |
+
|
187 |
+
for i in range(self.clip_n):
|
188 |
+
img, mask = img_pil, mask_pil
|
189 |
+
|
190 |
+
if i > 0:
|
191 |
+
img, mask = self.random_horizontal_flip(img, mask)
|
192 |
+
img, mask = self.random_affine(img, mask)
|
193 |
+
|
194 |
+
img = self.color_jitter(img)
|
195 |
+
|
196 |
+
img, mask = self.random_resize_crop(img, mask)
|
197 |
+
|
198 |
+
if self.aug_type == 'v2':
|
199 |
+
img = self.gray_scale(img)
|
200 |
+
img = self.blur(img)
|
201 |
+
|
202 |
+
mask = np.array(mask, np.uint8)
|
203 |
+
|
204 |
+
if i == 0:
|
205 |
+
mask, obj_list = self.to_onehot(mask)
|
206 |
+
obj_num = len(obj_list)
|
207 |
+
else:
|
208 |
+
mask, _ = self.to_onehot(mask, obj_list)
|
209 |
+
|
210 |
+
mask = torch.argmax(mask, dim=0, keepdim=True)
|
211 |
+
|
212 |
+
frames.append(self.normalize(self.to_tensor(img)))
|
213 |
+
masks.append(mask)
|
214 |
+
|
215 |
+
sample = {
|
216 |
+
'ref_img': frames[0],
|
217 |
+
'prev_img': frames[1],
|
218 |
+
'curr_img': frames[2:],
|
219 |
+
'ref_label': masks[0],
|
220 |
+
'prev_label': masks[1],
|
221 |
+
'curr_label': masks[2:]
|
222 |
+
}
|
223 |
+
sample['meta'] = {
|
224 |
+
'seq_name': self.img_list[idx],
|
225 |
+
'frame_num': 1,
|
226 |
+
'obj_num': obj_num
|
227 |
+
}
|
228 |
+
|
229 |
+
return sample
|
230 |
+
|
231 |
+
def __getitem__(self, idx):
|
232 |
+
sample1 = self.sample_sequence(idx)
|
233 |
+
|
234 |
+
if self.dynamic_merge and (sample1['meta']['obj_num'] == 0
|
235 |
+
or random.random() < self.merge_prob):
|
236 |
+
rand_idx = np.random.randint(len(self.img_list))
|
237 |
+
while (rand_idx == idx):
|
238 |
+
rand_idx = np.random.randint(len(self.img_list))
|
239 |
+
|
240 |
+
sample2 = self.sample_sequence(rand_idx)
|
241 |
+
|
242 |
+
sample = self.merge_sample(sample1, sample2)
|
243 |
+
else:
|
244 |
+
sample = sample1
|
245 |
+
|
246 |
+
return sample
|
247 |
+
|
248 |
+
def merge_sample(self, sample1, sample2, min_obj_pixels=100):
|
249 |
+
return _merge_sample(sample1, sample2, min_obj_pixels, self.max_obj_n)
|
250 |
+
|
251 |
+
|
252 |
+
class VOSTrain(Dataset):
|
253 |
+
def __init__(self,
|
254 |
+
image_root,
|
255 |
+
label_root,
|
256 |
+
imglistdic,
|
257 |
+
transform=None,
|
258 |
+
rgb=True,
|
259 |
+
repeat_time=1,
|
260 |
+
rand_gap=3,
|
261 |
+
seq_len=5,
|
262 |
+
rand_reverse=True,
|
263 |
+
dynamic_merge=True,
|
264 |
+
enable_prev_frame=False,
|
265 |
+
merge_prob=0.3,
|
266 |
+
max_obj_n=10):
|
267 |
+
self.image_root = image_root
|
268 |
+
self.label_root = label_root
|
269 |
+
self.rand_gap = rand_gap
|
270 |
+
self.seq_len = seq_len
|
271 |
+
self.rand_reverse = rand_reverse
|
272 |
+
self.repeat_time = repeat_time
|
273 |
+
self.transform = transform
|
274 |
+
self.dynamic_merge = dynamic_merge
|
275 |
+
self.merge_prob = merge_prob
|
276 |
+
self.enable_prev_frame = enable_prev_frame
|
277 |
+
self.max_obj_n = max_obj_n
|
278 |
+
self.rgb = rgb
|
279 |
+
self.imglistdic = imglistdic
|
280 |
+
self.seqs = list(self.imglistdic.keys())
|
281 |
+
print('Video Num: {} X {}'.format(len(self.seqs), self.repeat_time))
|
282 |
+
|
283 |
+
def __len__(self):
|
284 |
+
return int(len(self.seqs) * self.repeat_time)
|
285 |
+
|
286 |
+
def reverse_seq(self, imagelist, lablist):
|
287 |
+
if np.random.randint(2) == 1:
|
288 |
+
imagelist = imagelist[::-1]
|
289 |
+
lablist = lablist[::-1]
|
290 |
+
return imagelist, lablist
|
291 |
+
|
292 |
+
def get_ref_index(self,
|
293 |
+
seqname,
|
294 |
+
lablist,
|
295 |
+
objs,
|
296 |
+
min_fg_pixels=200,
|
297 |
+
max_try=5):
|
298 |
+
bad_indices = []
|
299 |
+
for _ in range(max_try):
|
300 |
+
ref_index = np.random.randint(len(lablist))
|
301 |
+
if ref_index in bad_indices:
|
302 |
+
continue
|
303 |
+
ref_label = Image.open(
|
304 |
+
os.path.join(self.label_root, seqname, lablist[ref_index]))
|
305 |
+
ref_label = np.array(ref_label, dtype=np.uint8)
|
306 |
+
ref_objs = list(np.unique(ref_label))
|
307 |
+
is_consistent = True
|
308 |
+
for obj in ref_objs:
|
309 |
+
if obj == 0:
|
310 |
+
continue
|
311 |
+
if obj not in objs:
|
312 |
+
is_consistent = False
|
313 |
+
xs, ys = np.nonzero(ref_label)
|
314 |
+
if len(xs) > min_fg_pixels and is_consistent:
|
315 |
+
break
|
316 |
+
bad_indices.append(ref_index)
|
317 |
+
return ref_index
|
318 |
+
|
319 |
+
def get_ref_index_v2(self,
|
320 |
+
seqname,
|
321 |
+
lablist,
|
322 |
+
min_fg_pixels=200,
|
323 |
+
max_try=20,
|
324 |
+
total_gap=0):
|
325 |
+
search_range = len(lablist) - total_gap
|
326 |
+
if search_range <= 1:
|
327 |
+
return 0
|
328 |
+
bad_indices = []
|
329 |
+
for _ in range(max_try):
|
330 |
+
ref_index = np.random.randint(search_range)
|
331 |
+
if ref_index in bad_indices:
|
332 |
+
continue
|
333 |
+
ref_label = Image.open(
|
334 |
+
os.path.join(self.label_root, seqname, lablist[ref_index]))
|
335 |
+
ref_label = np.array(ref_label, dtype=np.uint8)
|
336 |
+
xs, ys = np.nonzero(ref_label)
|
337 |
+
if len(xs) > min_fg_pixels:
|
338 |
+
break
|
339 |
+
bad_indices.append(ref_index)
|
340 |
+
return ref_index
|
341 |
+
|
342 |
+
def get_curr_gaps(self, seq_len, max_gap=999, max_try=10):
|
343 |
+
for _ in range(max_try):
|
344 |
+
curr_gaps = []
|
345 |
+
total_gap = 0
|
346 |
+
for _ in range(seq_len):
|
347 |
+
gap = int(np.random.randint(self.rand_gap) + 1)
|
348 |
+
total_gap += gap
|
349 |
+
curr_gaps.append(gap)
|
350 |
+
if total_gap <= max_gap:
|
351 |
+
break
|
352 |
+
return curr_gaps, total_gap
|
353 |
+
|
354 |
+
def get_prev_index(self, lablist, total_gap):
|
355 |
+
search_range = len(lablist) - total_gap
|
356 |
+
if search_range > 1:
|
357 |
+
prev_index = np.random.randint(search_range)
|
358 |
+
else:
|
359 |
+
prev_index = 0
|
360 |
+
return prev_index
|
361 |
+
|
362 |
+
def check_index(self, total_len, index, allow_reflect=True):
|
363 |
+
if total_len <= 1:
|
364 |
+
return 0
|
365 |
+
|
366 |
+
if index < 0:
|
367 |
+
if allow_reflect:
|
368 |
+
index = -index
|
369 |
+
index = self.check_index(total_len, index, True)
|
370 |
+
else:
|
371 |
+
index = 0
|
372 |
+
elif index >= total_len:
|
373 |
+
if allow_reflect:
|
374 |
+
index = 2 * (total_len - 1) - index
|
375 |
+
index = self.check_index(total_len, index, True)
|
376 |
+
else:
|
377 |
+
index = total_len - 1
|
378 |
+
|
379 |
+
return index
|
380 |
+
|
381 |
+
def get_curr_indices(self, lablist, prev_index, gaps):
|
382 |
+
total_len = len(lablist)
|
383 |
+
curr_indices = []
|
384 |
+
now_index = prev_index
|
385 |
+
for gap in gaps:
|
386 |
+
now_index += gap
|
387 |
+
curr_indices.append(self.check_index(total_len, now_index))
|
388 |
+
return curr_indices
|
389 |
+
|
390 |
+
def get_image_label(self, seqname, imagelist, lablist, index):
|
391 |
+
image = cv2.imread(
|
392 |
+
os.path.join(self.image_root, seqname, imagelist[index]))
|
393 |
+
image = np.array(image, dtype=np.float32)
|
394 |
+
|
395 |
+
if self.rgb:
|
396 |
+
image = image[:, :, [2, 1, 0]]
|
397 |
+
|
398 |
+
label = Image.open(
|
399 |
+
os.path.join(self.label_root, seqname, lablist[index]))
|
400 |
+
label = np.array(label, dtype=np.uint8)
|
401 |
+
|
402 |
+
return image, label
|
403 |
+
|
404 |
+
def sample_sequence(self, idx):
|
405 |
+
idx = idx % len(self.seqs)
|
406 |
+
seqname = self.seqs[idx]
|
407 |
+
imagelist, lablist = self.imglistdic[seqname]
|
408 |
+
frame_num = len(imagelist)
|
409 |
+
if self.rand_reverse:
|
410 |
+
imagelist, lablist = self.reverse_seq(imagelist, lablist)
|
411 |
+
|
412 |
+
is_consistent = False
|
413 |
+
max_try = 5
|
414 |
+
try_step = 0
|
415 |
+
while (is_consistent is False and try_step < max_try):
|
416 |
+
try_step += 1
|
417 |
+
|
418 |
+
# generate random gaps
|
419 |
+
curr_gaps, total_gap = self.get_curr_gaps(self.seq_len - 1)
|
420 |
+
|
421 |
+
if self.enable_prev_frame: # prev frame is randomly sampled
|
422 |
+
# get prev frame
|
423 |
+
prev_index = self.get_prev_index(lablist, total_gap)
|
424 |
+
prev_image, prev_label = self.get_image_label(
|
425 |
+
seqname, imagelist, lablist, prev_index)
|
426 |
+
prev_objs = list(np.unique(prev_label))
|
427 |
+
|
428 |
+
# get curr frames
|
429 |
+
curr_indices = self.get_curr_indices(lablist, prev_index,
|
430 |
+
curr_gaps)
|
431 |
+
curr_images, curr_labels, curr_objs = [], [], []
|
432 |
+
for curr_index in curr_indices:
|
433 |
+
curr_image, curr_label = self.get_image_label(
|
434 |
+
seqname, imagelist, lablist, curr_index)
|
435 |
+
c_objs = list(np.unique(curr_label))
|
436 |
+
curr_images.append(curr_image)
|
437 |
+
curr_labels.append(curr_label)
|
438 |
+
curr_objs.extend(c_objs)
|
439 |
+
|
440 |
+
objs = list(np.unique(prev_objs + curr_objs))
|
441 |
+
|
442 |
+
start_index = prev_index
|
443 |
+
end_index = max(curr_indices)
|
444 |
+
# get ref frame
|
445 |
+
_try_step = 0
|
446 |
+
ref_index = self.get_ref_index_v2(seqname, lablist)
|
447 |
+
while (ref_index > start_index and ref_index <= end_index
|
448 |
+
and _try_step < max_try):
|
449 |
+
_try_step += 1
|
450 |
+
ref_index = self.get_ref_index_v2(seqname, lablist)
|
451 |
+
ref_image, ref_label = self.get_image_label(
|
452 |
+
seqname, imagelist, lablist, ref_index)
|
453 |
+
ref_objs = list(np.unique(ref_label))
|
454 |
+
else: # prev frame is next to ref frame
|
455 |
+
# get ref frame
|
456 |
+
ref_index = self.get_ref_index_v2(seqname, lablist)
|
457 |
+
|
458 |
+
ref_image, ref_label = self.get_image_label(
|
459 |
+
seqname, imagelist, lablist, ref_index)
|
460 |
+
ref_objs = list(np.unique(ref_label))
|
461 |
+
|
462 |
+
# get curr frames
|
463 |
+
curr_indices = self.get_curr_indices(lablist, ref_index,
|
464 |
+
curr_gaps)
|
465 |
+
curr_images, curr_labels, curr_objs = [], [], []
|
466 |
+
for curr_index in curr_indices:
|
467 |
+
curr_image, curr_label = self.get_image_label(
|
468 |
+
seqname, imagelist, lablist, curr_index)
|
469 |
+
c_objs = list(np.unique(curr_label))
|
470 |
+
curr_images.append(curr_image)
|
471 |
+
curr_labels.append(curr_label)
|
472 |
+
curr_objs.extend(c_objs)
|
473 |
+
|
474 |
+
objs = list(np.unique(curr_objs))
|
475 |
+
prev_image, prev_label = curr_images[0], curr_labels[0]
|
476 |
+
curr_images, curr_labels = curr_images[1:], curr_labels[1:]
|
477 |
+
|
478 |
+
is_consistent = True
|
479 |
+
for obj in objs:
|
480 |
+
if obj == 0:
|
481 |
+
continue
|
482 |
+
if obj not in ref_objs:
|
483 |
+
is_consistent = False
|
484 |
+
break
|
485 |
+
|
486 |
+
# get meta info
|
487 |
+
obj_num = list(np.sort(ref_objs))[-1]
|
488 |
+
|
489 |
+
sample = {
|
490 |
+
'ref_img': ref_image,
|
491 |
+
'prev_img': prev_image,
|
492 |
+
'curr_img': curr_images,
|
493 |
+
'ref_label': ref_label,
|
494 |
+
'prev_label': prev_label,
|
495 |
+
'curr_label': curr_labels
|
496 |
+
}
|
497 |
+
sample['meta'] = {
|
498 |
+
'seq_name': seqname,
|
499 |
+
'frame_num': frame_num,
|
500 |
+
'obj_num': obj_num
|
501 |
+
}
|
502 |
+
|
503 |
+
if self.transform is not None:
|
504 |
+
sample = self.transform(sample)
|
505 |
+
|
506 |
+
return sample
|
507 |
+
|
508 |
+
def __getitem__(self, idx):
|
509 |
+
sample1 = self.sample_sequence(idx)
|
510 |
+
|
511 |
+
if self.dynamic_merge and (sample1['meta']['obj_num'] == 0
|
512 |
+
or random.random() < self.merge_prob):
|
513 |
+
rand_idx = np.random.randint(len(self.seqs))
|
514 |
+
while (rand_idx == (idx % len(self.seqs))):
|
515 |
+
rand_idx = np.random.randint(len(self.seqs))
|
516 |
+
|
517 |
+
sample2 = self.sample_sequence(rand_idx)
|
518 |
+
|
519 |
+
sample = self.merge_sample(sample1, sample2)
|
520 |
+
else:
|
521 |
+
sample = sample1
|
522 |
+
|
523 |
+
return sample
|
524 |
+
|
525 |
+
def merge_sample(self, sample1, sample2, min_obj_pixels=100):
|
526 |
+
return _merge_sample(sample1, sample2, min_obj_pixels, self.max_obj_n)
|
527 |
+
|
528 |
+
|
529 |
+
class DAVIS2017_Train(VOSTrain):
|
530 |
+
def __init__(self,
|
531 |
+
split=['train'],
|
532 |
+
root='./DAVIS',
|
533 |
+
transform=None,
|
534 |
+
rgb=True,
|
535 |
+
repeat_time=1,
|
536 |
+
full_resolution=True,
|
537 |
+
year=2017,
|
538 |
+
rand_gap=3,
|
539 |
+
seq_len=5,
|
540 |
+
rand_reverse=True,
|
541 |
+
dynamic_merge=True,
|
542 |
+
enable_prev_frame=False,
|
543 |
+
max_obj_n=10,
|
544 |
+
merge_prob=0.3):
|
545 |
+
if full_resolution:
|
546 |
+
resolution = 'Full-Resolution'
|
547 |
+
if not os.path.exists(os.path.join(root, 'JPEGImages',
|
548 |
+
resolution)):
|
549 |
+
print('No Full-Resolution, use 480p instead.')
|
550 |
+
resolution = '480p'
|
551 |
+
else:
|
552 |
+
resolution = '480p'
|
553 |
+
image_root = os.path.join(root, 'JPEGImages', resolution)
|
554 |
+
label_root = os.path.join(root, 'Annotations', resolution)
|
555 |
+
seq_names = []
|
556 |
+
for spt in split:
|
557 |
+
with open(os.path.join(root, 'ImageSets', str(year),
|
558 |
+
spt + '.txt')) as f:
|
559 |
+
seqs_tmp = f.readlines()
|
560 |
+
seqs_tmp = list(map(lambda elem: elem.strip(), seqs_tmp))
|
561 |
+
seq_names.extend(seqs_tmp)
|
562 |
+
imglistdic = {}
|
563 |
+
for seq_name in seq_names:
|
564 |
+
images = list(
|
565 |
+
np.sort(os.listdir(os.path.join(image_root, seq_name))))
|
566 |
+
labels = list(
|
567 |
+
np.sort(os.listdir(os.path.join(label_root, seq_name))))
|
568 |
+
imglistdic[seq_name] = (images, labels)
|
569 |
+
|
570 |
+
super(DAVIS2017_Train, self).__init__(image_root,
|
571 |
+
label_root,
|
572 |
+
imglistdic,
|
573 |
+
transform,
|
574 |
+
rgb,
|
575 |
+
repeat_time,
|
576 |
+
rand_gap,
|
577 |
+
seq_len,
|
578 |
+
rand_reverse,
|
579 |
+
dynamic_merge,
|
580 |
+
enable_prev_frame,
|
581 |
+
merge_prob=merge_prob,
|
582 |
+
max_obj_n=max_obj_n)
|
583 |
+
|
584 |
+
|
585 |
+
class YOUTUBEVOS_Train(VOSTrain):
|
586 |
+
def __init__(self,
|
587 |
+
root='./datasets/YTB',
|
588 |
+
year=2019,
|
589 |
+
transform=None,
|
590 |
+
rgb=True,
|
591 |
+
rand_gap=3,
|
592 |
+
seq_len=3,
|
593 |
+
rand_reverse=True,
|
594 |
+
dynamic_merge=True,
|
595 |
+
enable_prev_frame=False,
|
596 |
+
max_obj_n=10,
|
597 |
+
merge_prob=0.3):
|
598 |
+
root = os.path.join(root, str(year), 'train')
|
599 |
+
image_root = os.path.join(root, 'JPEGImages')
|
600 |
+
label_root = os.path.join(root, 'Annotations')
|
601 |
+
self.seq_list_file = os.path.join(root, 'meta.json')
|
602 |
+
self._check_preprocess()
|
603 |
+
seq_names = list(self.ann_f.keys())
|
604 |
+
|
605 |
+
imglistdic = {}
|
606 |
+
for seq_name in seq_names:
|
607 |
+
data = self.ann_f[seq_name]['objects']
|
608 |
+
obj_names = list(data.keys())
|
609 |
+
images = []
|
610 |
+
labels = []
|
611 |
+
for obj_n in obj_names:
|
612 |
+
if len(data[obj_n]["frames"]) < 2:
|
613 |
+
print("Short object: " + seq_name + '-' + obj_n)
|
614 |
+
continue
|
615 |
+
images += list(
|
616 |
+
map(lambda x: x + '.jpg', list(data[obj_n]["frames"])))
|
617 |
+
labels += list(
|
618 |
+
map(lambda x: x + '.png', list(data[obj_n]["frames"])))
|
619 |
+
images = np.sort(np.unique(images))
|
620 |
+
labels = np.sort(np.unique(labels))
|
621 |
+
if len(images) < 2:
|
622 |
+
print("Short video: " + seq_name)
|
623 |
+
continue
|
624 |
+
imglistdic[seq_name] = (images, labels)
|
625 |
+
|
626 |
+
super(YOUTUBEVOS_Train, self).__init__(image_root,
|
627 |
+
label_root,
|
628 |
+
imglistdic,
|
629 |
+
transform,
|
630 |
+
rgb,
|
631 |
+
1,
|
632 |
+
rand_gap,
|
633 |
+
seq_len,
|
634 |
+
rand_reverse,
|
635 |
+
dynamic_merge,
|
636 |
+
enable_prev_frame,
|
637 |
+
merge_prob=merge_prob,
|
638 |
+
max_obj_n=max_obj_n)
|
639 |
+
|
640 |
+
def _check_preprocess(self):
|
641 |
+
if not os.path.isfile(self.seq_list_file):
|
642 |
+
print('No such file: {}.'.format(self.seq_list_file))
|
643 |
+
return False
|
644 |
+
else:
|
645 |
+
self.ann_f = json.load(open(self.seq_list_file, 'r'))['videos']
|
646 |
+
return True
|
647 |
+
|
648 |
+
|
649 |
+
class TEST(Dataset):
|
650 |
+
def __init__(
|
651 |
+
self,
|
652 |
+
seq_len=3,
|
653 |
+
obj_num=3,
|
654 |
+
transform=None,
|
655 |
+
):
|
656 |
+
self.seq_len = seq_len
|
657 |
+
self.obj_num = obj_num
|
658 |
+
self.transform = transform
|
659 |
+
|
660 |
+
def __len__(self):
|
661 |
+
return 3000
|
662 |
+
|
663 |
+
def __getitem__(self, idx):
|
664 |
+
img = np.zeros((800, 800, 3)).astype(np.float32)
|
665 |
+
label = np.ones((800, 800)).astype(np.uint8)
|
666 |
+
sample = {
|
667 |
+
'ref_img': img,
|
668 |
+
'prev_img': img,
|
669 |
+
'curr_img': [img] * (self.seq_len - 2),
|
670 |
+
'ref_label': label,
|
671 |
+
'prev_label': label,
|
672 |
+
'curr_label': [label] * (self.seq_len - 2)
|
673 |
+
}
|
674 |
+
sample['meta'] = {
|
675 |
+
'seq_name': 'test',
|
676 |
+
'frame_num': 100,
|
677 |
+
'obj_num': self.obj_num
|
678 |
+
}
|
679 |
+
|
680 |
+
if self.transform is not None:
|
681 |
+
sample = self.transform(sample)
|
682 |
+
return sample
|
aot/dataloaders/video_transforms.py
ADDED
@@ -0,0 +1,715 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import torchvision.transforms as TF
|
8 |
+
import dataloaders.image_transforms as IT
|
9 |
+
|
10 |
+
cv2.setNumThreads(0)
|
11 |
+
|
12 |
+
|
13 |
+
class Resize(object):
|
14 |
+
"""Rescale the image in a sample to a given size.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
output_size (tuple or int): Desired output size. If tuple, output is
|
18 |
+
matched to output_size. If int, smaller of image edges is matched
|
19 |
+
to output_size keeping aspect ratio the same.
|
20 |
+
"""
|
21 |
+
def __init__(self, output_size, use_padding=False):
|
22 |
+
assert isinstance(output_size, (int, tuple))
|
23 |
+
if isinstance(output_size, int):
|
24 |
+
self.output_size = (output_size, output_size)
|
25 |
+
else:
|
26 |
+
self.output_size = output_size
|
27 |
+
self.use_padding = use_padding
|
28 |
+
|
29 |
+
def __call__(self, sample):
|
30 |
+
return self.padding(sample) if self.use_padding else self.rescale(
|
31 |
+
sample)
|
32 |
+
|
33 |
+
def rescale(self, sample):
|
34 |
+
prev_img = sample['prev_img']
|
35 |
+
h, w = prev_img.shape[:2]
|
36 |
+
if self.output_size == (h, w):
|
37 |
+
return sample
|
38 |
+
else:
|
39 |
+
new_h, new_w = self.output_size
|
40 |
+
|
41 |
+
for elem in sample.keys():
|
42 |
+
if 'meta' in elem:
|
43 |
+
continue
|
44 |
+
tmp = sample[elem]
|
45 |
+
|
46 |
+
if elem == 'prev_img' or elem == 'curr_img' or elem == 'ref_img':
|
47 |
+
flagval = cv2.INTER_CUBIC
|
48 |
+
else:
|
49 |
+
flagval = cv2.INTER_NEAREST
|
50 |
+
|
51 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
52 |
+
new_tmp = []
|
53 |
+
all_tmp = tmp
|
54 |
+
for tmp in all_tmp:
|
55 |
+
tmp = cv2.resize(tmp,
|
56 |
+
dsize=(new_w, new_h),
|
57 |
+
interpolation=flagval)
|
58 |
+
new_tmp.append(tmp)
|
59 |
+
tmp = new_tmp
|
60 |
+
else:
|
61 |
+
tmp = cv2.resize(tmp,
|
62 |
+
dsize=(new_w, new_h),
|
63 |
+
interpolation=flagval)
|
64 |
+
|
65 |
+
sample[elem] = tmp
|
66 |
+
|
67 |
+
return sample
|
68 |
+
|
69 |
+
def padding(self, sample):
|
70 |
+
prev_img = sample['prev_img']
|
71 |
+
h, w = prev_img.shape[:2]
|
72 |
+
if self.output_size == (h, w):
|
73 |
+
return sample
|
74 |
+
else:
|
75 |
+
new_h, new_w = self.output_size
|
76 |
+
|
77 |
+
def sep_pad(x):
|
78 |
+
x0 = np.random.randint(0, x + 1)
|
79 |
+
x1 = x - x0
|
80 |
+
return x0, x1
|
81 |
+
|
82 |
+
top_pad, bottom_pad = sep_pad(new_h - h)
|
83 |
+
left_pad, right_pad = sep_pad(new_w - w)
|
84 |
+
|
85 |
+
for elem in sample.keys():
|
86 |
+
if 'meta' in elem:
|
87 |
+
continue
|
88 |
+
tmp = sample[elem]
|
89 |
+
|
90 |
+
if elem == 'prev_img' or elem == 'curr_img' or elem == 'ref_img':
|
91 |
+
pad_value = (124, 116, 104)
|
92 |
+
else:
|
93 |
+
pad_value = (0)
|
94 |
+
|
95 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
96 |
+
new_tmp = []
|
97 |
+
all_tmp = tmp
|
98 |
+
for tmp in all_tmp:
|
99 |
+
tmp = cv2.copyMakeBorder(tmp,
|
100 |
+
top_pad,
|
101 |
+
bottom_pad,
|
102 |
+
left_pad,
|
103 |
+
right_pad,
|
104 |
+
cv2.BORDER_CONSTANT,
|
105 |
+
value=pad_value)
|
106 |
+
new_tmp.append(tmp)
|
107 |
+
tmp = new_tmp
|
108 |
+
else:
|
109 |
+
tmp = cv2.copyMakeBorder(tmp,
|
110 |
+
top_pad,
|
111 |
+
bottom_pad,
|
112 |
+
left_pad,
|
113 |
+
right_pad,
|
114 |
+
cv2.BORDER_CONSTANT,
|
115 |
+
value=pad_value)
|
116 |
+
|
117 |
+
sample[elem] = tmp
|
118 |
+
|
119 |
+
return sample
|
120 |
+
|
121 |
+
|
122 |
+
class BalancedRandomCrop(object):
|
123 |
+
"""Crop randomly the image in a sample.
|
124 |
+
|
125 |
+
Args:
|
126 |
+
output_size (tuple or int): Desired output size. If int, square crop
|
127 |
+
is made.
|
128 |
+
"""
|
129 |
+
def __init__(self,
|
130 |
+
output_size,
|
131 |
+
max_step=5,
|
132 |
+
max_obj_num=5,
|
133 |
+
min_obj_pixel_num=100):
|
134 |
+
assert isinstance(output_size, (int, tuple))
|
135 |
+
if isinstance(output_size, int):
|
136 |
+
self.output_size = (output_size, output_size)
|
137 |
+
else:
|
138 |
+
assert len(output_size) == 2
|
139 |
+
self.output_size = output_size
|
140 |
+
self.max_step = max_step
|
141 |
+
self.max_obj_num = max_obj_num
|
142 |
+
self.min_obj_pixel_num = min_obj_pixel_num
|
143 |
+
|
144 |
+
def __call__(self, sample):
|
145 |
+
|
146 |
+
image = sample['prev_img']
|
147 |
+
h, w = image.shape[:2]
|
148 |
+
new_h, new_w = self.output_size
|
149 |
+
new_h = h if new_h >= h else new_h
|
150 |
+
new_w = w if new_w >= w else new_w
|
151 |
+
ref_label = sample["ref_label"]
|
152 |
+
prev_label = sample["prev_label"]
|
153 |
+
curr_label = sample["curr_label"]
|
154 |
+
|
155 |
+
is_contain_obj = False
|
156 |
+
step = 0
|
157 |
+
while (not is_contain_obj) and (step < self.max_step):
|
158 |
+
step += 1
|
159 |
+
top = np.random.randint(0, h - new_h + 1)
|
160 |
+
left = np.random.randint(0, w - new_w + 1)
|
161 |
+
after_crop = []
|
162 |
+
contains = []
|
163 |
+
for elem in ([ref_label, prev_label] + curr_label):
|
164 |
+
tmp = elem[top:top + new_h, left:left + new_w]
|
165 |
+
contains.append(np.unique(tmp))
|
166 |
+
after_crop.append(tmp)
|
167 |
+
|
168 |
+
all_obj = list(np.sort(contains[0]))
|
169 |
+
|
170 |
+
if all_obj[-1] == 0:
|
171 |
+
continue
|
172 |
+
|
173 |
+
# remove background
|
174 |
+
if all_obj[0] == 0:
|
175 |
+
all_obj = all_obj[1:]
|
176 |
+
|
177 |
+
# remove small obj
|
178 |
+
new_all_obj = []
|
179 |
+
for obj_id in all_obj:
|
180 |
+
after_crop_pixels = np.sum(after_crop[0] == obj_id)
|
181 |
+
if after_crop_pixels > self.min_obj_pixel_num:
|
182 |
+
new_all_obj.append(obj_id)
|
183 |
+
|
184 |
+
if len(new_all_obj) == 0:
|
185 |
+
is_contain_obj = False
|
186 |
+
else:
|
187 |
+
is_contain_obj = True
|
188 |
+
|
189 |
+
if len(new_all_obj) > self.max_obj_num:
|
190 |
+
random.shuffle(new_all_obj)
|
191 |
+
new_all_obj = new_all_obj[:self.max_obj_num]
|
192 |
+
|
193 |
+
all_obj = [0] + new_all_obj
|
194 |
+
|
195 |
+
post_process = []
|
196 |
+
for elem in after_crop:
|
197 |
+
new_elem = elem * 0
|
198 |
+
for idx in range(len(all_obj)):
|
199 |
+
obj_id = all_obj[idx]
|
200 |
+
if obj_id == 0:
|
201 |
+
continue
|
202 |
+
mask = elem == obj_id
|
203 |
+
|
204 |
+
new_elem += (mask * idx).astype(np.uint8)
|
205 |
+
post_process.append(new_elem.astype(np.uint8))
|
206 |
+
|
207 |
+
sample["ref_label"] = post_process[0]
|
208 |
+
sample["prev_label"] = post_process[1]
|
209 |
+
curr_len = len(sample["curr_img"])
|
210 |
+
sample["curr_label"] = []
|
211 |
+
for idx in range(curr_len):
|
212 |
+
sample["curr_label"].append(post_process[idx + 2])
|
213 |
+
|
214 |
+
for elem in sample.keys():
|
215 |
+
if 'meta' in elem or 'label' in elem:
|
216 |
+
continue
|
217 |
+
if elem == 'curr_img':
|
218 |
+
new_tmp = []
|
219 |
+
for tmp_ in sample[elem]:
|
220 |
+
tmp_ = tmp_[top:top + new_h, left:left + new_w]
|
221 |
+
new_tmp.append(tmp_)
|
222 |
+
sample[elem] = new_tmp
|
223 |
+
else:
|
224 |
+
tmp = sample[elem]
|
225 |
+
tmp = tmp[top:top + new_h, left:left + new_w]
|
226 |
+
sample[elem] = tmp
|
227 |
+
|
228 |
+
obj_num = len(all_obj) - 1
|
229 |
+
|
230 |
+
sample['meta']['obj_num'] = obj_num
|
231 |
+
|
232 |
+
return sample
|
233 |
+
|
234 |
+
|
235 |
+
class RandomScale(object):
|
236 |
+
"""Randomly resize the image and the ground truth to specified scales.
|
237 |
+
Args:
|
238 |
+
scales (list): the list of scales
|
239 |
+
"""
|
240 |
+
def __init__(self, min_scale=1., max_scale=1.3, short_edge=None):
|
241 |
+
self.min_scale = min_scale
|
242 |
+
self.max_scale = max_scale
|
243 |
+
self.short_edge = short_edge
|
244 |
+
|
245 |
+
def __call__(self, sample):
|
246 |
+
# Fixed range of scales
|
247 |
+
sc = np.random.uniform(self.min_scale, self.max_scale)
|
248 |
+
# Align short edge
|
249 |
+
if self.short_edge is not None:
|
250 |
+
image = sample['prev_img']
|
251 |
+
h, w = image.shape[:2]
|
252 |
+
if h > w:
|
253 |
+
sc *= float(self.short_edge) / w
|
254 |
+
else:
|
255 |
+
sc *= float(self.short_edge) / h
|
256 |
+
|
257 |
+
for elem in sample.keys():
|
258 |
+
if 'meta' in elem:
|
259 |
+
continue
|
260 |
+
tmp = sample[elem]
|
261 |
+
|
262 |
+
if elem == 'prev_img' or elem == 'curr_img' or elem == 'ref_img':
|
263 |
+
flagval = cv2.INTER_CUBIC
|
264 |
+
else:
|
265 |
+
flagval = cv2.INTER_NEAREST
|
266 |
+
|
267 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
268 |
+
new_tmp = []
|
269 |
+
for tmp_ in tmp:
|
270 |
+
tmp_ = cv2.resize(tmp_,
|
271 |
+
None,
|
272 |
+
fx=sc,
|
273 |
+
fy=sc,
|
274 |
+
interpolation=flagval)
|
275 |
+
new_tmp.append(tmp_)
|
276 |
+
tmp = new_tmp
|
277 |
+
else:
|
278 |
+
tmp = cv2.resize(tmp,
|
279 |
+
None,
|
280 |
+
fx=sc,
|
281 |
+
fy=sc,
|
282 |
+
interpolation=flagval)
|
283 |
+
|
284 |
+
sample[elem] = tmp
|
285 |
+
|
286 |
+
return sample
|
287 |
+
|
288 |
+
|
289 |
+
class RandomScaleV2(object):
|
290 |
+
"""Randomly resize the image and the ground truth to specified scales.
|
291 |
+
Args:
|
292 |
+
scales (list): the list of scales
|
293 |
+
"""
|
294 |
+
def __init__(self,
|
295 |
+
min_scale=0.36,
|
296 |
+
max_scale=1.0,
|
297 |
+
short_edge=None,
|
298 |
+
ratio=[3. / 4., 4. / 3.]):
|
299 |
+
self.min_scale = min_scale
|
300 |
+
self.max_scale = max_scale
|
301 |
+
self.short_edge = short_edge
|
302 |
+
self.ratio = ratio
|
303 |
+
|
304 |
+
def __call__(self, sample):
|
305 |
+
image = sample['prev_img']
|
306 |
+
h, w = image.shape[:2]
|
307 |
+
|
308 |
+
new_h, new_w = self.get_params(h, w)
|
309 |
+
|
310 |
+
sc_x = float(new_w) / w
|
311 |
+
sc_y = float(new_h) / h
|
312 |
+
|
313 |
+
# Align short edge
|
314 |
+
if not (self.short_edge is None):
|
315 |
+
if h > w:
|
316 |
+
sc_x *= float(self.short_edge) / w
|
317 |
+
sc_y *= float(self.short_edge) / w
|
318 |
+
else:
|
319 |
+
sc_x *= float(self.short_edge) / h
|
320 |
+
sc_y *= float(self.short_edge) / h
|
321 |
+
|
322 |
+
for elem in sample.keys():
|
323 |
+
if 'meta' in elem:
|
324 |
+
continue
|
325 |
+
tmp = sample[elem]
|
326 |
+
|
327 |
+
if elem == 'prev_img' or elem == 'curr_img' or elem == 'ref_img':
|
328 |
+
flagval = cv2.INTER_CUBIC
|
329 |
+
else:
|
330 |
+
flagval = cv2.INTER_NEAREST
|
331 |
+
|
332 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
333 |
+
new_tmp = []
|
334 |
+
for tmp_ in tmp:
|
335 |
+
tmp_ = cv2.resize(tmp_,
|
336 |
+
None,
|
337 |
+
fx=sc_x,
|
338 |
+
fy=sc_y,
|
339 |
+
interpolation=flagval)
|
340 |
+
new_tmp.append(tmp_)
|
341 |
+
tmp = new_tmp
|
342 |
+
else:
|
343 |
+
tmp = cv2.resize(tmp,
|
344 |
+
None,
|
345 |
+
fx=sc_x,
|
346 |
+
fy=sc_y,
|
347 |
+
interpolation=flagval)
|
348 |
+
|
349 |
+
sample[elem] = tmp
|
350 |
+
|
351 |
+
return sample
|
352 |
+
|
353 |
+
def get_params(self, height, width):
|
354 |
+
area = height * width
|
355 |
+
|
356 |
+
log_ratio = [np.log(item) for item in self.ratio]
|
357 |
+
for _ in range(10):
|
358 |
+
target_area = area * np.random.uniform(self.min_scale**2,
|
359 |
+
self.max_scale**2)
|
360 |
+
aspect_ratio = np.exp(np.random.uniform(log_ratio[0],
|
361 |
+
log_ratio[1]))
|
362 |
+
|
363 |
+
w = int(round(np.sqrt(target_area * aspect_ratio)))
|
364 |
+
h = int(round(np.sqrt(target_area / aspect_ratio)))
|
365 |
+
|
366 |
+
if 0 < w <= width and 0 < h <= height:
|
367 |
+
return h, w
|
368 |
+
|
369 |
+
# Fallback to central crop
|
370 |
+
in_ratio = float(width) / float(height)
|
371 |
+
if in_ratio < min(self.ratio):
|
372 |
+
w = width
|
373 |
+
h = int(round(w / min(self.ratio)))
|
374 |
+
elif in_ratio > max(self.ratio):
|
375 |
+
h = height
|
376 |
+
w = int(round(h * max(self.ratio)))
|
377 |
+
else: # whole image
|
378 |
+
w = width
|
379 |
+
h = height
|
380 |
+
|
381 |
+
return h, w
|
382 |
+
|
383 |
+
class RestrictSize(object):
|
384 |
+
"""Randomly resize the image and the ground truth to specified scales.
|
385 |
+
Args:
|
386 |
+
scales (list): the list of scales
|
387 |
+
"""
|
388 |
+
def __init__(self, max_short_edge=None, max_long_edge=800 * 1.3):
|
389 |
+
self.max_short_edge = max_short_edge
|
390 |
+
self.max_long_edge = max_long_edge
|
391 |
+
assert ((max_short_edge is None)) or ((max_long_edge is None))
|
392 |
+
|
393 |
+
def __call__(self, sample):
|
394 |
+
|
395 |
+
# Fixed range of scales
|
396 |
+
sc = None
|
397 |
+
image = sample['ref_img']
|
398 |
+
h, w = image.shape[:2]
|
399 |
+
# Align short edge
|
400 |
+
if not (self.max_short_edge is None):
|
401 |
+
if h > w:
|
402 |
+
short_edge = w
|
403 |
+
else:
|
404 |
+
short_edge = h
|
405 |
+
if short_edge < self.max_short_edge:
|
406 |
+
sc = float(self.max_short_edge) / short_edge
|
407 |
+
else:
|
408 |
+
if h > w:
|
409 |
+
long_edge = h
|
410 |
+
else:
|
411 |
+
long_edge = w
|
412 |
+
if long_edge > self.max_long_edge:
|
413 |
+
sc = float(self.max_long_edge) / long_edge
|
414 |
+
|
415 |
+
if sc is None:
|
416 |
+
new_h = h
|
417 |
+
new_w = w
|
418 |
+
else:
|
419 |
+
new_h = int(sc * h)
|
420 |
+
new_w = int(sc * w)
|
421 |
+
new_h = new_h - (new_h - 1) % 4
|
422 |
+
new_w = new_w - (new_w - 1) % 4
|
423 |
+
if new_h == h and new_w == w:
|
424 |
+
return sample
|
425 |
+
|
426 |
+
for elem in sample.keys():
|
427 |
+
if 'meta' in elem:
|
428 |
+
continue
|
429 |
+
tmp = sample[elem]
|
430 |
+
|
431 |
+
if 'label' in elem:
|
432 |
+
flagval = cv2.INTER_NEAREST
|
433 |
+
else:
|
434 |
+
flagval = cv2.INTER_CUBIC
|
435 |
+
|
436 |
+
tmp = cv2.resize(tmp, dsize=(new_w, new_h), interpolation=flagval)
|
437 |
+
|
438 |
+
sample[elem] = tmp
|
439 |
+
|
440 |
+
return sample
|
441 |
+
|
442 |
+
|
443 |
+
class RandomHorizontalFlip(object):
|
444 |
+
"""Horizontally flip the given image and ground truth randomly with a probability of 0.5."""
|
445 |
+
def __init__(self, prob):
|
446 |
+
self.p = prob
|
447 |
+
|
448 |
+
def __call__(self, sample):
|
449 |
+
|
450 |
+
if random.random() < self.p:
|
451 |
+
for elem in sample.keys():
|
452 |
+
if 'meta' in elem:
|
453 |
+
continue
|
454 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
455 |
+
new_tmp = []
|
456 |
+
for tmp_ in sample[elem]:
|
457 |
+
tmp_ = cv2.flip(tmp_, flipCode=1)
|
458 |
+
new_tmp.append(tmp_)
|
459 |
+
sample[elem] = new_tmp
|
460 |
+
else:
|
461 |
+
tmp = sample[elem]
|
462 |
+
tmp = cv2.flip(tmp, flipCode=1)
|
463 |
+
sample[elem] = tmp
|
464 |
+
|
465 |
+
return sample
|
466 |
+
|
467 |
+
|
468 |
+
class RandomVerticalFlip(object):
|
469 |
+
"""Vertically flip the given image and ground truth randomly with a probability of 0.5."""
|
470 |
+
def __init__(self, prob=0.3):
|
471 |
+
self.p = prob
|
472 |
+
|
473 |
+
def __call__(self, sample):
|
474 |
+
|
475 |
+
if random.random() < self.p:
|
476 |
+
for elem in sample.keys():
|
477 |
+
if 'meta' in elem:
|
478 |
+
continue
|
479 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
480 |
+
new_tmp = []
|
481 |
+
for tmp_ in sample[elem]:
|
482 |
+
tmp_ = cv2.flip(tmp_, flipCode=0)
|
483 |
+
new_tmp.append(tmp_)
|
484 |
+
sample[elem] = new_tmp
|
485 |
+
else:
|
486 |
+
tmp = sample[elem]
|
487 |
+
tmp = cv2.flip(tmp, flipCode=0)
|
488 |
+
sample[elem] = tmp
|
489 |
+
|
490 |
+
return sample
|
491 |
+
|
492 |
+
|
493 |
+
class RandomGaussianBlur(object):
|
494 |
+
def __init__(self, prob=0.3, sigma=[0.1, 2.]):
|
495 |
+
self.aug = TF.RandomApply([IT.GaussianBlur(sigma)], p=prob)
|
496 |
+
|
497 |
+
def __call__(self, sample):
|
498 |
+
for elem in sample.keys():
|
499 |
+
if 'meta' in elem or 'label' in elem:
|
500 |
+
continue
|
501 |
+
|
502 |
+
if elem == 'curr_img':
|
503 |
+
new_tmp = []
|
504 |
+
for tmp_ in sample[elem]:
|
505 |
+
tmp_ = self.apply_augmentation(tmp_)
|
506 |
+
new_tmp.append(tmp_)
|
507 |
+
sample[elem] = new_tmp
|
508 |
+
else:
|
509 |
+
tmp = sample[elem]
|
510 |
+
tmp = self.apply_augmentation(tmp)
|
511 |
+
sample[elem] = tmp
|
512 |
+
return sample
|
513 |
+
|
514 |
+
def apply_augmentation(self, x):
|
515 |
+
x = Image.fromarray(np.uint8(x))
|
516 |
+
x = self.aug(x)
|
517 |
+
x = np.array(x, dtype=np.float32)
|
518 |
+
return x
|
519 |
+
|
520 |
+
|
521 |
+
class RandomGrayScale(RandomGaussianBlur):
|
522 |
+
def __init__(self, prob=0.2):
|
523 |
+
self.aug = TF.RandomGrayscale(p=prob)
|
524 |
+
|
525 |
+
|
526 |
+
class RandomColorJitter(RandomGaussianBlur):
|
527 |
+
def __init__(self,
|
528 |
+
prob=0.8,
|
529 |
+
brightness=0.4,
|
530 |
+
contrast=0.4,
|
531 |
+
saturation=0.2,
|
532 |
+
hue=0.1):
|
533 |
+
self.aug = TF.RandomApply(
|
534 |
+
[TF.ColorJitter(brightness, contrast, saturation, hue)], p=prob)
|
535 |
+
|
536 |
+
|
537 |
+
class SubtractMeanImage(object):
|
538 |
+
def __init__(self, mean, change_channels=False):
|
539 |
+
self.mean = mean
|
540 |
+
self.change_channels = change_channels
|
541 |
+
|
542 |
+
def __call__(self, sample):
|
543 |
+
for elem in sample.keys():
|
544 |
+
if 'image' in elem:
|
545 |
+
if self.change_channels:
|
546 |
+
sample[elem] = sample[elem][:, :, [2, 1, 0]]
|
547 |
+
sample[elem] = np.subtract(
|
548 |
+
sample[elem], np.array(self.mean, dtype=np.float32))
|
549 |
+
return sample
|
550 |
+
|
551 |
+
def __str__(self):
|
552 |
+
return 'SubtractMeanImage' + str(self.mean)
|
553 |
+
|
554 |
+
|
555 |
+
class ToTensor(object):
|
556 |
+
"""Convert ndarrays in sample to Tensors."""
|
557 |
+
def __call__(self, sample):
|
558 |
+
|
559 |
+
for elem in sample.keys():
|
560 |
+
if 'meta' in elem:
|
561 |
+
continue
|
562 |
+
tmp = sample[elem]
|
563 |
+
|
564 |
+
if elem == 'curr_img' or elem == 'curr_label':
|
565 |
+
new_tmp = []
|
566 |
+
for tmp_ in tmp:
|
567 |
+
if tmp_.ndim == 2:
|
568 |
+
tmp_ = tmp_[:, :, np.newaxis]
|
569 |
+
tmp_ = tmp_.transpose((2, 0, 1))
|
570 |
+
new_tmp.append(torch.from_numpy(tmp_).int())
|
571 |
+
else:
|
572 |
+
tmp_ = tmp_ / 255.
|
573 |
+
tmp_ -= (0.485, 0.456, 0.406)
|
574 |
+
tmp_ /= (0.229, 0.224, 0.225)
|
575 |
+
tmp_ = tmp_.transpose((2, 0, 1))
|
576 |
+
new_tmp.append(torch.from_numpy(tmp_))
|
577 |
+
tmp = new_tmp
|
578 |
+
else:
|
579 |
+
if tmp.ndim == 2:
|
580 |
+
tmp = tmp[:, :, np.newaxis]
|
581 |
+
tmp = tmp.transpose((2, 0, 1))
|
582 |
+
tmp = torch.from_numpy(tmp).int()
|
583 |
+
else:
|
584 |
+
tmp = tmp / 255.
|
585 |
+
tmp -= (0.485, 0.456, 0.406)
|
586 |
+
tmp /= (0.229, 0.224, 0.225)
|
587 |
+
tmp = tmp.transpose((2, 0, 1))
|
588 |
+
tmp = torch.from_numpy(tmp)
|
589 |
+
sample[elem] = tmp
|
590 |
+
|
591 |
+
return sample
|
592 |
+
|
593 |
+
|
594 |
+
class MultiRestrictSize(object):
|
595 |
+
def __init__(self,
|
596 |
+
max_short_edge=None,
|
597 |
+
max_long_edge=800,
|
598 |
+
flip=False,
|
599 |
+
multi_scale=[1.3],
|
600 |
+
align_corners=True,
|
601 |
+
max_stride=16):
|
602 |
+
self.max_short_edge = max_short_edge
|
603 |
+
self.max_long_edge = max_long_edge
|
604 |
+
self.multi_scale = multi_scale
|
605 |
+
self.flip = flip
|
606 |
+
self.align_corners = align_corners
|
607 |
+
self.max_stride = max_stride
|
608 |
+
|
609 |
+
def __call__(self, sample):
|
610 |
+
samples = []
|
611 |
+
image = sample['current_img']
|
612 |
+
h, w = image.shape[:2]
|
613 |
+
for scale in self.multi_scale:
|
614 |
+
# restrict short edge
|
615 |
+
sc = 1.
|
616 |
+
if self.max_short_edge is not None:
|
617 |
+
if h > w:
|
618 |
+
short_edge = w
|
619 |
+
else:
|
620 |
+
short_edge = h
|
621 |
+
if short_edge > self.max_short_edge:
|
622 |
+
sc *= float(self.max_short_edge) / short_edge
|
623 |
+
new_h, new_w = sc * h, sc * w
|
624 |
+
|
625 |
+
# restrict long edge
|
626 |
+
sc = 1.
|
627 |
+
if self.max_long_edge is not None:
|
628 |
+
if new_h > new_w:
|
629 |
+
long_edge = new_h
|
630 |
+
else:
|
631 |
+
long_edge = new_w
|
632 |
+
if long_edge > self.max_long_edge:
|
633 |
+
sc *= float(self.max_long_edge) / long_edge
|
634 |
+
|
635 |
+
new_h, new_w = sc * new_h, sc * new_w
|
636 |
+
|
637 |
+
new_h = int(new_h * scale)
|
638 |
+
new_w = int(new_w * scale)
|
639 |
+
|
640 |
+
if self.align_corners:
|
641 |
+
if (new_h - 1) % self.max_stride != 0:
|
642 |
+
new_h = int(
|
643 |
+
np.around((new_h - 1) / self.max_stride) *
|
644 |
+
self.max_stride + 1)
|
645 |
+
if (new_w - 1) % self.max_stride != 0:
|
646 |
+
new_w = int(
|
647 |
+
np.around((new_w - 1) / self.max_stride) *
|
648 |
+
self.max_stride + 1)
|
649 |
+
else:
|
650 |
+
if new_h % self.max_stride != 0:
|
651 |
+
new_h = int(
|
652 |
+
np.around(new_h / self.max_stride) * self.max_stride)
|
653 |
+
if new_w % self.max_stride != 0:
|
654 |
+
new_w = int(
|
655 |
+
np.around(new_w / self.max_stride) * self.max_stride)
|
656 |
+
|
657 |
+
if new_h == h and new_w == w:
|
658 |
+
samples.append(sample)
|
659 |
+
else:
|
660 |
+
new_sample = {}
|
661 |
+
for elem in sample.keys():
|
662 |
+
if 'meta' in elem:
|
663 |
+
new_sample[elem] = sample[elem]
|
664 |
+
continue
|
665 |
+
tmp = sample[elem]
|
666 |
+
if 'label' in elem:
|
667 |
+
new_sample[elem] = sample[elem]
|
668 |
+
continue
|
669 |
+
else:
|
670 |
+
flagval = cv2.INTER_CUBIC
|
671 |
+
tmp = cv2.resize(tmp,
|
672 |
+
dsize=(new_w, new_h),
|
673 |
+
interpolation=flagval)
|
674 |
+
new_sample[elem] = tmp
|
675 |
+
samples.append(new_sample)
|
676 |
+
|
677 |
+
if self.flip:
|
678 |
+
now_sample = samples[-1]
|
679 |
+
new_sample = {}
|
680 |
+
for elem in now_sample.keys():
|
681 |
+
if 'meta' in elem:
|
682 |
+
new_sample[elem] = now_sample[elem].copy()
|
683 |
+
new_sample[elem]['flip'] = True
|
684 |
+
continue
|
685 |
+
tmp = now_sample[elem]
|
686 |
+
tmp = tmp[:, ::-1].copy()
|
687 |
+
new_sample[elem] = tmp
|
688 |
+
samples.append(new_sample)
|
689 |
+
|
690 |
+
return samples
|
691 |
+
|
692 |
+
|
693 |
+
class MultiToTensor(object):
|
694 |
+
def __call__(self, samples):
|
695 |
+
for idx in range(len(samples)):
|
696 |
+
sample = samples[idx]
|
697 |
+
for elem in sample.keys():
|
698 |
+
if 'meta' in elem:
|
699 |
+
continue
|
700 |
+
tmp = sample[elem]
|
701 |
+
if tmp is None:
|
702 |
+
continue
|
703 |
+
|
704 |
+
if tmp.ndim == 2:
|
705 |
+
tmp = tmp[:, :, np.newaxis]
|
706 |
+
tmp = tmp.transpose((2, 0, 1))
|
707 |
+
samples[idx][elem] = torch.from_numpy(tmp).int()
|
708 |
+
else:
|
709 |
+
tmp = tmp / 255.
|
710 |
+
tmp -= (0.485, 0.456, 0.406)
|
711 |
+
tmp /= (0.229, 0.224, 0.225)
|
712 |
+
tmp = tmp.transpose((2, 0, 1))
|
713 |
+
samples[idx][elem] = torch.from_numpy(tmp)
|
714 |
+
|
715 |
+
return samples
|
aot/datasets/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
aot/datasets/DAVIS/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Put DAVIS 2017 here.
|
aot/datasets/Static/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Put the static dataset here. Guidance can be found in [AFB-URR](https://github.com/xmlyqing00/AFB-URR), which we referred to in the implementation of the pre-training.
|
aot/datasets/YTB/2018/train/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Put the training split of YouTube-VOS 2018 here.
|
aot/datasets/YTB/2018/valid/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Put the validation split of YouTube-VOS 2018 here.
|