{"id":15031964,"url":"https://github.com/caoscott/srec","last_synced_at":"2025-04-12T15:43:20.759Z","repository":{"id":41431619,"uuid":"247876759","full_name":"caoscott/SReC","owner":"caoscott","description":"PyTorch Implementation of \"Lossless Image Compression through Super-Resolution\"","archived":false,"fork":false,"pushed_at":"2023-10-03T21:19:49.000Z","size":42650,"stargazers_count":1052,"open_issues_count":10,"forks_count":93,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-03T16:12:38.702Z","etag":null,"topics":["compression","lossless","neural-network","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caoscott.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}},"created_at":"2020-03-17T04:09:46.000Z","updated_at":"2025-04-03T01:39:56.000Z","dependencies_parsed_at":"2024-04-13T17:04:12.873Z","dependency_job_id":"6b8c6263-6f61-4a8e-b973-963d2e8561f6","html_url":"https://github.com/caoscott/SReC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caoscott%2FSReC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caoscott%2FSReC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caoscott%2FSReC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caoscott%2FSReC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caoscott","download_url":"https://codeload.github.com/caoscott/SReC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590939,"owners_count":21129916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["compression","lossless","neural-network","pytorch"],"created_at":"2024-09-24T20:17:00.047Z","updated_at":"2025-04-12T15:43:20.728Z","avatar_url":"https://github.com/caoscott.png","language":"Python","readme":"# Lossless Image Compression through Super-Resolution  \u003cbr\u003e\n[Sheng Cao](https://caoscott.github.io/),\n[Chao-Yuan Wu](https://www.cs.utexas.edu/~cywu/), \n[Philipp Kr\u0026auml;henb\u0026uuml;hl](http://www.philkr.net/).  \n## [[Paper]](https://arxiv.org/abs/2004.02872) ## \n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"figs/concept_fig.png\" /\u003e\n\u003c/div\u003e\n\n## Citation\n```bibtex\n@article{cao2020lossless,\n  title={Lossless Image Compression through Super-Resolution},\n  author={Cao, Sheng and Wu, Chao-Yuan and and Kr{\\\"a}henb{\\\"u}hl, Philipp},\n  year={2020},\n  journal={arXiv preprint arXiv:2004.02872},\n}\n```\n\nIf you use our codebase, please consider also [citing L3C](https://github.com/fab-jul/L3C-PyTorch#citation)\n\n## Overview\nThis is the official implementation of SReC in [PyTorch](http://pytorch.org/). \nSReC frames lossless compression as a super-resolution problem and applies neural networks to compress images. \nSReC can achieve state-of-the-art compression rates on large datasets with practical runtimes. \nTraining, compression, and decompression are fully supported and open-sourced.\n\n## Getting Started\nWe recommend the following steps for getting started.\n\n1. [Install the necessary dependencies](INSTALL.md)\n2. [Download the Open Images validation set](http://data.vision.ee.ethz.ch/mentzerf/validation_sets_lossless/val_oi_500_r.tar.gz)\n3. [Run compression on Open Images validation set](#compressiondecompression) with [trained model weights](#model-weights)\n\n## Installation\nSee [here](INSTALL.md) for installation instructions.\n\n## Model Weights\nWe've released trained models for both [ImageNet64](https://arxiv.org/abs/1707.08819) and [Open Images (PNG)](https://storage.googleapis.com/openimages/web/index.html). \nAll compression results are measured in bits per subpixel (bpsp).\n\n| Dataset | Bpsp | Model Weights |\n| ----------- | ---- | ---------------------- |\n| ImageNet64 | 4.29 | [models/imagenet64.pth](models/imagenet64.pth) |\n| Open Images | 2.70 | [models/openimages.pth](models/openimages.pth) |\n\n## Training\nTo run code, you need to be in top level directory.\n```\npython3 -um src.train \\\n  --train-path \"path to directory of training images\" \\\n  --train-file \"list of filenames of training images, one filename per line\" \\\n  --eval-path \"path to directory of eval images\" \\\n  --eval-file \"list of filenames of eval images, one filename per line\" \\\n  --plot \"directory to store model output\" \\\n  --batch \"batch size\"\n```\n\nThe training images must be organized in form of `train-path/filename` from filename in train-file. Same thing applies to eval images.\n\nWe've included our training and eval files used for ImageNet64 and Open Images (PNG) in `datasets` directory. \n\nFor ImageNet64, we use a slightly different set of hyperparameters than Open Images hyperparameters, which are the default. To train ImageNet64 based on settings from our paper, run \n```\npython3 -um src.train \\\n  --train-path \"path to directory of training images\" \\\n  --train-file \"list of filenames of training images, one filename per line\" \\\n  --eval-path \"path to directory of eval images\" \\\n  --eval-file \"list of filenames of eval images, one filename per line\" \\\n  --plot \"directory to store model output\" \\\n  --batch \"batch size\" \\\n  --epochs 10 \\\n  --lr-epochs 1 \\\n  --crop 64\n```\n\nRun `python3 -um src.train --help` for a list of tunable hyperparameters.\n\n## Evaluation\nGiven a model checkpoint, this evaluates theoretical bits/subpixel (bpsp) based on log-likelihood. The log-likelihood bpsp lower-bounds the actual compression bpsp.\n```\npython3 -um src.eval \\\n  --path \"path to directory of images\" \\\n  --file \"list of filenames of images, one filename per line\" \\\n  --load \"path to model weights\"\n```\n\n## Compression/Decompression\n\nWith torchac installed, you can run compression/decompression to convert any image into .srec files.\nThe following compresses a directory of images.\n```\npython3 -um src.encode \\\n  --path \"path to directory of images\" \\ \n  --file \"list of filenames of images, one filename per line\" \\\n  --save-path \"directory to save new .srec files\" \\\n  --load \"path to model weights\"\n```\nIf you want an accurate runtime, we recommend running python with `-O` flag to disable asserts.\nWe also include an optional `--decode` flag so that you can check if decompressing the .srec file gives the original image, as well as provide runtime for decoding.\n\nTo convert .srec files into PNG, you can run\n```\npython3 -um src.decode \\\n  --path \"path to directory of .srec images\" \\ \n  --file \"list of filenames of .srec images, one filename per line\" \\\n  --save-path \"directory to save png files\" \\\n  --load \"path to model weights\"\n```\n\n## Downloading ImageNet64\nYou can download ImageNet64 training and validation sets [here](http://www.image-net.org/small/download.php).\n\n## Preparing Open Images Dataset (PNG)\nWe use the same set of training and validation images of Open Images as [L3C](https://github.com/fab-jul/L3C-PyTorch). \n\nFor **validation images**, you can [**download them here**](http://data.vision.ee.ethz.ch/mentzerf/validation_sets_lossless/val_oi_500_r.tar.gz).\n\nFor **training images**, please clone the [L3C repo](https://github.com/fab-jul/L3C-PyTorch/) and run [script from here](https://github.com/fab-jul/L3C-PyTorch#prepare-open-images-for-training)\n\nSee [this issue](https://github.com/fab-jul/L3C-PyTorch/issues/14) for differences between Open Images JPEG and Open Images PNG.\n\n## Acknowledgment\nThanks to [L3C](https://github.com/fab-jul/L3C-PyTorch) for implementations of EDSR, logistic mixtures, and arithmetic coding.\nSpecial thanks to [Fabian Mentzer](https://github.com/fab-jul) for letting us know about issues with the preprocessing script for Open Images JPEG and resolving them quickly.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaoscott%2Fsrec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaoscott%2Fsrec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaoscott%2Fsrec/lists"}