{"id":28276319,"url":"https://github.com/fl0wbar/frllic","last_synced_at":"2026-05-02T03:05:42.060Z","repository":{"id":240446147,"uuid":"521316338","full_name":"fl0wbar/FRLLIC","owner":"fl0wbar","description":"Experiment applying L3C (CVPR2019) for image compression on CLIC-2019 dataset","archived":false,"fork":false,"pushed_at":"2022-08-04T15:27:36.000Z","size":3495,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-16T16:43:16.434Z","etag":null,"topics":["arithmetic-coding","clic2019","compression","image-compression","learned-image-compression","pytorch","torchac"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fl0wbar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-04T15:19:33.000Z","updated_at":"2023-07-04T12:54:30.000Z","dependencies_parsed_at":"2024-05-18T23:28:49.308Z","dependency_job_id":"2b9527a0-3c9e-45ef-a91e-8c61b22b52bb","html_url":"https://github.com/fl0wbar/FRLLIC","commit_stats":null,"previous_names":["fl0wbar/frllic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fl0wbar/FRLLIC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fl0wbar%2FFRLLIC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fl0wbar%2FFRLLIC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fl0wbar%2FFRLLIC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fl0wbar%2FFRLLIC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fl0wbar","download_url":"https://codeload.github.com/fl0wbar/FRLLIC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fl0wbar%2FFRLLIC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32521113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic-coding","clic2019","compression","image-compression","learned-image-compression","pytorch","torchac"],"created_at":"2025-05-21T05:10:21.988Z","updated_at":"2026-05-02T03:05:42.032Z","avatar_url":"https://github.com/fl0wbar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## FRLLIC (Full Resolution Learned Lossless Image Compression)\n\n#### Experiments done in February 2019\n\n#### Project repository for testing and understanding L3C on CLIC2019 image dataset.\n\n#### Original README below.\n\nPlease refer to new and updated [L3C](https://github.com/fab-jul/L3C-PyTorch) for new preprocessing scripts solving certain issues.\n\nThis repo is a public backup of a hobby project.\n\n### CLIC Dataset\n\n#### Preparing CLIC for Training\n```bash\n$ ./prep_clic.sh ./data\n```\n\n#### Training\n```bash\n$ python train.py configs/ms/cr.cf configs/dl/clic.cf FRLLIC_logdir\n```\n- Extra arguments can be passed using -p (global_config.py)\n```bash\n$ python train.py configs/ms/cr.cf configs/dl/clic.cf FRLLIC_logdir -p upsampling=deconv\n```\n- For using pretrained model / restoring training\n```bash\n$ python train.py configs/ms/cr.cf configs/dl/clic.cf FRLLIC_logdir --restore 0502_1213 --restore_restart\n```\n#### Testing\n```bash\n$ python test.py FRLLIC_logdir 0502_1213 data/CLIC/test\n```\n\n#### Sampling\n```bash\n$ python test.py FRLLIC_logdir 0524_0001 data/CLIC/test --sample=samples\n```\n\n#### Encoding\n\n- Encode to out.l3c\n```bash\n$ python l3c.py FRLLIC_logdir 0524_0001 enc /path/to/img out.l3c\n```\n```bash\n$ python l3c.py FRLLIC_logdir 0624_2025 enc ./fixedimg256.png out.l3c\n```\n- Decode from out.l3c, save to decoded.png\n```bash\n$ python l3c.py FRLLIC_logdir 0524_0001 dec out.l3c decoded.png\n```\n```bash\n$ python l3c.py FRLLIC_logdir 0624_2025 dec out.l3c decoded.png\n```\n\n\n## Acknowledgment\nThanks to [L3C](https://github.com/fab-jul/L3C-PyTorch) for implementations of EDSR, logistic mixtures, and arithmetic coding (torchac) and dataset preprocessing scripts.\n\n# Practical Full Resolution Learned Lossless Image Compression\n\n\n### Fabian Mentzer, Eirikur Agustsson, Michael Tschannen, Radu Timofte, Luc Van Gool\nETH Zurich\n\n_CVPR'19 (oral presentation)_\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src='figs/teaser.png' width=\"50%\"/\u003e\n\u003c/div\u003e\n\n\n## [[Paper]](https://arxiv.org/abs/1811.12817) [[Citation]](#citation) [[Oral]](#oral) [[Poster]](#poster) [[FAQ]](#faq)\n\n### Abstract\n\nWe propose the first practical learned lossless image compression system, L3C, and show that it outperforms the\npopular engineered codecs, PNG, WebP and JPEG 2000.\nAt the core of our method is a fully parallelizable hierarchical probabilistic model for adaptive entropy coding which is optimized end-to-end for the compression task.\nIn contrast to recent autoregressive discrete probabilistic models such as PixelCNN, our method i) models the image distribution jointly with learned auxiliary representations instead of exclusively modeling the image distribution in RGB space, and ii) only requires three forward-passes to predict all pixel probabilities instead of one for each pixel.\nAs a result, L3C obtains over two orders of magnitude speedups when sampling compared to the fastest PixelCNN variant (Multiscale-PixelCNN).\nFurthermore, we find that learning the auxiliary representation is crucial and outperforms predefined auxiliary representations such as an RGB pyramid significantly.\n\n\n## Version 3\n\nThis is an updated version of the repo. See issue [#14](https://github.com/fab-jul/L3C-PyTorch/issues/14) for details.\n\n\n## Prerequisites for Code\n\nClone the repo and create a conda environment as follows:\n\n```\nconda create --name l3c_env python=3.7 pip --yes\nconda activate l3c_env\n```\n\nWe need PyTorch 1.1, CUDA, and some PIP packages (If you don't have a GPU, remove `cudatoolkit=10.0`):\n\n```\nconda install pytorch=1.1 torchvision cudatoolkit=10.0 -c pytorch\npip install -r pip_requirements.txt\n```\n\nTo test our entropy coding, **you must also install torchac**, as [described below](#the-torchac-module-fast-entropy-coding-in-pytorch).\n\n##### Notes\n- We tested this code with Python 3.7 and PyTorch 1.1. PyTorch 1.2 is _not supported_, but progress is tracked in [#5](https://github.com/fab-jul/L3C-PyTorch/issues/5).\n- The training code also works with PyTorch 0.4, but for testing, we use the `torchac` module, which\nneeds PyTorch 1.0 or newer to build, [see below](#the-torchac-module-fast-entropy-coding-in-pytorch).\n- The code relies on `tensorboardX==1.2`, even though TensorBoard is now part of PyTorch (since 1.1)\n\n## Released Models\n\nWe release the following trained models:\n\n\n|     | Name | Training Set | ID  | Download Model |\n| --- | ---- | ------------ | --- | --------- |\n| Main Model | L3C | [Open Images](#prepare-open-images-for-training) | `0306_0001` | [L3C.tar.gz](http://data.vision.ee.ethz.ch/mentzerf/l3c_models_v3/L3C.tar.gz) |\n| Baseline | RGB Shared | Open Images | `0306_0002` | [RGB_Shared.tar.gz](http://data.vision.ee.ethz.ch/mentzerf/l3c_models_v3/RGB_Shared.tar.gz) |\n| Baseline | RGB | Open Images | `0306_0003` | [RGB.tar.gz](http://data.vision.ee.ethz.ch/mentzerf/l3c_models_v3/RGB.tar.gz) |\n| Main Model | L3C | [ImageNet32](http://image-net.org/download-images)    | `0524_0004` | [L3C_inet32.tar.gz](http://data.vision.ee.ethz.ch/mentzerf/l3c_models/L3C_inet32.tar.gz) |\n| Main Model | L3C | [ImageNet64](http://image-net.org/download-images)    | `0524_0005` | [L3C_inet64.tar.gz](http://data.vision.ee.ethz.ch/mentzerf/l3c_models/L3C_inet64.tar.gz) |\n\nSee [Evaluation of Models](#evaluation) to learn how to evaluate on a dataset.\n\n### Training\n\nTo train a model yourself,\nyou have to first prepare the data as shown in [Prepare Open Images Train](#prepare-open-images-for-training).\nThen, use one of the following commands, [explained in more detail below](#experiments):\n\n| Model | Train with the following flags to `train.py`|\n| --- | --- |\n| L3C               | `configs/ms/cr.cf configs/dl/oi.cf log_dir` |\n| RGB Shared        | `configs/ms/cr_rgb_shared.cf configs/dl/oi.cf log_dir` |\n| RGB               | `configs/ms/cr_rgb.cf configs/dl/oi.cf log_dir` |\n| L3C ImageNet32    | `configs/ms/cr.cf configs/dl/in32.cf -p lr.schedule=exp_0.75_e1 log_dir` |\n| L3C ImageNet64    | `configs/ms/cr.cf configs/dl/in64.cf -p lr.schedule=exp_0.75_e1 log_dir` |\n\nEach of the released models were trained for around 5 days on a Titan Xp.\n\n*Note*: We do not provide code for multi-GPU training. To incorporate `nn.DataParallel`, the code must be changed\nslightly: In `net.py`, `EncOut` and `DecOut` are `namedtuple`s, which is not supported by `nn.DataParallel`.\n\n### Evaluation\n\nTo test an [experiment](#experiments), use `test.py`. For example, to test L3C and the baselines, run\n\n```\npython test.py /path/to/logdir 0306_0001,0306_0002,0306_0003 /some/imgdir,/some/other/imgdir \\\n    --names \"L3C,RGB Shared,RGB\" --recursive=auto\n```\n\nFor this, you need to download the models to some directory, in the example this is `/path/to/logdir`.\n\nTo use the entropy coder and get timings for encoding/decoding, use `--write_to_files` (this needs `torchac`,\n[see below](#the-torchac-module-fast-entropy-coding-in-pytorch). If you did not compile `torchac` with CUDA support,\ndisable CUDA by running `CUDA_VISIBLE_DEVICES=\"\" python test.py ...`):\n\n```\npython test.py /path/to/logdir 0306_0001 /some/imgdir --write_to_files=files_out_dir\n```\n\nMore flags available with `python test.py -h`.\n\n#### Evaluation on Open Images\n\nWe evaluated our model on 500 images randomly selected from the Open Images validation set, and preprocessed like the\ntraining data. To compare, please\n[download Open Images evaluation set here](http://data.vision.ee.ethz.ch/mentzerf/validation_sets_lossless/val_oi_500_r.tar.gz).\n\n#### Adaptive Cropping\n\nThe evaluation code automatically split images that are too big into non-overlapping crops. By default,\nthe threshold is set to images bigger than `2000 * 1500` pixels in total. This can be overwritten by\nsetting `AC_NEEDS_CROP_DIM` from the console, e.g.,\n\n```\nAC_NEEDS_CROP_DIM=2000,2000 python test.py ...\n```\n\nSee `auto_crop.py` for details.\n\n\n\u003c!--\n### Results\n\nWhen preparing this repo, we found that removing one approximation in the loss originally introduced by the PixelCNN++\n code slightly improved the final bitrates of L3C, while performance of the baselines got slightly worse.\n\n\nThe code contains the loss without the approximation.\nWe note that [arXiv v2](https://arxiv.org/abs/1811.12817v2) is the same as CVPR Camera Ready version, and the results in there where obtained\nwith the approximation.\n\nHowever, if you re-train with the provided code, you'll get the new results.\nFor clarity, we compare the new results as obtained by the **released code**, with the results in the **Camera Ready**:\n\n| Model | Released [bpsp OI] | Camera Ready [bpsp OI] |\n| ----- | ------------- | ----------------- |\n| L3C   | 2.578         | 2.604 |\n| RGB Shared | 2.948    | 2.918 |\n| RGB   | 2.832         | 2.819 |\n\nHere, _bpsp OI_ means bit per sub-pixel on Open Images Test.\n\nWe did not re-train the ImageNet32 and ImageNet64 models.\n--\u003e\n\n## Oral\n\n### [[Oral on Youtube]](https://youtu.be/PzALQZOy09c?t=63) [[Download Oral Slides]](http://data.vision.ee.ethz.ch/mentzerf/l3c_pdfs/l3c_oral_slides.pdf)\n\n## Poster\n\n### [[Download Poster PDF]](http://data.vision.ee.ethz.ch/mentzerf/l3c_pdfs/l3c_poster.pdf)\n\n## FAQ\n\nDuring the CVPR Poster session, the following where the most frequently asked questions:\n\n#### How can I learn a _lossless_ model with CNNs?\n\nFirst of all, to do lossless compression, you just need to know a probability distribution over your symbols. This is visualized in the bottom left of the poster. Given such a distribution, you can do entropy coding, for example [Huffman Coding](https://en.wikipedia.org/wiki/Huffman_coding).\n\nFor natural images, we use the pixels of an image as the stream of symbols. Because they are not independent, we model the joint `p tilde (x_1, ..., x_N)` (see bottom left of poster).\n\nNow, what Fig. 1 in the paper and the figure in the middle of the poster show is how we learn this p tilde. **The important thing to realize** is that the output of our model is p tilde, _it is not a quantized autoencoder_. Given this p tilde, we can do entropy coding. It doesn't matter that we have quantization in the network: no matter how bad p tilde is,\nyou can always do lossless compression -- you might just use a lot of bits!\n\nNote that the model we learn (shown in Fig. 1), is used to get p tilde. We then use this to do entropy coding, as visualized on the top right of the poster or Fig. A4 in the paper.\n\n#### What does Adapative Arithmetic Coding mean?\n\nI'll explain this via [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding), as more people are familiar with that. In the default lossless compression case, we assume the symbols in our stream (\"message\") are all independent and identically distributed (i.i.d) according to p. We create one Huffman table for all symbols. Consider now the fruit in the bottom left of the poster. Imagine that they are not independent, but that e.g. apples are more likely to appear after bananas. In these cases, it makes sense to have different Huffman tables for different positions in the stream. We would call that \"adaptive\" Huffman coding. The table at some point in the stream would depend on the _conditional distribution of that symbol_.\n\nAdaptive Arithmetic coding is the same thing, except that we generalize [Arithmetic coding](https://en.wikipedia.org/wiki/Arithmetic_coding) to the non-i.i.d. case.\n\nThis is also described in the Paper, in Section 3.1.\n\n#### Other questions?\n\nFeel free to write an email to us (E-Mail in paper) or open an issue here.\n\n\n## Details about Code\n\n### Experiments\n\nWhenever `train.py` is executed, a new _experiment_ is started.\nEvery experiment is based on a specific configuration file for the network, stored in _configs/ms_ and\nanother file for the dataloading, stored in _configs/dl_.\nAn experiment is uniquely identified by the **log date**, which is just date and time (e.g. `0506_1107`).\nThe config files are parsed with the [parser from `fjcommon`](https://github.com/fab-jul/fjcommon#configparserpy),\nwhich allows hiararchies of configs.\nAdditionally, there is `global_config.py`, to allow quick changes by passing\n additional parameters via the `-p` flag, which are then available _everywhere_ in the code, see below.\n The config files plus the `global_config` flags specify _all_ parameters needed to train a network.\n\nWhen an experiment is started, a directory with all this information is created in the folder passed as\n`LOG_DIR_ROOT` to `train.py` (see `python train.py -h`).\n\nFor example, running\n\n```bash\npython train.py configs/ms/cr.cf configs/dl/oi.cf log_dir\n```\n\nresults in a folder `log_dir`, and in there another folder called\n\n```\n0502_1213 cr oi\n```\n\nIf you want to modify the code, consider using the `-p` flag. For example,\nif you wanted to add a flag for upsampling, you could do\n\n```bash\npython train.py configs/ms/cr.cf configs/dl/oi.cf log_dir -p upsampling=newfancymethod\n```\n\nwhich would result in a folder called\n\n```\n0502_1213 cr oi upsampling=newfancymethod\n```\n\nCheckpoints (weights) will be stored in a subfolder called `ckpts`.\n\nThis experiment can then be evaluated simply by passing the log date to `test.py`, in addition to some image folders:\n\n\n```bash\npython test.py logs 0502_1213 data/openimages_test,data/raise1k\n```\n\nwhere we test on images in `data/openimages_test` and `data/raise1k`.\n\nTo use another model as a **pretrained model**, use `--restore` and `--restore_restart`:\n\n```bash\npython train.py configs/ll/cr.cf configs/dl/oi.cf logs --restore 0502_1213 --restore_restart\n```\n\n### Naming of Code vs. Paper\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src='figs/arch_detail.png' width=\"99%\"/\u003e\n\u003c/div\u003e\n\n\n| Name in Paper | Symbol | Name in Code | Short | Class |\n| ----- | -------| -----| ----- | -----|\n| Feature Extractor | `E` | Encoder | `enc` | `EDSRLikeEnc`\n| Predictor | `D` | Decoder | `dec` | `EDSRLikeDec`\n| Quantizer | `Q` | Quantizer | `q` | `Quantizer`\n| Final box, outputting pi, mu, sigma |  | Probability Classifier | `prob_clf` | `AtrousProbabilityClassifier`\n\nSee also the notes in `src/multiscale_network/multiscale.py`.\n\n### Structure of the Code\n\nThe code is quite modular, as it was used to experiment with different things. At the heart is the\n`MultiscaleBlueprint` class, which has the following main functions: `forward`, `get_loss`, `sample`. It is used by the\n`MultiscaleTrainer` and `MultiscaleTester`. The network is created by `MultiscaleNetwork`, which pulls together all\nthe PyTorch modules needed. The discretized mixture of logistics loss is in `DiscretizedMixLogisticsLoss`, which is\nusally referred to as `dmll` or `dmol` in the code.\n\nFor bitcoding, there is the `Bitcoding` class, which uses the `ArithmeticCoding` class, which in turn uses my\n`torchac` module, written in C++, and described below.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src='figs/l3c_code_outline.jpg' width='60%'/\u003e\n\u003c/div\u003e\n\n## The `torchac` Module: Fast Entropy Coding in PyTorch\n\n\u0026#x2757; **Update**: _We released `torchac` as a stand-alone repo, that does not depend on CUDA.\nCheck it out [here](https://github.com/fab-jul/torchac).\nTo run L3C, you need the version here, but for your own future work, the stand-alone repo will be better._ \u0026#x2757;\n\nWe implemented an entropy coding module as a C++ extension for PyTorch, because no existing fast Python entropy\n coding module was available. You'll need to build it if you plan to use the `--write_to_file` flag for `test.py`\n ([see Evaluation of Models](#evaluation)).\n\nThe implementation is based on [this blog post](https://marknelson.us/posts/2014/10/19/data-compression-with-arithmetic-coding.html),\nmeaning that we implement _arithmetic coding_.\nIt is **not optimized**, however, it's much faster than doing the equivalent thing in pure-Python (because of all the\n bit-shift etc.). Encoding an entire `512 x 512` image happens in 0.202s (see Appendix A in the paper).\n\n\n#### GPU and CPU support\n\nThe module can be built with or without CUDA. The only difference between the CUDA and non-CUDA versions is:\nWith CUDA, `_get_uint16_cdf` from `torchac.py` is done with a simple/non-optimized CUDA kernel (`torchac_kernel.cu`),\nwhich has one benefit: we can directly write into shared memory! This saves an expensive copying step from GPU to CPU.\n\nHowever, compiling with CUDA is probably a hassle. We tested with\n- GCC 5.5 and NVCC 9.0\n- GCC 7.4 and NVCC 10.1 (update 2)\n- _Did not work_: GCC 6.0 and NVCC 9\n\nPlease comment if you have insights into which other configurations work (or don't.)\n\n\u0026#x2757; _See update above on the stand-alond [torchac repo](https://github.com/fab-jul/torchac) that does not need GCC or NVCC._ \u0026#x2757;\n\nThe main part (arithmetic coding), is always on CPU.\n\n#### Compiling\n\n_Step 1_: Make sure a **recent `gcc` is available** in `$PATH` by running `gcc --version` (tested with version 5.5).\nIf you want CUDA support, make sure `nvcc -V` gives the desired version (tested with nvcc version 9.0).\n\n_Step 1b, macOS only_ (tested with 10.14): Set the following\n```bash\nexport CC=\"clang++ -std=libc++\"\nexport MACOSX_DEPLOYMENT_TARGET=10.14\n```\n\n_Step 2_:\n ```bash\n conda activate l3c_env\n cd src/torchac\n COMPILE_CUDA=auto python setup.py install\n ```\n- `COMPILE_CUDA=auto`: Use CUDA if a `gcc` between 5 and 6, and `nvcc` 9 is avaiable\n- `COMPILE_CUDA=force`: Use CUDA, don't check `gcc` or `nvcc`\n- `COMPILE_CUDA=no`: Don't use CUDA\n\nThis installs a package called `torchac-backend-cpu` or `torchac-backend-gpu` in your `pip`.\nBoth can be installed simultaneously. See also next subsection.\n\n_Step 3_: To test if it works, you can do\n  ```\n conda activate l3c_env\n cd src/torchac\n python -c \"import torchac\"\n ```\nIt should not print any error messages.\n\n\n#### Selecting torchac: `torchac-backend-cpu` vs `torchac-backend-gpu`\n\nInstalling `torchac-backend-cpu` is easiest. However, if a GPU is available in the system, `torchac-backend-gpu` will be faster.\n\nIf you use `l3c.py`, it will automatically select whether the\ncode should run on GPU or CPU depending on whether `torchac-backend-gpu` is available. The behavior of this can be\ntuned with the `--device` flag to `l3c.py`, e.g., `python l3c.py --device=cpu enc ...`, see `python l3c.py --help`.\n\nIf you use `test.py` with the `--write_to_files` flag, a check will be performed an exception will be thrown, if the wrong\ncombination of _CUDA available_ and _installed `torchac`_ exists. If you just have `torchac-backend-cpu` but a GPU in the system,\ndisable it via `CUDA_VISIBLE_DEVICES=\"\" python test.py ...`.\n\n\n## Sampling\n\nTo sample from L3C, use `test.py` with `--sample`:\n\n```bash\npython test.py /path/to/logdir 0306_0001 /some/imgdir --sample=samples\n```\n\nThis produces outputs in a directory `samples`. Per image, you'll get something like\n\n```bash\n# Ground Truth\n0_IMGNAME_3.549_gt.png\n# Sampling from RGB scale, resulting bitcost 1.013bpsp\n0_IMGNAME_rgb_1.013.png\n# Sampling from RGB scale and z1, resulting bitcost 0.342bpsp\n0_IMGNAME_rgb+bn0_0.342.png\n# Sampling from RGB scale and z1 and z2, resulting bitcost 0.121bpsp\n0_IMGNAME_rgb+bn0+bn1_0.121.png\n```\n\nSee Section 5.4. (\"Sampling Representations\") in the paper.\n\n\n## Using L3C to Compress Images\n\nTo encode/decode a single image, use `l3c.py`. This requires `torchac`:\n\n```bash\n# Encode to out.l3c\npython l3c.py /path/to/logdir 0306_0001 enc /path/to/img out.l3c\n# Decode from out.l3c, save to decoded.png\npython l3c.py /path/to/logdir 0306_0001 dec out.l3c decoded.png\n```\n\n## Prepare Open Images for Training\n\nUse the `prep_openimages.sh` script. Run it in an environment with\nPython 3,\n`skimage` (`pip install scikit-image`, tested with version 0.13.1), and\n[`awscli`](https://aws.amazon.com/cli/) (`pip install awscli`):\n```bash\ncd src\n./prep_openimages.sh \u003cDATA_DIR\u003e\n```\n**NOTE**: The preprocessing may take a long time. We run it over our internal CPU cluster. Please see\n`import_train_images.py` for tips on how to incorporate your own cluster.\n\nThis will download all images to `DATA_DIR`. Make sure there is enough space there, as **this script will create\naround 300 GB of data**. Also, it will probably run for a few hours.\n\nAfter `./prep_openimages.sh` is done, training data is in `DATA_DIR/train_oi` and `DATA_DIR/val_oi`. Follow the\ninstructions printed by `./prep_openimages.sh` to update the config file. You may `rm -rf DATA_DIR/download` and\n`rm -rf DATA_DIR/imported` to free up some space.\n\n(Optional) It helps to have one fixed validation image to monitor training. You may put any image at\n\n\u003c!--\n### Option 2: Step by Step\n\n1. Download [Open Images training sets and validation set](https://github.com/cvdfoundation/open-images-dataset#download-images-with-bounding-boxes-annotations),\nwe used the parts 0, 1, 2, plus the validation set:\n    ```\n    aws s3 --no-sign-request cp s3://open-images-dataset/tar/train_0.tar.gz train_0.tar.gz\n    aws s3 --no-sign-request cp s3://open-images-dataset/tar/train_1.tar.gz train_1.tar.gz\n    aws s3 --no-sign-request cp s3://open-images-dataset/tar/train_2.tar.gz train_2.tar.gz\n    aws s3 --no-sign-request cp s3://open-images-dataset/tar/validation.tar.gz validation.tar.gz\n    ```\n1. Extract to a folder, let's say `data`. Now you should have `data/train_0`, `data/train_1`, `data/train_2`, as well\n as `data/validation`.\n1. (Optional) to do the same preprocessing as in our paper, run the following. Note that it requires the `skimage`\npackage. To speed this up, you can distribute it on some server, by implementing a\n`task_array.sh`, see `import_train_images.py`.\n    ```\n    python import_train_images.py data train_0 train_1 train_2 validation\n    ```\n1. Put all (preprocessed) images into a train and a validation folder, let's say `data/train_oi` and\n`data/validation_oi`.\n1. (Optional) If you are on a slow file system, it helps to cache the contents of `data/train_oi`. Run\n    ```\n    cd src\n    export CACHE_P=\"data/cache.pkl\"  # \u003c--- Change this\n    export PYTHONPATH=$(pwd)\n    python dataloaders/images_loader.py update data/train_oi \"$CACHE_P\"  --min_size 128\n    ```\n    The `--min_size` makes sure to skip smaller images. *NOTE*: If you skip this step, make sure no files with\n    dimensions smaller than 128 are in your training foler. If they are there, training might crash.\n1. Update the dataloader config, `configs/dl/oi.cf`: Set `train_imgs_glob =\n'data/train_oi'` (or whatever folder you used.) If you did the previous step, set `image_cache_pkl = 'data/cache.pkl`,\nif you did not, set `image_cache_pkl = None`. Finally, update `val_glob = 'data/validation_oi'`.\n1. (Optional) It helps to have one fixed validation image to monitor training. You may put any image at\n`src/train/fixedimg.jpg` and it will be used for that (see `multiscale_trainer.py`).\n--\u003e\n\n## Future Work for Code\n\n- Add support for `nn.DataParallel`.\n- Incorporate TensorBoard support from PyTorch, instead of pip package.\n\n## Citation\n\nIf you use the work released here for your research, please cite this paper:\n```\n@inproceedings{mentzer2019practical,\n    Author = {Mentzer, Fabian and Agustsson, Eirikur and Tschannen, Michael and Timofte, Radu and Van Gool, Luc},\n    Booktitle = {Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},\n    Title = {Practical Full Resolution Learned Lossless Image Compression},\n    Year = {2019}}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffl0wbar%2Ffrllic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffl0wbar%2Ffrllic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffl0wbar%2Ffrllic/lists"}