This repo accompanies the prototype code from our report, specifically the Invariant Risk Minimization (IRM) approach discussed in chapters 3 & 4.
conda create --name irm_env python=3.7 ipykernel
conda activate irm_env
conda install pip
pip install -r requirements.txt
Steps to generate the WildCam dataset used for this experiment.
-
Step 1 : Download the Camera Traps (or Wild Cams) dataset - iWildCam 2019 using Kaggle.
- Use Kaggle account to download data. This involves first creating a new Kaggle API from your account and then downloading the
kaggle.jsonfile in[user-home]/.kagglefolder. If there is no.kagglefolder yet, create it and then move thekaggle.jsonto the.kagglefolder. - Install kaggle package,
conda install -c conda-forge kaggle chmod 600 ~/.kaggle/kaggle.json- Download data,
kaggle competitions download -c iwildcam-2019-fgvc6. This is a 44GB file! unzip iwildcam-2019-fgvc6.zip -d ./iWildCamunzip -q train_images.zip -d ./train. NOTE: The test set images are unlabeled so are being ignored from our experiments. Instead, we create a test set from the training data in the next step.
- Use Kaggle account to download data. This involves first creating a new Kaggle API from your account and then downloading the
-
Step 2 :
- Run
python create_denoised_data.py- This creates a new directory./data/wildcam_denoisedconsisting of the images we used for training and testing both the IRM and ERM models. The list of images are available in./data/train_test_filenames.json.
- Run
.
├── ./create_denoised_data.py
├── ./data
│ ├── ./data/train_test_filenames.json
│ └── ./data/wildcam_denoised
│ ├── ./data/wildcam_denoised/test
│ ├── ./data/wildcam_denoised/train_43
│ └── ./data/wildcam_denoised/train_46
├── ./dataset.py
├── ./ERM_results.out
├── ./IRM_results.out
├── ./main.py
├── ./models
│ └── ./models/wildcam_denoised_121_0.001_0_0.0_ERM.pth
│ └── ./models/wildcam_denoised_121_0.001_40_10000.0_IRM.pth
├── ./models.py
├── ./README.md
├── ./requirements.txt
└── ./train.py
- Simply run
python main.pyto train an ERM/ IRM model. The argumentspenalty_anneal_itersandpenalty_weightwhen set to 0 trains an ERM model. - The model is saved in the
./modelsfolder
- Results from training both IRM and ERM are available in
ERM_results.outandIRM_results.outfiles
- The
model_explanation_irm.ipynbnotebook provides LIME explanations for a sample image based on the IRM model. For a deeper dive into explanations and comparison between all images based on both the ERM and IRM models look at our prototype - Scene
Leveraged source code from the paper:
@article{InvariantRiskMinimization,
title={Invariant Risk Minimization},
author={Arjovsky, Martin and Bottou, L{\'e}on and Gulrajani, Ishaan and Lopez-Paz, David},
journal={arXiv},
year={2019}
}