{"id":28988683,"url":"https://github.com/eidoslab/stanh","last_synced_at":"2025-06-24T22:06:36.351Z","repository":{"id":265070425,"uuid":"869966437","full_name":"EIDOSLAB/StanH","owner":"EIDOSLAB","description":"Pytorch implementation of StanH quantizer for variable rate coding","archived":false,"fork":false,"pushed_at":"2025-02-10T19:40:48.000Z","size":5866,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-10T20:30:48.951Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EIDOSLAB.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":"2024-10-09T08:01:15.000Z","updated_at":"2025-02-10T19:40:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"edff9cb3-8794-42a9-ad77-3eccff974f19","html_url":"https://github.com/EIDOSLAB/StanH","commit_stats":null,"previous_names":["eidoslab/stanh"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EIDOSLAB/StanH","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2FStanH","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2FStanH/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2FStanH/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2FStanH/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EIDOSLAB","download_url":"https://codeload.github.com/EIDOSLAB/StanH/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2FStanH/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261764387,"owners_count":23206255,"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":[],"created_at":"2025-06-24T22:06:35.503Z","updated_at":"2025-06-24T22:06:36.305Z","avatar_url":"https://github.com/EIDOSLAB.png","language":"Python","readme":"# STanH : Parametric Quantization for Variable Rate Learned Image Compression\n\n\nPytorch implementation of the paper \"**STanH : Parametric Quantization for Variable Rate Learned Image Compression**\",  accepted at TIP. This repository is based on [CompressAI](https://github.com/InterDigitalInc/CompressAI) and [STF](https://github.com/Googolxx/STF)\n\n[Paper link](https://arxiv.org/abs/2410.00557)\n\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"imgs/stanh.png\" alt=\"stanh\" width=\"400\"/\u003e\n\u003cp\u003e\u003cem\u003eSTanH activation function with 5 quantization\nlevels and for increasing values of inverse temperature β.\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n\n## Abstract\nIn end-to-end learned image compression, encoder\nand decoder are jointly trained to minimize a R + λD cost\nfunction, where λ controls the trade-off between rate of the\nquantized latent representation and image quality. Unfortunately,\na distinct encoder-decoder pair with millions of parameters must\nbe trained for each λ, hence the need to switch encoders and\nto store multiple encoders and decoders on the user device for\nevery target rate. This paper proposes to exploit a differentiable\nquantizer designed around a parametric sum of hyperbolic\ntangents, called STanH , that relaxes the step-wise quantization\nfunction. STanH is implemented as a differentiable activation\nlayer with learnable quantization parameters that can be plugged\ninto a pre-trained fixed rate model and refined to achieve different\ntarget bitrates. Experimental results show that our method\nenables variable rate coding with comparable efficiency to the\nstate-of-the-art, yet with significant savings in terms of ease of\ndeployment, training time, and storage costs.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"imgs/arch.png\" alt=\"arch\" width=\"600\"/\u003e\n\u003cp\u003e\u003cem\u003eThe reference learned image compression architecture Zou22  (CNN-based architecture) with two STanH layers for quantizing the main latent space y and the hyperprior latent space z.\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n## Preparation \nIn order to use this code, You can create a conda environment, with CUDA if you use GPU (suggested)\n\n```\nconda create -n $NAME python=3.8\nconda activate $NAME\n\nconda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch\npip install -r requirements.txt\n```\n\n\n## Validate\n\nDownload our pretrained model (based on Zou2022) in the following directory from [here](https://drive.google.com/drive/folders/1LJ6nmQZJyMaJKFzr-sb2C9m9oxHE5pE5).\n\n\n\n```\ncd src \n\npython demo.py \\\n--image_path #path-for-the-image-to-encode \\ \n--model_checkpoint #path-for-the-checkpoint-of-the-anchor \\\n--stanh_path #path-where-stanhs-are-saved \\ \n--wandb_log #if-ypu-want-wandb-plot \\ \n--entropy_estimation #estimation-of-entropy (faster) \n--path_save #path-where-to-save-results \\\n--interpolation #to include-interpolated-points\n--device cuda\n```\n\nUntil now, we use Torcach to perform Arithmetic coding (very slow), in future code will be adapted to use RANS as standard model in CompressAI library","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feidoslab%2Fstanh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feidoslab%2Fstanh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feidoslab%2Fstanh/lists"}