Analysis Tools
This folder contains the visualization and analysis tools developed for BackdoorBench. The demo scripts for utilizing such tools are given in demo.sh. The jupyter notebook for utilizing such tools are in Demos folder.
The implemented tools and corresponding scripts are * visual_tsne.py * T-SNE, the T-SNE of features. Typical output is
visual_umap.py
visual_na.py
visual_shap.py
visual_gradcam.py
visualize_fre.py
visual_act.py
visual_cm.py
visual_fv.py
visual_fm.py
visual_actdist.py
visual_tac.py
visual_lips.py
visual_landscape.py
visual_network.py
visual_hessian.py
visual_metric.py
visual_quality.py
Image Quality, evaluating the given results using some image quality metrics. The csv file is given.
Dataset used for visualization.
Mixed Test is generated by sampling data from both Clean Test and BD Test by a poison ratio pratio given in args.
Subset is default to sample 5000 samples with n_sub in args.
By default, all methods use BD train dataset for visualization (if needed).
For clean model trained using prototype.py, the results can be loaded using args ‘prototype’. However, only clean dataset can be loaded and some methods cannot be adopted to analyze such results.
Supported dataset types for each method is given in the following table
Script
Method
Clean Train
BD Train
Clean Test
BD Test
Mixed Test
Subset
Remark
visual_tsne.py
T-SNE
\(\surd\)
\(\surd\)
\(\surd\)
\(\times\)
\(\surd\)
\(\surd\)
visual_umap.py
UMAP
\(\surd\)
\(\surd\)
\(\surd\)
\(\times\)
\(\surd\)
\(\surd\)
visual_na.py
Neuron Activation
\(\times\)
\(\surd\)
\(\times\)
\(\surd\)
\(\times\)
\(\surd\)
BD only
visual_shap.py
Shapely Value
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
visual_gradcam.py
Grad-CAM
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
visual_fre.py
Frequency Saliency Map
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
visual_act.py
Activated Image
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
visual_cm.py
Confusion Matrix
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\times\)
\(\times\)
visual_fv.py
Feature Visualization
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
visual_fm.py
Feature Map
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\times\)
\(\times\)
visual_actdist.py
Activation Distribution
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
visual_tac.py
Trigger Activation Change
\(\times\)
\(\surd\)
\(\times\)
\(\surd\)
\(\times\)
\(\surd\)
BD only
visual_lips.py
Lipschitz Constant
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
visual_landscape.py
Loss Landscape
\(\surd\)
\(\surd\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
visual_network.py
Network Structure
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
\(\times\)
visual_hessian.py
Eigenvalues of Hessian
\(\surd\)
\(\surd\)
\(\surd\)
\(\surd\)
\(\times\)
\(\times\)
visual_metric.py
Metrics
\(\times\)
\(\times\)
\(\surd\)
\(\surd\)
\(\times\)
\(\times\)
visual_quality.py
Image Quality
\(\times\)
\(\surd\)
\(\times\)
\(\surd\)
\(\surd\)
\(\surd\)
Additional note for Loss Landscape
Message Passing Interface (MPI) is needed to accelerate the computation of loss landscape. Thus, you will need to install mpi4py. mpi4py can be installed either using pip or conda, but with pip you will need to install MPI yourself first (e.g. OpenMPI or MPICH), while conda will install its own MPI libraries. For example, you can run the following commands in your terminal to install mpi4py:
sudo apt install libopenmpi-dev pip install mpi4py
or
conda install -c conda-forge mpi4py
You need also clone the repo https://github.com/tomgoldstein/loss-landscape to the visualization folder.
To run the landscape visualization using MPI (parallel), you can run the command
mpirun -n num_gpu python visual_landscape.py
For more information, please refer to https://github.com/tomgoldstein/loss-landscape/blob/master/README.md
Additional note for network structure
GraphViz and its Python wrapper are needed by hiddenlayer and pytorchviz to generate network graphs. Similar as MPI, you can install them using pip or conda. For example, you can run the following commands in your terminal to install them
sudo apt install graphviz pip3 install graphviz pip install hiddenlayer pip install -U git+https://github.com/szagoruyko/pytorchviz.git@master
or
conda install graphviz python-graphviz pip install hiddenlayer pip install -U git+https://github.com/szagoruyko/pytorchviz.git@master
For more information, please refer to https://github.com/waleedka/hiddenlayer/blob/master/README.md or https://github.com/szagoruyko/pytorchviz/blob/master/README.md