This repository includes the code and experimental data in our paper entitled "Patching Weak Convolutional Neural Network Models through Modularization and Composition".
In this paper, we propose a structured modularization approach, CNNSplitter, which decomposes a strong CNN model for
- python 3.8.10
- pytorch 1.8.1
- numpy 1.19.2
- tqdm 4.61.0
- matplotlib 3.4.2
- seaborn 0.11.1
- GPU with CUDA support is also needed
Install the dependent packages via pip:
$ pip install numpy==1.19.2 tqdm==4.61.0 matplotlib==3.4.2 seaborn==0.11.1
Install pytorch according to your environment, see https://pytorch.org/.
- modify
global_configure.py
to set theroot_dir
. - run
python train.py --model simcnn --dataset cifar10
to get the pre-trained modelSimCNN-CIFAR
. - run
python kernel_importance_analyzer.py --model simcnn --dataset cifar10
in directorypreprocess/
to get the importance of each kernel inSimCNN-CIFAR
. - run
python run_layer_sensitivity_analyzer.py --model simcnn --dataset cifar10
in directoryscripts/
to analyze the sensitivity ofSimCNN-CIFAR
. - modify
configures/simcnn_cifar10.py
to set the configures of GA searching. - run
python module_recorder.py --model simcnn --dataset cifar10
. - run
python module_explorer.py --model simcnn --dataset cifar10 --target_class 0
with 10 instances in parallel (--target_class
from 0 to 9), each of which searches for one class.
We provide the four trained CNN models and the corresponding modules, as well as the weak models.
One can download data/
from here and reuse a module to patch a weak CNN model following the description below.
- run
python module_output_collector.py --model simcnn --dataset cifar10
in directorypreprocess/
to collect the outputs of 10 modules.
- run
python train.py --model simcnn --dataset cifar10
in directoryexperiments/patch/patch_for_weak_model
to train an overly simple SimCNN-CIFAR. - run
python apply_patch.py --model simcnn --dataset cifar10 --exp_type weak --target_class 0 --target_epoch 99
in directoryexperiments/patch
to patch the simple SimCNN-CIFAR.
- run
python train.py --model simcnn --dataset cifar10
in directoryexperiments/patch/patch_for_poor_model
to train an overfitting/underfitting SimCNN-CIFAR. - run
python apply_patch.py --model simcnn --dataset cifar10 --exp_type poor_fit --target_class 0 --target_epoch 169
in directoryexperiments/patch
to patch the overfitting SimCNN-CIFAR. - run
python apply_patch.py --model simcnn --dataset cifar10 --exp_type poor_fit --target_class 0 --target_epoch 84
in directoryexperiments/patch
to patch the underfitting SimCNN-CIFAR.