https://github.com/modeltc/l2_compression
https://github.com/modeltc/l2_compression
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/modeltc/l2_compression
- Owner: ModelTC
- License: apache-2.0
- Created: 2023-08-07T12:48:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T13:11:09.000Z (over 1 year ago)
- Last Synced: 2025-03-20T19:16:20.257Z (11 months ago)
- Language: Python
- Size: 112 KB
- Stars: 13
- Watchers: 7
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# L^2 compression
## Introduction
Deep neural networks have delivered remarkable performance and have been widely used in various visual tasks. However, their huge size causes significant inconvenience for transmission and storage. This work proposes a unified post-training model size compression method that combines lossy and lossless compression.
## Requirements
* torch
* torchvision
* constriction
* ninja
* matplotlib
* timm
````shell
pip install -r requirements.txt
````
## Usage
### train
* change the model checkpoints paths in train/train_final
```` python
state_path = {
"resnet18": "",
"resnet50": "",
"mobilenetv2": "",
"mnasnet": "",
"regnetx_600m": "",
"regnetx_3200m": ""
}
````
* change dataset in train/train_final
````python
train_dataset = ImageNetDataset(ROOTDIR + '/train/', 'train.txt', train_transform)
test_dataset = ImageNetDataset(ROOTDIR + 'val/', METADIR + 'val.txt', val_transform)
````
* the calibration dataset we provide is train.txt in the repo
* examples are in run.sh
````shell
# example ResNet18
python -u -m train.train_final \
--model_name resnet18 \
--lambda_r 1e-6 \
--lambda_kd 1.0 \
--weight_transform edgescale \
--bias_transform scale \
--transform_iter 300 \
--transform_lr 0.0001 \
--reconstruct_iter 1000 \
--reconstruct_lr 5e-06 \
--resolution 64 \
--diffkernel cos \
--log_path ./log \
--target_CR 10.0 \
--run_name resnet_test
````
## encode and decode
refer to cal_bit.py