Download the following datasets:
- FSC-147-OCC (occlusion-augmented FSC-147 dataset)
- CARPK-OCC (occlusion-augmented CARPK dataset)
- CAPTURE-Real
<repo-root>/
data/
FSC147_OCC/
images/
annotations/
fsc147_val_occ.json
fsc147_test_occ.json
CARPK_OCC/
test/
carpk_occ.json
Capture/
real_dataset/
real_dataset.json
The code has been tested with the following setup:
- OS: Ubuntu 24.04.3 LTS
- Compiler: GCC 11.3 and 11.4
- Python: 3.9.19
- GPU: RTX 5090
In this project, GCC 11.3 and 11.4 were tested. The following command installs GCC and other development libraries and tools required for compiling software in Ubuntu.
sudo apt update
sudo apt install build-essential
The following commands will create a suitable Anaconda environment for running the training and inference procedures.
conda create -n countocc python=3.9.19
conda activate countocc
cd countocc
pip install -r requirements.txt
export CC=/usr/bin/gcc-11 # this ensures that gcc 11 is being used for compilation
cd models/GroundingDINO/ops
python setup.py build install
python test.py # should result in 6 lines of * True
pip install git+https://github.com/facebookresearch/segment-anything.git
cd ../../../
Make the checkpoints directory inside the CountOCC repository.
mkdir checkpoints
Execute the following command.
python download_bert.py
Download the pretrained Swin-B GroundingDINO weights.
wget -P checkpoints https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha2/groundingdino_swinb_cogcoor.pth
Download the pretrained ViT-H Segment Anything Model (SAM) weights.
wget -P checkpoints https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
Download the pretrained weights. To reproduce the results in the paper, run the following commands after activating the Anaconda environment.
For the validation set:
python -u main_inference.py --output_dir ./countocc_val -c config/cfg_fsc147_val.py --eval --datasets config/datasets_fsc147_val.json --pretrain_model_path checkpoints/checkpoint_best.pth --options text_encoder_type=checkpoints/bert-base-uncased --crop --sam_tt_norm --remove_bad_exemplar --use_frm
For the test set:
python -u main_inference.py --output_dir ./countocc_test -c config/cfg_fsc147_test.py --eval --datasets config/datasets_fsc147_test.json --pretrain_model_path checkpoints/checkpoint_best.pth --options text_encoder_type=checkpoints/bert-base-uncased --crop --sam_tt_norm --remove_bad_exemplar --use_frm
For the test set:
python test_carpk.py --pretrain_model_path ./checkpoints/checkpoint_best.pth --images_path ./data/CARPK-OCC/test --annotations_json ./data/CARPK-OCC/carpk_occ.json --use_exemplars --confidence_thresh 0.40 --use_frm
For the Capture-Real set:
python test_capture.py --pretrain_model_path ./checkpoints/checkpoint_best.pth --images_path ./data/Capture/real_dataset --annotations_json ./data/Capture/real_dataset_updated.json --use_exemplars --confidence_thresh 0.40 --use_frm