This repo contains code used to perform experiments in our paper about generating counterfactual explanations in the context of time-series remote sensing multiclass data.
Please open our v2 code and follow the instructions therein.
Click to read the v2 instructions
- Set up virtual environment:
conda env create -f environment.yml && conda activate cf-env - Produce CFE4SITS results:
python ExtractCF.py --do-plots - Produce NG results: Disclaimer: takes several hours to complete.
python competitor_NG.py pred --use-cam && python competitor_NG.py results --use-cam - Produce k-NNC results:
python competitor_knn.py train && python competitor_knn.py pred && python competitor_knn.py results5.To generate comparative plotspython selected_plots.py
All plots get saved in the folder img. A metrics summary is logged both to the standard output and to a text file in logs.
The project can be divided into the following functional blocks:
- [Model training] Training a classifier model
- [Noiser training] Training the counterfactual generative model based on an existing classifier
- [Result analysis] Scripts and notebooks registering metrics, plots and tables for publication
- [General utils] General utility files, be them scripts or data
Each script can be somewhat parameterized via command line. Please call python3 SCRIPT_FILENAME.py --help to get help specific to each script.
All scripts log results to logs/SCRIPT_FILENAME/RUN_ID_FOLDER, where RUN_ID_FOLDER is an identifier depending on the parameters that were used to run the script. Model weights, hyperparameters, runtime metrics and plots, they all get saved to this folder.
Files concerning this part:
main_classif.py: trains a timeseries classifier
Files concerning this part:
main_noiser.py: trains a noiser model from a base model- [FUTURE]
main_multi.py: trains a noiser for a multivariate case (for now the scripts seems to train a classifier as well?). This is halted now and kept for the future.
Files concerning this part:
ExtractCF.py: generates several results presented in the paper (chord graph, perturbation examples, average perturbation) and some not yet included (PCA)
Modules used across several scripts have been assembled in the cfsits_tools folder/module.
In the data folder there are files corrsponding to the Koumbia dataset:
- all
[x|y]_[train|valid|test]_2020.npyfiles dates.txt
For experiments with the UCR data, a folder UCRArchive_2018 containing the dataset should be placed here, within data.