The code for paper Adaptive Contextual Perception: How to Generalize to New Backgrounds and Ambiguous Objects
Zhuofan Ying, Peter Hase, Mohit Bansal
Create and activate conda environment:
conda create -n AdaCont python=3.7
conda activate AdaContInstall the dependencies with:
pip install -r requirements.txt- Download data: 1) Places dataset and 2) COCO dataset.
- Preprocess Places and COCO datasets:
# preprocess COCO
python coco.py
# preprocess Places
python places.py- Create ColorObject and SceneObject dataset, including in-distribution (ID) train, ID val, ID test, Background-Invariance (OOD1) test, Object-Disambiguation (OOD2) test, probing data for probing method, perturbation data for geometric method, and perturbation data for sets:
python data_gen.py- Run scripts in
scripts/to train all baseline models and augmentation models for our analysis:
./scripts/train_color.sh
./scripts/train_scene.shFor all scripts, see scripts/all_scripts.sh
- To compute feature factorization and feature weighting metrics for models, run
ComputeMetrics.ipynb. This will save the metrics tosaved_dict_ColorObject.pklandsaved_dict_SceneCOCO.pkl. - To reproduce our regression and causal analysis, run
RegressionAnalysis.ipynbandCausalAnalysis.ipynb
This code is based on TRM.
