|
| 1 | +# Universal Deep Image Compression via Content-Adaptive Optimization with Adapters |
| 2 | +Official implementation of "Universal Deep Image Compression via Content-Adaptive Optimization with Adapters" presented at WACV 23. |
| 3 | + |
| 4 | +## Environment |
| 5 | +Use Miniconda. |
| 6 | + |
| 7 | +```bash |
| 8 | +# python=3.8, 3.9, or 3.10 should be fine. |
| 9 | +conda create -n aof python=3.7 |
| 10 | +conda activate aof |
| 11 | +# install 7z for [Lam+, ACM MM 20] |
| 12 | +conda install -c bioconda p7zip |
| 13 | +pip install -r requirements.txt |
| 14 | +``` |
| 15 | + |
| 16 | +## Preparation |
| 17 | +### Dataset |
| 18 | +Prepare a dataset that consists of four domains: natural images, line drawings, comics, and vector arts. |
| 19 | + |
| 20 | +```bash |
| 21 | +# In 2022/08/31, four files have missing links. |
| 22 | +# the four files: (`156526161`, `99117125`, `15642096`, `158633139`) |
| 23 | +python scripts/download_dataset.py |
| 24 | +``` |
| 25 | + |
| 26 | +### Pre-trained Weights |
| 27 | +Prepare the weights of WACNN pre-trained on natural images. |
| 28 | + |
| 29 | +Note: we cannot provide the `weights.zip` due to the storage limit. |
| 30 | + |
| 31 | +```bash |
| 32 | +unzip weights.zip |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | +### Training of the Proposed Method |
| 37 | +Apply the demo code (`main.py`) to a dataset by running a script. |
| 38 | +Please specify `["vector", "natural", "line", "comic"]` as a dataset and `[1, 2, 3, 4, 5, 6]` as quality. |
| 39 | + |
| 40 | +```bash |
| 41 | +python run_main.py vector --out results/ours --quality 1 |
| 42 | +``` |
| 43 | + |
| 44 | +The refined latent representation is encoded and saved in `cache/`. |
| 45 | +The parameters of the adapters are encoded and saved in `results/ours/wacnn/q1/<image file name>/weights.pt`. |
| 46 | + |
| 47 | +### Evaluation of the Proposed Method |
| 48 | +Perform evaluation using the compressed data obtained in training with the command below. |
| 49 | +Please specify `--domain` from `["vector", "natural", "line", "comic"]`. The default is `"vector"`. |
| 50 | + |
| 51 | +```bash |
| 52 | +# Without adaptation |
| 53 | +python decode.py --stage 0th # --domain vector |
| 54 | +# Without adapters (= only refining the latent representation = [Yang+, NeurIPS 20]) |
| 55 | +python decode.py --stage 1st # --domain vector |
| 56 | +# Ours |
| 57 | +python decode.py --stage 2nd # --domain vector |
| 58 | +``` |
| 59 | + |
| 60 | +You can finally obtain the results in the csv format in `results/ours/wacnn/q{1,2,3,4,5,6}/<dataset name>_{0th,1st,2nd}.csv`. |
| 61 | + |
| 62 | +### Comparison with Other Adaptive Methods |
| 63 | +Run other adaptive methods in our framework. |
| 64 | + |
| 65 | +```bash |
| 66 | +# [Lam+, ACM MM 20] |
| 67 | +python run_main.py vector --out results/lam-mm20 --regex "'g_s\..*\.bias'" --n-dim 0 --width 0.0 --data_type float32 --quality 1 |
| 68 | +python decode.py --weight_root results/lam-mm20 --n-dim-2 0 --width 0.0 --regex "g_s\..*\.bias" --data_type float64+7z |
| 69 | + |
| 70 | +# [Rozendaal+, ICLR 21] |
| 71 | +python run_main.py vector --out results/rozendaal-iclr21 --regex "'.*'" --n-dim 0 --width 0.005 --alpha 1000 --sigma 0.05 --distrib spike-and-slab --lr 3e-5 --opt-enc --quality 1 |
| 72 | +python decode.py --weight_root results/rozendaal-iclr21 --rozendaal |
| 73 | + |
| 74 | +# [Zou+, ISM 21] |
| 75 | +python run_main.py vector --out results/zou-ism21 --n-dim -1 --groups 192 --width 0.0 --quality 1 |
| 76 | +python decode.py --weight_root results/zou-ism21 --n-dim-2 -1 --groups 192 --width 0.0 |
| 77 | +``` |
| 78 | + |
| 79 | +You can compare these methods with the baseline and proposed methods using the command below. |
| 80 | + |
| 81 | +```bash |
| 82 | +python plot_rdcurve.py |
| 83 | +``` |
| 84 | + |
| 85 | +### Ablation Studies |
| 86 | +(Optional) Perform ablation studies. |
| 87 | + |
| 88 | +* Optimization only in terms of distortion |
| 89 | +```bash |
| 90 | +# Distortion opt. |
| 91 | +python run_main.py vector --out results-abl/ours-dopt --width 0.0 --quality 1 |
| 92 | +python decode.py --weight_root results-abl/ours-dopt --width 0.0 |
| 93 | +``` |
| 94 | + |
| 95 | +* Optimization of other parameters |
| 96 | + |
| 97 | +```bash |
| 98 | +# Biases |
| 99 | +python run_main.py vector --out results-abl/ours-bias --regex "'g_s\..*\.bias'" --n-dim 0 --lr_2 1e-5 --quality 1 |
| 100 | +python decode.py --weight_root results-abl/ours-bias --regex "'g_s\..*\.bias'" --n-dim-2 0 |
| 101 | +# OMPs |
| 102 | +python run_main.py vector --out results-abl/ours-omp --distrib logistic --n-dim -1 --groups 192 --quality 1 |
| 103 | +python decode.py --weight_root results-abl/ours-omp --n-dim-2 -1 --groups 192 |
| 104 | +``` |
| 105 | + |
| 106 | +* Optimization Order |
| 107 | + |
| 108 | +```bash |
| 109 | +python run_main.py vector --out results-abl/ours-swap --swap --quality 1 |
| 110 | +python decode.py --weight_root results-abl/ours-swap --swap |
| 111 | +``` |
| 112 | + |
| 113 | +* Another Base Network Architecture |
| 114 | + |
| 115 | +```bash |
| 116 | +# Cheng20 |
| 117 | +python run_main.py vector --out results/ours --model cheng2020-attn --regex "'g_s\.[8-8]\.adapter_1.*'" --quality 1 |
| 118 | +python decode.py --model cheng2020-attn --n-dim-1 2 --n-dim-2 0 |
| 119 | +``` |
| 120 | + |
| 121 | +## Contact |
| 122 | +Feel free to contact me if there is any question: tsubota (a) hal.t.u-tokyo.ac.jp |
| 123 | + |
| 124 | +## License |
| 125 | +This code is licensed under MIT (if not specified in the code). |
| 126 | + |
| 127 | +The code contains modified and copied open source code. |
| 128 | +Thus, I describe the original license of the code. |
| 129 | +Please let me know if there is a license issue with code redistribution. |
| 130 | +If so, I will remove the code and provide the instructions to reproduce the work. |
| 131 | + |
| 132 | +As for the dataset, I do not have any right and provide only URLs. |
| 133 | +Please refer to the original datasets (Kodak and BAM) for the detailed license of the images. |
| 134 | +When the link of some URLs is missing, I will redistribute the corresponding images if they are licensed under Creative Commons. |
0 commit comments