Skip to content

Commit ba34e63

Browse files
committed
code release
1 parent 44ccd39 commit ba34e63

14 files changed

+1907
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Michael Hobley @ Active Vision Laboratory, Oxford
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

100644100755
Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
# ABC123
1+
# Learning To Count Anything: Reference-less Class-agnostic Counting with Weak Supervision
2+
**[Project Page](https://ABC123.active.vision/) |
3+
[Latest arXiv](https://arxiv.org/abs/2309.04820) |
4+
[Dataset](https://MCAC.active.vision)
5+
**
6+
7+
[Michael Hobley](https://scholar.google.co.uk/citations?user=2EftbyIAAAAJ&hl=en),
8+
[Victor Adrian Prisacariu](http://www.robots.ox.ac.uk/~victor/).
9+
10+
[Active Vision Lab (AVL)](https://www.robots.ox.ac.uk/~lav/),
11+
University of Oxford.
12+
13+
14+
## Environment
15+
We provide a `environment.yml` file to set up a `conda` environment:
16+
17+
```sh
18+
git clone https://github.com/ActiveVisionLab/ABC123.git
19+
cd ABC123
20+
conda env create -f environment.yml
21+
```
22+
23+
## Dataset Download
24+
### MCAC
25+
Dowload [MCAC](https://www.robots.ox.ac.uk/~lav/Datasets/MCAC/MCAC.zip)
26+
to precompute ground truth density maps for other resolutions, occlusion percentages, and gaussian standard deviations:
27+
28+
```sh
29+
cd PATH/TO/MCAC/
30+
python make_gaussian_maps.py --occulsion_limit <desired_max_occlusion> --crop_size 672 --img_size <desired_resolution> --gauss_constant <desired_gaussian_std>;
31+
```
32+
33+
## Trained Model Download
34+
We provide [example weights](https://www.robots.ox.ac.uk/~mahobley/ABC123/model_chkpt.zip) for our models trained on MCAC.
35+
Put this in ./checkpoints/.
36+
37+
38+
## Example Training
39+
40+
To train the counting network:
41+
```sh
42+
python main.py --config ABC123;
43+
```
44+
45+
## Example Testing
46+
To test a trained model on MCAC:
47+
48+
```sh
49+
python main.py --config ABC123test;
50+
```
51+
52+
To test a trained model on MCAC-M1:
53+
54+
```sh
55+
python main.py --config ABC123testM1;
56+
```
57+
58+
59+
60+
## Citation
61+
```
62+
@article{hobley2023abc,
63+
title={ABC Easy as 123: A Blind Counter for Exemplar-Free Multi-Class Class-agnostic Counting},
64+
author={Michael A. Hobley and Victor A. Prisacariu},
65+
journal={arXiv preprint arXiv:2309.04820},
66+
year={2023},
67+
}
68+
```

configs/ABC123.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
seed: -1
2+
dataset: MCAC
3+
test_split: val
4+
5+
MCAC_crop_size: 672
6+
MCAC_occ_limit: 70
7+
img_channels: 3
8+
image_transforms: ref_rot
9+
10+
counting_backbone: "vit_dino"
11+
counting_backbone_unfreeze_layers: -1
12+
13+
counting_head: "5_32"
14+
upsample_padding_mode: 'replicate' # 'zeros', 'reflect', 'replicate'
15+
16+
17+
matching_type: density # no_match, count, density
18+
matcher_cost_power: 2
19+
normalize_matching: True
20+
21+
counting_loss: pixelwise_mae
22+
gtd_scale: 400
23+
24+
25+
learning_rate: 3e-5
26+
scheduler: StepLR
27+
scheduler_steps: 35
28+
scheduler_gamma: 0.5
29+
weight_decay: 0
30+
31+
train_batch_size: 2
32+
eval_batch_size: 2
33+
val_every: 1
34+
35+
36+
max_epochs: 150
37+
38+
39+
40+
41+
42+

configs/ABC123M1.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
seed: -1
2+
dataset: MCAC-M1
3+
test_split: val
4+
5+
MCAC_crop_size: 672
6+
MCAC_occ_limit: 70
7+
img_channels: 3
8+
image_transforms: ref_rot
9+
10+
counting_backbone: "vit_dino"
11+
counting_backbone_unfreeze_layers: -1
12+
13+
counting_head: "5_32"
14+
upsample_padding_mode: 'replicate' # 'zeros', 'reflect', 'replicate'
15+
16+
17+
matching_type: density # no_match, count, density
18+
matcher_cost_power: 2
19+
normalize_matching: True
20+
21+
counting_loss: pixelwise_mae
22+
gtd_scale: 400
23+
24+
25+
learning_rate: 3e-5
26+
scheduler: StepLR
27+
scheduler_steps: 35
28+
scheduler_gamma: 0.5
29+
weight_decay: 0
30+
31+
train_batch_size: 2
32+
eval_batch_size: 2
33+
val_every: 1
34+
35+
max_epochs: 150
36+
37+
38+
39+
40+
41+

configs/ABC123test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
seed: -1
2+
dataset: MCAC
3+
test_split: test
4+
resume_path: "checkpoints/model_chkpt.ckpt"
5+
6+
MCAC_crop_size: 672
7+
MCAC_occ_limit: 70
8+
img_channels: 3
9+
10+
counting_backbone: "vit_dino"
11+
counting_head: "5_32"
12+
upsample_padding_mode: 'replicate' # 'zeros', 'reflect', 'replicate'
13+
14+
matching_type: density # no_match, count, density
15+
matcher_cost_power: 2
16+
normalize_matching: True
17+
18+
gtd_scale: 400
19+
20+
21+
eval_batch_size: 2
22+
val_every: 1
23+
24+
max_epochs: 0

configs/ABC123testM1.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
seed: -1
2+
dataset: MCAC-M1
3+
test_split: test
4+
resume_path: "checkpoints/model_chkpt.ckpt"
5+
6+
MCAC_crop_size: 672
7+
MCAC_occ_limit: 70
8+
img_channels: 3
9+
10+
counting_backbone: "vit_dino"
11+
counting_head: "5_32"
12+
upsample_padding_mode: 'replicate' # 'zeros', 'reflect', 'replicate'
13+
14+
matching_type: density # no_match, count, density
15+
matcher_cost_power: 2
16+
normalize_matching: True
17+
18+
gtd_scale: 400
19+
20+
21+
eval_batch_size: 2
22+
val_every: 1
23+
24+
max_epochs: 0

configs/_DEFAULT.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
seed: -1
3+
dataset: MCAC
4+
data_path: "PATH/TO/MCAC/"
5+
log_dir: logs/
6+
resume_path: ""
7+
find_unused_parameters: False
8+
9+
10+
MCAC_occ_limit: -1
11+
MCAC_crop_size: -1
12+
MCAC_max_num_classes: 5
13+
MCAC_max_number_per_type: 300
14+
MCAC_exclude_imgs_with_counts_over: -1 # no images with counts over the amount, -1 is the no excclusion case
15+
MCAC_exclude_imgs_with_num_classes_over: -1 # no images with number of classes over the amount, -1 is the no excclusion case
16+
17+
img_channels: 3
18+
img_size: [224, 224]
19+
image_transforms: None
20+
drop_last: True
21+
22+
counting_backbone_pretrained: True # if using pretrained vakues (only a thing for dino)
23+
counting_backbone_unfreeze_layers: -1
24+
counting_head: "5_32" # linearprobe
25+
upsample_padding_mode: 'replicate' # 'zeros', 'reflect', 'replicate'
26+
27+
28+
matching_type: no_match # no_match, count, density
29+
normalize_matching: False # ONLY APPLIES TO DENSITY MATCHING
30+
matcher_cost_p_norm: 1
31+
matcher_cost_power: 1
32+
33+
counting_loss: pixelwise_mae
34+
gtd_scale: 1
35+
36+
learning_rate: 3e-4
37+
scheduler: None
38+
weight_decay: 0
39+
scheduler_steps: 100
40+
scheduler_gamma: 0.5
41+
accumulate_grad_batches: 1
42+
43+
train_batch_size: 32
44+
eval_batch_size: 32
45+
num_workers: 4
46+
47+
num_sanity_val_steps: -1
48+
49+
val_every: 1
50+
max_epochs: 10000
51+
max_steps: -1

0 commit comments

Comments
 (0)