Source code for "transform quantization for CNN compression". Works out of the box for image classification CNNs on ImageNet.
Slight modifications are necessary to quantize other types of networks. Commands below are for resnet18py
.
-
Construct Karhunen–Loève transforms (KLTs) for convolution/dense layers.
CUDA_VISIBLE_DEVICES=X python generate_KL_basis.py inter klt resnet18py 10000
Here,10000
is the number of ILSVRC2012 validation images for non-KLT transforms. Just keep the10000
in there. -
Construct rate–distortion curves for all convolution/dense layers.
CUDA_VISIBLE_DEVICES=X python generate_RD_curves_base.py inter klt resnet18py 100
CUDA_VISIBLE_DEVICES=X python generate_RD_curves_kern.py inter klt resnet18py 100
These are separate calls to construct RD curves for transform basis and kernels. Here,100
is the number of ILSVRC2012 validation images to use. -
Compute the rate–distortion frontier for
your_network_name
.
CUDA_VISIBLE_DEVICES=X python generate_RD_frontier.py inter klt resnet18py 100 1 1 0
Here,100 1 1 0
means use100
ILSVRC2012 validation images, quantize basis1
and kernels1
, but not activations0
. -
Modifying the code to work with
your_own_cnn
instead ofresnet18py
.
Essentially, you'll need to have a notion of MSE for your network output. First, make sure dense layers inyour_own_cnn
are represented as1x1-conv
layers. Second, modifycommon.py:loadnetwork
to loadyour_own_cnn
andcommon.py:predict
to appropriately return the output of your CNN.