{"id":20335836,"url":"https://github.com/twuilliam/bias-gzsl","last_synced_at":"2025-04-11T22:07:36.314Z","repository":{"id":77243463,"uuid":"286835642","full_name":"twuilliam/bias-gzsl","owner":"twuilliam","description":"Source code for \"Bias-Awareness for Zero-Shot Learning the Seen and Unseen\" (BMVC, 2020).","archived":false,"fork":false,"pushed_at":"2020-09-01T14:18:17.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T22:07:31.644Z","etag":null,"topics":["generalized-zero-shot-learning","gzsl","zero-shot-learning"],"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/twuilliam.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":"2020-08-11T19:54:06.000Z","updated_at":"2024-06-06T06:09:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"46d0ae53-5d14-4fdf-84bb-90aa0fefb9a0","html_url":"https://github.com/twuilliam/bias-gzsl","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/twuilliam%2Fbias-gzsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twuilliam%2Fbias-gzsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twuilliam%2Fbias-gzsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twuilliam%2Fbias-gzsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twuilliam","download_url":"https://codeload.github.com/twuilliam/bias-gzsl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487714,"owners_count":21112191,"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":["generalized-zero-shot-learning","gzsl","zero-shot-learning"],"created_at":"2024-11-14T20:44:49.869Z","updated_at":"2025-04-11T22:07:36.305Z","avatar_url":"https://github.com/twuilliam.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bias-gzsl\n\nThis is the source code for reproducing the experiments from the paper:  \n\n[Bias-Awareness for Zero-Shot Learning the Seen and Unseen](https://arxiv.org/abs/2008.11185)  \n**William Thong and Cees G.M. Snoek**  \nBritish Machine Vision Conference (BMVC), 2020\n\n**TL;DR** *We mitigate the classifier bias towards classes seen during training in generalized zero-shot learning (GZSL).\nTo achieve this, we calibrate the model with temperature and apply entropy regularization to balance out seen and unseen class probabilities.*\n\nWe validate the proposed approach on four benchmarks (CUB, SUN, AWA, and FLO) in two scenarios:  \n(a) stand-alone classifier with only seen class features,  \n(b) classifier with real seen class samples and generated unseen class features.\n\nIn other words, our bias-aware classifier behaves like a traditional compatibility functions for (G)ZSL and can integrate unseen class features from any existing generative model.\n\n### Datasets\n\n**Features** We rely on the features extracted by \\[Xian, et al, CVPR 2018\\] and use the same train/test splits. Sentences for CUB and FLO were collected by \\[Reed et al, CVPR 2016\\].  \n* CUB, SUN, and AWA features are [here](http://datasets.d2.mpi-inf.mpg.de/xian/xlsa17.zip).  \n* CUB sentences are [here](https://www.dropbox.com/sh/btoc495ytfbnbat/AAAaurkoKnnk0uV-swgF-gdSa?dl=0).\n* FLO features and sentences are [here](http://datasets.d2.mpi-inf.mpg.de/xian/cvpr18xian.zip).\n\n\n##  Stand-alone classification with seen classes only\n\n**GZSL** Run [runs/stand-alone.sh](runs/stand-alone.sh). This will train a bias-aware model with real seen features only. It will perform GZSL at the end of the training for each of the four benchmarks.\n\n**Swapping representations** Run [runs/swapping.sh](runs/swapping.sh). This will train one model with *attributes* representations, and one with *sentence* representations. Then, it will extract the features and perform a least squares estimation for swapping the representations between seen and unseen classes.\n\n##  Classification with both seen and unseen classes\n\n**Generating unseen class features** We rely on existing models to generate unseen class features. We select [f-CLSWGAN](https://www.mpi-inf.mpg.de/departments/computer-vision-and-machine-learning/research/zero-shot-learning/feature-generating-networks-for-zero-shot-learning) and [cycle-CLSWGAN](https://github.com/rfelixmg/frwgan-eccv18), which are publicly available and reproducible.\n\nWe train both and extract the features to be used in our bias-aware classifier. Note that our bias-aware classifier is not limited to these two methods to generate features, and can be used for any other method that produces generated features! For this, you just need to save into an `.npz` file the following:\n```\ntrain_seen_X\ntrain_seen_Y\ntrain_unseen_X\ntrain_unseen_Y\ntest_seen_X\ntest_seen_Y\ntest_unseen_X\ntest_unseen_Y\n```\nor alternatively with seen and unseen merged in the training set:\n```\ntrain_X  # includes both real and generated features\ntrain_Y\ntest_seen_X\ntest_seen_Y\ntest_unseen_X\ntest_unseen_Y\n```\n\nFor convenience, [here](https://isis-data.science.uva.nl/wthong/cyclegan.tar.gz) are features from cycle-CLSWGAN for each dataset (900MB file). Note that it corresponds to features for one seed point. In the paper we report the average over 3 runs, so numbers might be different.\n\n**GZSL** Run [runs/with-generated.sh](runs/with-generated.sh). This will train a bias-aware model with real seen features and generated unseen features from cycle-CLSWGAN. It perform GZSL at the end of the training for each of the four benchmarks.\n\n## Requirements\n\nThe source code relies on python 3.6 and pytorch 0.4:\n\n```\npython=3.6.9\npandas=0.25.2\nnumpy=1.17.3\npytorch=0.4.1\ntorchvision=0.2.1\nscikit-learn=0.22.1\n```\n\n## Citation\n\nIf you find these scripts useful, please consider citing our paper:\n\n```\n@inproceedings{\n    Thong2020BiasGZSL,\n    title={Bias-Awareness for Zero-Shot Learning the Seen and Unseen},\n    author={Thong, William and Snoek, Cees G.M.},\n    booktitle={BMVC},\n    year={2020},\n    url={https://arxiv.org/abs/2008.11185}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwuilliam%2Fbias-gzsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwuilliam%2Fbias-gzsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwuilliam%2Fbias-gzsl/lists"}