cnn-compression-master
所属分类:图形图像处理
开发工具:Python
文件大小:4751KB
下载次数:2
上传日期:2020-11-23 15:57:48
上 传 者:
甜汤拌饭
说明: compression压缩感知算法用于图像处理。信号压缩
(compressionCompressed sensing algorithm)
文件列表:
FALCON2 (0, 2020-11-16)
FALCON2\requirements.txt (110, 2020-11-16)
FALCON2\script (0, 2020-11-16)
FALCON2\script\imagenet_vgg_test.sh (1226, 2020-11-16)
FALCON2\script\imagenet_vgg_train.sh (1272, 2020-11-16)
FALCON2\script\inference.sh (1176, 2020-11-16)
FALCON2\script\train.sh (1183, 2020-11-16)
FALCON2\src (0, 2020-11-16)
FALCON2\src\imagenetutils (0, 2020-11-16)
FALCON2\src\imagenetutils\__init__.py (319, 2020-11-16)
FALCON2\src\imagenetutils\dataloaders.py (10774, 2020-11-16)
FALCON2\src\imagenetutils\eval.py (808, 2020-11-16)
FALCON2\src\imagenetutils\logger.py (3876, 2020-11-16)
FALCON2\src\imagenetutils\misc.py (2283, 2020-11-16)
FALCON2\src\imagenetutils\visualize.py (3879, 2020-11-16)
FALCON2\src\models (0, 2020-11-16)
FALCON2\src\models\falcon.py (9475, 2020-11-16)
FALCON2\src\models\model_imageNet.py (12589, 2020-11-16)
FALCON2\src\models\resnet.py (9919, 2020-11-16)
FALCON2\src\models\stconv_branch.py (14877, 2020-11-16)
FALCON2\src\models\vgg.py (4684, 2020-11-16)
FALCON2\src\train_test (0, 2020-11-16)
FALCON2\src\train_test\imagenet.py (25320, 2020-11-16)
FALCON2\src\train_test\main.py (8387, 2020-11-16)
FALCON2\src\train_test\test.py (2310, 2020-11-16)
FALCON2\src\train_test\train.py (5432, 2020-11-16)
FALCON2\src\train_test\trained_model (0, 2020-11-16)
FALCON2\src\train_test\trained_model\conv=FALCON,model=ResNet,data=cifar100,rank=1,alpha=0.77,init,opt=SGD,lr=0.1.pkl (5319454, 2020-11-16)
FALCON2\src\train_test\validation.py (2131, 2020-11-16)
FALCON2\src\utils (0, 2020-11-16)
FALCON2\src\utils\compression_cal.py (5365, 2020-11-16)
FALCON2\src\utils\default_param.py (5291, 2020-11-16)
FALCON2\src\utils\load_data.py (6807, 2020-11-16)
FALCON2\src\utils\lr_decay.py (1306, 2020-11-16)
FALCON2\src\utils\optimizer_option.py (2401, 2020-11-16)
FALCON2\src\utils\save_restore.py (9455, 2020-11-16)
FALCON2\src\utils\timer.py (1787, 2020-11-16)
... ...
FALCON: Lightweight and Accurate Convolution
===
This package provides implementations of FALCON/FALCONBranch convolution with their corresponding CNN model.
## Overview
#### Code structure
``` unicode
FALCON
│
├── src
│ │
│ ├── models
│ │ ├── vgg.py: VGG model
│ │ ├── resnet.py: ResNet model
│ │ ├── model_imagenet.py: Pretrained model (from pytorch)
│ │ ├── falcon.py: FALCON
│ │ └── stconv_branch.py: StConvBranch & FALCONBranch
│ │
│ ├── train_test
│ │ ├── imagenet.py: train/validate on ImageNet
│ │ ├── main.py: train/test on CIFAR10/CIFAR100/SVHN
│ │ ├── train.py: training process
│ │ ├── test.py: testing process
│ │ └── validation.py: validation process
│ ├── imagenetutils: this code are from https://github.com/d-li14/mobilenetv2.pytorch
│ │ ├── dataloaders.py: dataloader for ImageNet
│ │ ├── eval.py: evaluate function for ImageNet
│ │ ├── logger.py: logger functions
│ │ ├── misc.py: helper function
│ │ └── visualize.py: visualization functions
│ │
│ └── utils
│ ├── compression_cal.py: calculate the number of parameters and FLOPs
│ ├── default_param.py: default cfgs
│ ├── load_data.py: load datasets
│ ├── lr_decay.py: control learning rate
│ ├── optimizer_option.py: choose optimizer
│ ├── save_restore.py: save and restore trained model
│ └── timer.py: timer for inference time
│
└── script: shell scripts for execution of training/testing codes
```
#### Naming convention
**StandardConv**: Standard Convolution (baseline)
**FALCON**: Lightweight and Accurate Convolution - the new convolution architecture we proposed
**Rank**: Rank of convolution. Copy the conv layer for k times, run independently and add output together at the end of the layer. This hyperparameter helps balace compression rate/ accelerate rate and accuracy.
**FALCON-branch**: New version of FALCON - for fitting FALCON into ShuffleUnitV2 architecture.
#### Data description
* CIFAR-100 datasets
* SVHN
* ImageNet
* Note that:
* CIFAR and SVHN datasets depend on torchvision (https://pytorch.org/docs/stable/torchvision/datasets.html#cifar). You don't have to download anything. When executing the source code, the datasets will be automaticly downloaded if it is not detected.
* ImageNet is downloaded from http://www.image-net.org/challenges/LSVRC/
#### Output
* For CIFAR datasets, the trained model will be saved in `train_test/trained_model/` after training.
* For ImageNet, the checkpoint will be saved in `train_test/checkpoint`
* You can test the model only if there is a trained model in `train_test/trained_model/`.
## Install
#### Environment
* Unbuntu
* CUDA 10.1
* Python 3.6
* torch
* torchvision
* [DALI (NVIDIA Data Loading Library)](https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html)
#### Dependence Install
pip install torch torchvision
## How to use
### CIFAR100/SVHN
#### Training & Testing
* To train the model on CIFAR-100/SVHN datasets, run script:
```
cd src/train_test
python main.py -train -conv StandardConv -m VGG19 -data cifar100
python main.py -train -conv FALCON -m VGG19 -data cifar100 -init
```
The trained model will be saved in `src/train_test/trained_model/`
* To test the model, run script:
```
cd src/train_test
python main.py -conv StandardConv -m VGG19 -data cifar100
python main.py -conv FALCON -m VGG19 -data cifar100 -init
```
The testing accuracy, inference time, number of parameters and number of FLOPs will be printed on the screen.
* Pre-trained model is saved in `src/train_test/trained_model/`
* For example:
* Standard model:
conv=StandardConv,model=VGG19,data=cifar100,rank=1,alpha=1,opt=SGD,lr=0.1.pkl
* FALCON model:
conv=FALCON,model=VGG19,data=cifar100,rank=1,alpha=1,init,opt=SGD,lr=0.1.pkl
#### DEMO
* There are two demo scripts: `script/train.sh` and `script/inference.sh`.
* You can change arguments in `.sh` files to train/test different model.
* `train.sh`: Execute training process of the model
* Accuracy/ loss/ training time for 100 iteration will be printed on the screen during training.
* Accuracy/ inference time/ number of parameters/ number of FLOPs will be printed on the screen after training.
* `inference.sh`: Execute inference process of the model
* Accuracy/ inference time/ number of parameters/ number of FLOPs will be printed on the screen.
* You can run this file only when the trained model exist.
* Sample trained model is provided in `src/train_test/trained_model/`.
### ImageNet
#### Training & Testing
* To train the model on ImageNet dataset, run script:
```
python imagenet.py \
-a
\
-conv \
-b \
-init \
-c \
--pretrained \
--epochs \
--lr-decay \
--lr \
data directory
```
The trained model will be saved in `src/checkpoint directory/`
Note: dataloader function is implemented based on DALI library; hence, you install DALI library before training a model with ImageNet dataset. Our dataloader function is from https://github.com/d-li14/mobilenetv2.pytorch
* To test the modelon ImageNet dataset, run script:
```
python imagenet.py \
-a \
-e \
-conv \
-b \
-init \
--resume \
data directory
```
The testing accuracy, inference time, number of parameters and number of FLOPs will be printed on the screen.
* Pre-trained model is saved in `src/checkpoint directory/` for ImageNet dataset
* For example:
* FALCON model:
checkpoints/model_best.pth.tar
#### DEMO
* There are four demo scripts: `script/train.sh`, `script/inference.sh`, `script/imagenet_vgg_train.sh`, and `script/imagenet_vgg_test.sh`.
* You can change arguments in `.sh` files to train/test different model.
* `imagenet_vgg_train.sh`: Execute training process of vgg model for ImageNet
* `imagenet_vgg_test.sh`: Execute inference process of vgg model for ImageNet
* Sample trained model is provided in `src/checkpoints/`.
## License
Licensed under the Apache License, Version 2.0
近期下载者:
相关文件:
收藏者: