Home

Awesome

Filter Sketch for Network Pruning (Link).

Pruning neural network model via filter sketch.

<div align=center><img src="img/framework.jpeg" height = "50%" width = "60%"/></div>

Tips

Any problem, free to contact the authors via emails: lmbxmu@stu.xmu.edu.cn or shaojieli@stu.xmu.edu.cn. Do not post issues with github as much as possible, just in case that I could not receive the emails from github thus ignore the posted issues.

Citation

If you find FilterSketch useful in your research, please consider citing:

@article{lin2020filter,
  title={Filter Sketch for Network Pruning},
  author={Lin, Mingbao and Ji, Rongrong and Li, Shaojie and Ye, Qixiang and Tian, Yonghong and Liu, Jianzhuang and Tian, Qi},
  journal={arXiv preprint arXiv:2001.08514},
  year={2020}
}

Pre-trained Models

We provide the pre-trained models used in our paper.

CIFAR-10

| ResNet56 | ResNet110 |GoogLeNet |

ImageNet

| ResNet50 |

Result Models

We provide our pruned models in the experiments, along with their training loggers and configurations.

DataSetSketch RateFlops<br>(Prune Rate)Params<br>(Prune Rate)Top-1 AccuracyTop-5 AccuracyDownload
ResNet56CIFAR-10[0.6]*2773.36M(41.5%)0.50M(41.2%)93.19%-Link
ResNet110CIFAR-10[0.9]*3+[0.4]*24+[0.3]*24+[0.9]*392.84M(63.3%)0.69M(59.9%)93.44%-Link
GoogLeNetCIFAR-10[0.25]*90.59B(61.1%)2.61M(57.6%)94.88%-Link
ResNet50ImageNet[0.2]*160.93B(77.3%)7.18M(71.8%)69.43%89.23%Link
ResNet50ImageNet[0.4]*161.51B(63.1%)10.40M(59.2%)73.04%91.18%Link
ResNet50ImageNet[0.6]*162.23B(45.5%)14.53M(43.0%)74.68%92.17%Link
ResNet50ImageNet[0.7]*162.64B(35.5%)16.95M(33.5%)75.22%92.41%Link

Performance of FilterSketch using ResNet-56 under different compression rates.

DataSetSketch RateFlops<br>(Prune Rate)Params<br>(Prune Rate)Top-1 AccuracyDownload
CIFAR-10[0.1]*2711.43M(91.0%)0.08M(90.45%)87.38%Link
CIFAR-10[0.2]*2724.54M(80.6%)0.16M(81.0%)90.19%Link
CIFAR-10[0.3]*2735.61M(71.9%)0.25M(70.6%)91.65%Link
CIFAR-10[0.4]*2748.72M(61.5%)0.33M(61.1%)92.00%Link
CIFAR-10[0.5]*2763.78M(49.6%)0.43M(49.8%)92.29%Link
CIFAR-10[0.6]*2773.36M(41.5%)0.50M(41.2%)93.19%Link
CIFAR-10[0.7]*2787.31M(31.0%)0.59M(31.1%)93.36%Link
CIFAR-10[0.8]*2798.40M(22.3%)0.68M(20.8%)93.40%Link
CIFAR-10[0.9]*27111.5M(11.9%)0.75M(11.3%)93.44%Link
CIFAR-10[0.9]*3+[0.1]*10+[0.1]*10+[0.6]*432.47M(74.4%)0.24M(71.8%)91.20%Link
CIFAR-10[0.7]*3+[0.4]*10+[0.4]*10+[0.9]*462.63M(50.5%)0.48M(43.3%)92.94%Link
CIFAR-10[0.8]*3+[0.5]*10+[0.8]*10+[0.9]*488.05M(30.4%)0.68M(20.6%)93.65%Link

Running Code

The code has been tested using Pytorch1.3 and CUDA10.0 on Ubuntu16.04.

Filter Sketch

You can run the following code to sketch model on Cifar-10:

python sketch_cifar.py 
--data_set cifar10 
--data_path ../data/cifar10/
--sketch_model ./experiment/pretrain/resnet56.pt 
--job_dir ./experiment/resnet56/sketch/
--arch resnet 
--cfg resnet56 
--lr 0.01
--lr_decay_step 50 100
--num_epochs 150 
--gpus 0
--sketch_rate [0.6]*27
--weight_norm_method l2

You can run the following code to sketch model on Imagenet:

python sketch_imagenet.py 
--data_set imagenet 
--data_path ../data/imagenet/
--sketch_model ./experiment/pretrain/resnet50.pth 
--job_dir ./experiment/resnet50/sketch/
--arch resnet 
--cfg resnet50 
--lr 0.1
--lr_decay_step 30 60
--num_epochs 90 
--gpus 0
--sketch_rate [0.6]*16
--weight_norm_method l2

Test Our Performance

Follow the command below to verify our pruned models:

python test.py 
--data_set cifar10 
--data_path ../data/cifar10 
--arch resnet 
--cfg resnet56 
--sketch_model ./experiment/result/sketch_resnet56.pt 
--sketch_rate [0.6]*27 
--gpus 0

Get FLOPS and Params

You can use the following command to install the thop python package when you need to calculate the flops of the model:

pip install thop
python get_flops_params.py 
--data_set cifar10 
--input_image_size 32 
--arch resnet 
--cfg resnet56
--sketch_rate [0.6]*27

Remarks

The number of pruning rates required for different networks is as follows:

CIFAR-10ImageNet
ResNet5627-
ResNet11054-
GoogLeNet9-
ResNet50-16

Other Arguments

optional arguments:
  -h, --help            show this help message and exit
  --gpus GPUS [GPUS ...]
                        Select gpu_id to use. default:[0]
  --data_set DATA_SET   Select dataset to train. default:cifar10
  --data_path DATA_PATH
                        The dictionary where the input is stored.
                        default:/home/lishaojie/data/cifar10/
  --job_dir JOB_DIR     The directory where the summaries will be stored.
                        default:./experiments
  --arch ARCH           Architecture of model. default:resnet
  --cfg CFG             Detail architecuture of model. default:resnet56
  --num_epochs NUM_EPOCHS
                        The num of epochs to train. default:150
  --train_batch_size TRAIN_BATCH_SIZE
                        Batch size for training. default:128
  --eval_batch_size EVAL_BATCH_SIZE
                        Batch size for validation. default:100
  --momentum MOMENTUM   Momentum for MomentumOptimizer. default:0.9
  --lr LR               Learning rate for train. default:1e-2
  --lr_decay_step LR_DECAY_STEP [LR_DECAY_STEP ...]
                        the iterval of learn rate. default:50, 100
  --weight_decay WEIGHT_DECAY
                        The weight decay of loss. default:5e-4
  --start_conv START_CONV
                        The index of Conv to start sketch, index starts from
                        0. default:1
  --sketch_rate SKETCH_RATE
                        The proportion of each layer reserved after sketching
                        convolution layer sketch. default:None
  --sketch_model SKETCH_MODEL
                        Path to the model wait for sketch. default:None
  --weight_norm_method WEIGHT_NORM_METHOD
                        Select the weight norm method. default:None
                        Optional:l2