This is the program of personal individual project, the academic part of MSc degree in Master of Science of Imperial College London.
The problem we are interested in is to identify the specific semantic meaning of units within a CNN. In this project, we adapt a quantitative interpretability analysing framework named Network Dissection from NetDissect to perform the identification job and verify its result by an ablation test and visual validation. Currently, our program can provide a complete and detailed semantic meaning identification for VGG16 on the datasets of PASCAL Part and COCO, and visualise the activation map of any unit inside it. However, our program is designed to be easily scaled to support other datasets and models.
Before running the program, there are two things, downloading datasets and installing dependencies, should be done.
We support two datasets, PASCAL Part and COCO, to perform the identification. Unfortunately, we do not finish the script for automatically downloading and preparing the dataset. In other words, anyone want to set up the program from scratch should:
- Download the dataset to be used on the corresponding website
- Organise the data and annotations as the requirements of the program, i.e. following the directories setting in the
src/config.py
In this project, we probe the pre-trained models instead of training new ones. The defualt examined model is VGG16, whose well-trained weights is obtained from machrisaa/tensorflow-vgg. Again, you are required to download it by yourself and put it in the correct directory with the defined name:
pre-models/vgg16/vgg16_params.npy
.
The used third-party packages are listed as below:
- opencv-python 3.4.1
- tensorflow 1.8.0
- matplotlib
- skiimage
- addict
Apart from them, the library, cocoapi
, for managing the data of COCO should be recompiled to adapt the running system environment by two steps:
cd utils/cocoapi/PythonAPI/
make
One more thing before really running the identification or other experiments is to map the data and encode the classes. After obtaining the working data mappings, other functionalities are free to be executed. By the way, Several frequently used instructions are encoded in the makefile
. So for convenience, please check the file to get the commands.
The generated mapping files describe the encoding of classes and the information of samples, which are required by the utils/helper/data_loader.py
to load the data from specific directories of dataset. The mapping operation can be simply done by running command:
make data
After mapping data, the experiments can be executed using the commands:
- Identify semantic meaning of untis:
make match
- Sensitivity analysis on activation threshold:
make activthres
- Statistical verification:
make verify
- Visualisation:
make visualise
Almost all configurations are specified in src/config.py
, so you should check the global variables defined in the file and modify the variables in response to the configurations you want to change.
The support for the new dataset or model can not be completed automatically. You need to, except downloading them, also write some codes and set up the related configurations in src/config.py
.
The instructions to add custom data include:
- download the data and set up the configurations
- remap the data to generate new mapping files
- add the functions for loading the images and parsing the corresponding annotations in a similar manner defined in
utils/helper/data_loader.py
The instructions contain:
- download the pre-trained weights data, put it in the
pre-models/
and set up the corresponding configurations - write the architecture specifications as the same style as
pre-models/vgg16/vgg16_config.py
- if the data file is not encoded in a form of
.npy
, you may also need to consider writing your own parameter loading functions.