Skip to content

Commit a151225

Browse files
ImaGonEsStepCrow
andauthored
Add All4One (#382)
Co-authored-by: ImaGonEs <[email protected]>
1 parent 5b564c2 commit a151225

File tree

11 files changed

+987
-0
lines changed

11 files changed

+987
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The library is self-contained, but it is possible to use the models outside of s
5959
---
6060

6161
## Methods available
62+
* [All4One](https://openaccess.thecvf.com/content/ICCV2023/html/Estepa_All4One_Symbiotic_Neighbour_Contrastive_Learning_via_Self-Attention_and_Redundancy_Reduction_ICCV_2023_paper.html)
6263
* [Barlow Twins](https://arxiv.org/abs/2103.03230)
6364
* [BYOL](https://arxiv.org/abs/2006.07733)
6465
* [DeepCluster V2](https://arxiv.org/abs/2006.09882)
@@ -216,6 +217,7 @@ All pretrained models avaiable can be downloaded directly via the tables below o
216217

217218
| Method | Backbone | Epochs | Dali | Acc@1 | Acc@5 | Checkpoint |
218219
|--------------|:--------:|:------:|:----:|:--------------:|:--------------:|:----------:|
220+
| All4One | ResNet18 | 1000 | :x: | 93.24 | 99.88 | [:link:](https://drive.google.com/drive/folders/1dtYmZiftruQ7B2PQ8fo44wguCZ0eSzAd?usp=sharing) |
219221
| Barlow Twins | ResNet18 | 1000 | :x: | 92.10 | 99.73 | [:link:](https://drive.google.com/drive/folders/1L5RAM3lCSViD2zEqLtC-GQKVw6mxtxJ_?usp=sharing) |
220222
| BYOL | ResNet18 | 1000 | :x: | 92.58 | 99.79 | [:link:](https://drive.google.com/drive/folders/1KxeYAEE7Ev9kdFFhXWkPZhG-ya3_UwGP?usp=sharing) |
221223
|DeepCluster V2| ResNet18 | 1000 | :x: | 88.85 | 99.58 | [:link:](https://drive.google.com/drive/folders/1tkEbiDQ38vZaQUsT6_vEpxbDxSUAGwF-?usp=sharing) |
@@ -237,6 +239,7 @@ All pretrained models avaiable can be downloaded directly via the tables below o
237239

238240
| Method | Backbone | Epochs | Dali | Acc@1 | Acc@5 | Checkpoint |
239241
|--------------|:--------:|:------:|:----:|:--------------:|:--------------:|:----------:|
242+
| All4One | ResNet18 | 1000 | :x: | 72.17 | 93.35 | [:link:](https://drive.google.com/drive/folders/1oQcC80XPr-Wxhjs-PEqD_8VhUa_izqeZ?usp=sharing) |
240243
| Barlow Twins | ResNet18 | 1000 | :x: | 70.90 | 91.91 | [:link:](https://drive.google.com/drive/folders/1hDLSApF3zSMAKco1Ck4DMjyNxhsIR2yq?usp=sharing) |
241244
| BYOL | ResNet18 | 1000 | :x: | 70.46 | 91.96 | [:link:](https://drive.google.com/drive/folders/1hwsEdsfsUulD2tAwa4epKK9pkSuvFv6m?usp=sharing) |
242245
|DeepCluster V2| ResNet18 | 1000 | :x: | 63.61 | 88.09 | [:link:](https://drive.google.com/drive/folders/1gAKyMz41mvGh1BBOYdc_xu6JPSkKlWqK?usp=sharing) |
@@ -257,6 +260,7 @@ All pretrained models avaiable can be downloaded directly via the tables below o
257260

258261
| Method | Backbone | Epochs | Dali | Acc@1 (online) | Acc@1 (offline) | Acc@5 (online) | Acc@5 (offline) | Checkpoint |
259262
|-------------------------|:--------:|:------:|:------------------:|:--------------:|:---------------:|:--------------:|:---------------:|:----------:|
263+
| All4One | ResNet18 | 400 | :heavy_check_mark: | 81.93 | - | 96.23 | - | [:link:](https://drive.google.com/drive/folders/1bJCRLP5Rz_JEylNq9C4sY3ccYZSchUGR?usp=sharing) |
260264
| Barlow Twins :rocket: | ResNet18 | 400 | :heavy_check_mark: | 80.38 | 80.16 | 95.28 | 95.14 | [:link:](https://drive.google.com/drive/folders/1rj8RbER9E71mBlCHIZEIhKPUFn437D5O?usp=sharing) |
261265
| BYOL :rocket: | ResNet18 | 400 | :heavy_check_mark: | 80.16 | 80.32 | 95.02 | 94.94 | [:link:](https://drive.google.com/drive/folders/1riOLjMawD_znO4HYj8LBN2e1X4jXpDE1?usp=sharing) |
262266
| DeepCluster V2 | ResNet18 | 400 | :x: | 75.36 | 75.4 | 93.22 | 93.10 | [:link:](https://drive.google.com/drive/folders/1d5jPuavrQ7lMlQZn5m2KnN5sPMGhHFo8?usp=sharing) |

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ While the library is self contained, it is possible to use the models outside of
6363

6464
solo/methods/base
6565
solo/methods/linear
66+
solo/methods/all4one
6667
solo/methods/barlow
6768
solo/methods/byol
6869
solo/methods/deepclusterv2

docs/source/solo/methods/all4one.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
All4One
2+
======
3+
4+
.. automethod:: solo.methods.all4one.All4One.__init__
5+
:noindex:
6+
7+
8+
add_model_specific_args
9+
~~~~~~~~~~~~~~~~~~~~~~~
10+
.. automethod:: solo.methods.all4one.All4One.add_model_specific_args
11+
:noindex:
12+
13+
learnable_params
14+
~~~~~~~~~~~~~~~~
15+
.. autoattribute:: solo.methods.all4one.All4One.learnable_params
16+
:noindex:
17+
18+
dequeue_and_enqueue
19+
~~~~~~~~~~~~~~~~~~~
20+
.. automethod:: solo.methods.all4one.All4One.dequeue_and_enqueue
21+
:noindex:
22+
23+
find_nn
24+
~~~~~~~~~~~~~~~~~~~~
25+
.. automethod:: solo.methods.all4one.All4One.find_nn
26+
:noindex:
27+
28+
off_diagonal
29+
~~~~~~~~~~~~~~~~~~~~
30+
.. automethod:: solo.methods.all4one.All4One.off_diagonal
31+
:noindex:
32+
33+
34+
save_NN
35+
~~~~~~~~~~~~~~~~~~~~
36+
.. automethod:: solo.methods.all4one.All4One.save_NN
37+
:noindex:
38+
39+
40+
forward
41+
~~~~~~~
42+
.. automethod:: solo.methods.all4one.All4One.forward
43+
:noindex:
44+
45+
training_step
46+
~~~~~~~~~~~~~
47+
.. automethod:: solo.methods.all4one.All4One.training_step
48+
:noindex:

docs/source/solo/utils.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,103 @@ Whitening
158158

159159
.. automethod:: solo.utils.whitening.Whitening2d.__init__
160160
:noindex:
161+
162+
163+
PositionalEncoding1D
164+
---------------------
165+
:class:`PositionalEncoding1D` applies positional encoding to the last dimension of a 3D tensor.
166+
167+
__init__
168+
~~~~~~~~
169+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding1D.__init__
170+
:noindex:
171+
172+
forward
173+
~~~~~~~
174+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding1D.forward
175+
:noindex:
176+
177+
PositionalEncodingPermute1D
178+
---------------------------
179+
:class:`PositionalEncodingPermute1D` permutes the input tensor and applies 1D positional encoding.
180+
181+
__init__
182+
~~~~~~~~
183+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute1D.__init__
184+
:noindex:
185+
186+
forward
187+
~~~~~~~
188+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute1D.forward
189+
:noindex:
190+
191+
PositionalEncoding2D
192+
---------------------
193+
:class:`PositionalEncoding2D` applies positional encoding to the last two dimensions of a 4D tensor.
194+
195+
__init__
196+
~~~~~~~~
197+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding2D.__init__
198+
:noindex:
199+
200+
forward
201+
~~~~~~~
202+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding2D.forward
203+
:noindex:
204+
205+
PositionalEncodingPermute2D
206+
---------------------------
207+
:class:`PositionalEncodingPermute2D` permutes the input tensor and applies 2D positional encoding.
208+
209+
__init__
210+
~~~~~~~~
211+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute2D.__init__
212+
:noindex:
213+
214+
forward
215+
~~~~~~~
216+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute2D.forward
217+
:noindex:
218+
219+
PositionalEncoding3D
220+
---------------------
221+
:class:`PositionalEncoding3D` applies positional encoding to the last three dimensions of a 5D tensor.
222+
223+
__init__
224+
~~~~~~~~
225+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding3D.__init__
226+
:noindex:
227+
228+
forward
229+
~~~~~~~
230+
.. automethod:: solo.utils.positional_encoding.PositionalEncoding3D.forward
231+
:noindex:
232+
233+
PositionalEncodingPermute3D
234+
---------------------------
235+
:class:`PositionalEncodingPermute3D` permutes the input tensor and applies 3D positional encoding.
236+
237+
__init__
238+
~~~~~~~~
239+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute3D.__init__
240+
:noindex:
241+
242+
forward
243+
~~~~~~~
244+
.. automethod:: solo.utils.positional_encoding.PositionalEncodingPermute3D.forward
245+
:noindex:
246+
247+
Summer
248+
------
249+
:class:`Summer` adds positional encoding to the original tensor.
250+
251+
__init__
252+
~~~~~~~~
253+
.. automethod:: solo.utils.positional_encoding.Summer.__init__
254+
:noindex:
255+
256+
forward
257+
~~~~~~~
258+
.. automethod:: solo.utils.positional_encoding.Summer.forward
259+
:noindex:
260+

scripts/pretrain/cifar/all4one.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
defaults:
2+
- _self_
3+
- augmentations: asymmetric.yaml
4+
- wandb: private.yaml
5+
- override hydra/hydra_logging: disabled
6+
- override hydra/job_logging: disabled
7+
8+
# disable hydra outputs
9+
hydra:
10+
output_subdir: null
11+
run:
12+
dir: .
13+
14+
name: "All4One-cifar100" # change here for cifar10
15+
method: "all4one"
16+
backbone:
17+
name: "resnet18"
18+
method_kwargs:
19+
temperature: 0.2
20+
proj_hidden_dim: 2048
21+
pred_hidden_dim: 4096
22+
proj_output_dim: 256
23+
queue_size: 98304
24+
momentum:
25+
base_tau: 0.99
26+
final_tau: 1.0
27+
data:
28+
dataset: cifar100 # change here for cifar10
29+
train_path: "./datasets/"
30+
val_path: "./datasets/"
31+
format: "image_folder"
32+
num_workers: 4
33+
optimizer:
34+
name: "lars"
35+
batch_size: 256
36+
lr: 1.0
37+
classifier_lr: 0.1
38+
weight_decay: 1e-5
39+
kwargs:
40+
clip_lr: True
41+
eta: 0.02
42+
exclude_bias_n_norm: True
43+
scheduler:
44+
name: "warmup_cosine"
45+
checkpoint:
46+
enabled: True
47+
dir: "trained_models"
48+
frequency: 1
49+
auto_resume:
50+
enabled: False
51+
52+
# overwrite PL stuff
53+
max_epochs: 1000
54+
devices: [0]
55+
sync_batchnorm: True
56+
accelerator: "gpu"
57+
strategy: "ddp"
58+
precision: 16-mixed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defaults:
2+
- _self_
3+
- augmentations: asymmetric.yaml
4+
- wandb: private.yaml
5+
- override hydra/hydra_logging: disabled
6+
- override hydra/job_logging: disabled
7+
8+
# disable hydra outputs
9+
hydra:
10+
output_subdir: null
11+
run:
12+
dir: .
13+
14+
name: "all4one-imagenet100"
15+
method: "all4one"
16+
backbone:
17+
name: "resnet18"
18+
method_kwargs:
19+
temperature: 0.2
20+
proj_hidden_dim: 2048
21+
pred_hidden_dim: 4096
22+
proj_output_dim: 256
23+
queue_size: 98340
24+
data:
25+
dataset: imagenet100
26+
train_path: "./datasets/imagenet-100/train"
27+
val_path: "./datasets/imagenet-100/val"
28+
format: "dali"
29+
num_workers: 4
30+
optimizer:
31+
name: "lars"
32+
batch_size: 128
33+
lr: 1.0
34+
classifier_lr: 0.1
35+
weight_decay: 1e-5
36+
kwargs:
37+
clip_lr: True
38+
eta: 0.02
39+
exclude_bias_n_norm: True
40+
scheduler:
41+
name: "warmup_cosine"
42+
checkpoint:
43+
enabled: True
44+
dir: "trained_models"
45+
frequency: 1
46+
auto_resume:
47+
enabled: True
48+
49+
# overwrite PL stuff
50+
max_epochs: 400
51+
devices: [0, 1]
52+
sync_batchnorm: True
53+
accelerator: "gpu"
54+
strategy: "ddp"
55+
precision: 16-mixed

solo/methods/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from solo.methods.vibcreg import VIbCReg
3838
from solo.methods.vicreg import VICReg
3939
from solo.methods.wmse import WMSE
40+
from solo.methods.all4one import All4One
41+
4042

4143
METHODS = {
4244
# base classes
@@ -61,6 +63,7 @@
6163
"vibcreg": VIbCReg,
6264
"vicreg": VICReg,
6365
"wmse": WMSE,
66+
"all4one": All4One,
6467
}
6568
__all__ = [
6669
"BarlowTwins",
@@ -83,4 +86,5 @@
8386
"VIbCReg",
8487
"VICReg",
8588
"WMSE",
89+
"All4One",
8690
]

0 commit comments

Comments
 (0)