|
1 | 1 | # High-Fidelity Generative Image Compression
|
2 | 2 |
|
| 3 | +## PRE-RELEASE |
| 4 | + |
3 | 5 | <div align="center">
|
4 | 6 | <a href='https://hific.github.io'>
|
5 | 7 | <img src='https://hific.github.io/social/thumb.jpg' width="80%"/>
|
@@ -30,71 +32,131 @@ use more than 2× the bitrate.
|
30 | 32 | We show some images on the [demo page](https://hific.github.io) and we
|
31 | 33 | release a
|
32 | 34 | [colab](https://colab.research.google.com/github/tensorflow/compression/blob/master/models/hific/colab.ipynb)
|
33 |
| -update for interactively using our models on your own images. |
| 35 | +for interactively using our models on your own images. |
| 36 | + |
| 37 | +## Running models trained by us locally |
| 38 | + |
| 39 | +Use `tfci.py` for locally running our models to encode and decode images: |
| 40 | + |
| 41 | +```bash |
| 42 | +git clone https://github.com/tensorflow/compression |
| 43 | +cd compression/compression/models |
| 44 | +python tfci.py compress <model> <PNG file> |
| 45 | +``` |
| 46 | + |
| 47 | +where `model` can be one of `"hific-lo", "hific-mi", "hific-hi"`. |
| 48 | + |
| 49 | +**NOTE**: This is also directly available in the |
| 50 | +[colab](https://colab.research.google.com/github/tensorflow/compression/blob/master/models/hific/colab.ipynb)! |
34 | 51 |
|
35 | 52 | ## Using the code
|
36 | 53 |
|
37 |
| -In addition to `tensorflow_compression`, you need to install [`compare_gan`](https://github.com/google/compare_gan) |
38 |
| -and TensorFlow 1.15: |
| 54 | + |
| 55 | +To use the code, create a conda environment using Python 3.6 |
| 56 | +(newer is not supported at the moment), and the following packages. |
| 57 | + |
| 58 | +**NOTE**: We only support CUDA 10.0, Python 3.6, and TensorFlow 1.15. |
| 59 | +TensorFlow must be installed via pip, not conda. |
| 60 | +Any other setup is not going to work (we tested newer versions of Tensorflow |
| 61 | +and Python and they don't work). We're working on a fix. |
39 | 62 |
|
40 | 63 | ```bash
|
41 |
| -pip install -r requirements.txt |
| 64 | +conda create --name hific python=3.6 cudatoolkit=10.0 cudnn |
| 65 | +conda activate hific |
| 66 | +pip install tensorflow-gpu==1.15 # Make sure to install TF via pip, not conda! |
| 67 | +pip install git+git://github.com/google/compare_gan@19922d3004b675c1a49c4d7515c06f6f75acdcc8 |
| 68 | +pip install tensorflow-compression==1.3 |
| 69 | +pip install Pillow |
42 | 70 | ```
|
43 | 71 |
|
44 |
| -## Running our models locally |
| 72 | +#### Note on CUDNN Errors |
45 | 73 |
|
46 |
| -Use `tfci.py` for locally running our models to encode and decode images: |
| 74 | +On some of our test machines, the code crashes with one of "Could not create |
| 75 | +cudnn handle: CUDNN_STATUS_INTERNAL_ERROR", "terminate called after throwing an |
| 76 | +instance of 'std::bad_alloc'", "Segmentation fault", "Unknown: Failed to get |
| 77 | +convolution algorithm. This is probably because cuDNN". |
47 | 78 |
|
48 |
| -```python |
49 |
| -python tfci.py compress <model> <PNG file> |
| 79 | +In this case, try setting `TF_FORCE_GPU_ALLOW_GROWTH=true`, e.g.: |
| 80 | +```bash |
| 81 | +TF_FORCE_GPU_ALLOW_GROWTH=true python train.py ... |
50 | 82 | ```
|
51 | 83 |
|
52 |
| -where `model` can be one of `"hific-lo", "hific-mi", "hific-hi"`. |
| 84 | +#### Note on Memory Consumption |
53 | 85 |
|
54 |
| -## Code |
| 86 | +This model trains best on a V100. If you get out-of-memory errors |
| 87 | +("Resource exhausted: OOM"), try lowering the batch size |
| 88 | +(e.g., `--batch_size 6`), or tweak `num_residual_blocks` in `archs.py/Decoder`. |
| 89 | + |
| 90 | +If you get slow training/stalling, try tweaking the `DATASET_NUM_PARALLEL` and |
| 91 | +`DATASET_PREFETCH` constants in `model.py`. |
55 | 92 |
|
56 |
| -The architecture is defined in `arch.py` , which is used to build the model in |
57 |
| -`model.py`. Our configurations are in `configs.py`. |
58 | 93 |
|
59 | 94 | ### Training your own models.
|
60 | 95 |
|
| 96 | +The architecture is defined in `arch.py`, which is used to build the model from |
| 97 | +`model.py`. Our configurations are in `configs.py`. |
| 98 | + |
| 99 | + |
61 | 100 | We release a _simplified_ trainer in `train.py` as a starting point for custom
|
62 |
| -training. Note that it's using [LSUN]() from [tfds]() which likely needs to be |
63 |
| -adapted to a bigger dataset to obtain state-of-the-art results (see below). |
| 101 | +training. Note that it's using |
| 102 | +[coco2014](https://cocodataset.org) from |
| 103 | +[tfds](https://www.tensorflow.org/datasets/api_docs/python/tfds) which likely |
| 104 | +needs to be adapted to a bigger dataset to obtain good results |
| 105 | +(see below). |
64 | 106 |
|
65 | 107 | For the paper, we initialize our GAN models from a MSE+LPIPS checkpoint. To
|
66 | 108 | replicate this, first train a model for MSE + LPIPS only, and then use that as a
|
67 | 109 | starting point:
|
68 |
| - |
69 | 110 | ```bash
|
70 | 111 | # First train a model for MSE+LPIPS:
|
71 |
| -python train.py --config mselpips --ckpt_dir ckpts --num_steps 1M |
| 112 | +python train.py --config mselpips --ckpt_dir ckpts/mse_lpips --num_steps 1M |
| 113 | + --tfds_dataset_name coco2014 |
72 | 114 |
|
73 | 115 | # Once that finishes, train a GAN model:
|
74 |
| -python train.py --config hific --ckpt_dir ckpts \ |
75 |
| - --init_from ckpts/mselpips --num_steps 1M |
| 116 | +python train.py --config hific --ckpt_dir ckpts/hific \ |
| 117 | + --init_autoencoder_from_ckpt_dir ckpts/mselpips --num_steps 1M |
| 118 | + --tfds_dataset_name coco2014 |
76 | 119 | ```
|
| 120 | +Additional helpful arguments are `--tfds_dataset_name`, |
| 121 | +and `--tfds_download_dir`, see `--help` for more. |
77 | 122 |
|
78 |
| -To test a trained model, use `eval.py`: |
| 123 | +Note that TensorBoard summaries will be saved in `--ckpts` as well. By default, |
| 124 | +we create summaries of inputs and reconstructions, which can use a lot of |
| 125 | +memory. Disable with `--no-image-summaries`. |
| 126 | + |
| 127 | +To test a trained model, use `evaluate.py` (it also supports the `--tfds_*` |
| 128 | +flags): |
79 | 129 |
|
80 | 130 | ```bash
|
81 |
| -python eval.py --config hific --ckpt_dir ckpts/hific |
| 131 | +python evaluate.py --config hific --ckpt_dir ckpts/hific --out_dir out/ \ |
| 132 | + --tfds_dataset_name coco2014 |
82 | 133 | ```
|
83 | 134 |
|
84 | 135 | #### Adapting the dataset
|
85 | 136 |
|
86 |
| -You can change to any other TFDS dataset by changing the `tfds_name` flag for |
87 |
| -`build_input`. To train on a custom dataset, you can replace the `_get_dataset` |
| 137 | +You can change to any other TFDS dataset by adapting the `--tfds_dataset_name`, |
| 138 | +`--tfds_feature_key`, and `--tfds_download_dir` flags of `train.py`. |
| 139 | + |
| 140 | +Note that when using TFDS, the dataset first has to be downloaded, which can |
| 141 | +take time. To do this separately, use the following code snippet: |
| 142 | +```python |
| 143 | +import tensorflow_datasets as tfds |
| 144 | +builder = tfds.builder(TFDS_DATASET_NAME, data_dir=TFDS_DOWNLOAD_DIR) |
| 145 | +builder.download_and_prepare() |
| 146 | +``` |
| 147 | + |
| 148 | +To train on a custom dataset, you can replace the `_get_dataset` |
88 | 149 | call in `train.py`.
|
89 | 150 |
|
90 | 151 | ## Citation
|
91 | 152 |
|
92 | 153 | If you use the work released here for your research, please cite this paper:
|
93 | 154 |
|
94 | 155 | ```
|
95 |
| -@inproceedings{mentzer2020hific, |
| 156 | +@article{mentzer2020high, |
96 | 157 | title={High-Fidelity Generative Image Compression},
|
97 |
| - author={Fabian Mentzer and George Toderici and Michael Tschannen and Eirikur Agustsson}, |
| 158 | + author={Mentzer, Fabian and Toderici, George and Tschannen, Michael and Agustsson, Eirikur}, |
| 159 | + journal={arXiv preprint arXiv:2006.09965}, |
98 | 160 | year={2020}
|
99 | 161 | }
|
100 | 162 | ```
|
|
0 commit comments