-
Training MobileNet on CIFAR-10.
Training:
python train.py data/ --dir models/mobilenet/model.pth.tar --arch mobilenet
Evaluation:
python eval.py data/ --dir models/mobilenet/model.pth.tar --arch mobilenet
One trained model can be found here.
-
Measuring Latency
Here we build the latency lookup table for
cuda:0
device:python build_lookup_table.py --dir latency_lut/lut_mobilenet.pkl --arch mobilenet
It measures latency of different layers contained in the network (i.e. MobileNet here). For conv layers, the sampled numbers of feature channels are multiples of
MIN_CONV_FEATURE_SIZE
. For fc layers, the sampled numbers of features are multiples ofMIN_FC_FEATURE_SIZE
. -
Applying NetAdapt
Modify which GPUs will be utilized (
-gp
) innetadapt_mobilenet-0.5mac.sh
and run the script to apply NetAdapt to a pretrained model:sh scripts/netadapt_mobilenet-0.5mac.sh
You can see how the model is simplified at each iteration in
models/mobilenet/prune-by-mac/master/history.txt
and select the one that satisfies the constraints to run long-term fine-tune.After obtaining the adapted model, we need to finetune the model (here we select the one after 28 iterations):
python train.py data/ --arch mobilenet --resume models/mobilenet/prune-by-mac/master/iter_28_best_model.pth.tar --dir models/mobilenet/prune-by-mac/master/finetune_model.pth.tar --lr 0.001
If you want to get a model with 50% latency, please run:
sh scripts/netadapt_mobilenet-0.5latency.sh
-
Evaluation Using Adapted Models
After applying NetAdapt to a pretrained model, we can evaluate this adapted model using:
python eval.py data/ --dir models/mobilenet/prune-by-mac/master/finetune_model.pth.tar --arch mobilenet
The adapted model can be restored without modifying the orignal python file.
We provide one adapted model here.