{"id":15694249,"url":"https://github.com/dansuh17/deep-supervised-hashing","last_synced_at":"2025-05-08T20:49:21.423Z","repository":{"id":40978667,"uuid":"190048137","full_name":"dansuh17/deep-supervised-hashing","owner":"dansuh17","description":"pytorch implementation of Deep Supervised Hashing","archived":false,"fork":false,"pushed_at":"2023-02-15T22:03:09.000Z","size":466,"stargazers_count":10,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T18:05:46.493Z","etag":null,"topics":["deep","deep-hashing","deep-learning","distance","hash-values","python","pytorch","umap"],"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/dansuh17.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":"2019-06-03T17:09:20.000Z","updated_at":"2024-12-06T06:12:55.000Z","dependencies_parsed_at":"2024-10-24T01:19:49.884Z","dependency_job_id":"f955045f-e2fc-495c-8c12-0441a3ca2e48","html_url":"https://github.com/dansuh17/deep-supervised-hashing","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/dansuh17%2Fdeep-supervised-hashing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dansuh17%2Fdeep-supervised-hashing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dansuh17%2Fdeep-supervised-hashing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dansuh17%2Fdeep-supervised-hashing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dansuh17","download_url":"https://codeload.github.com/dansuh17/deep-supervised-hashing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253149322,"owners_count":21861716,"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":["deep","deep-hashing","deep-learning","distance","hash-values","python","pytorch","umap"],"created_at":"2024-10-03T18:55:07.589Z","updated_at":"2025-05-08T20:49:21.406Z","avatar_url":"https://github.com/dansuh17.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deep Supervised Hashing in pyTorch\n\nThis is a [pyTorch](https://pytorch.org/) implementation of paper: [Liu et al. - Deep Supervised Hashing for Fast Image Retrieval (CVPR 2016)](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Liu_Deep_Supervised_Hashing_CVPR_2016_paper.pdf)\n\n## Requirements\n- python \u003e=3.6\n- pytorch \u003e=1.1 (must havetensorboard included)\n\n## Model\n![img](./img/model.png)\n- Uses a simple CNN layer, but in this repository the model is a small ResNet.\n- Accepts the number of bits it should encode the hash into.\n\n## Loss Function\n![loss_func](./img/loss_function.png)\n\n- The loss function is the pairwise ranking loss function with _margin_ and _regularization_ \n(There is a nice [blog post](https://gombru.github.io/2019/04/03/ranking_loss/) about the description of various loss functions).\n- The pairwise loss function forces the distance of similar pairs to be small, \nand that of dissimilar pairs to be large, with a margin so that the model does not leverage on dissimilar pairs.\n- The third term, the regularization term, leads the output binary-like vectors' elements have absolute values close to 1 \n(an L1 loss with `ones` tensor).\n- Large `alpha` value introduces more penalty if vector's elements are not close to 1.\n\n## Experiments\n- The experiment is done with **MNIST** dataset, and the model is told to encode the class of the image in **8** bits (which can hold max 256 classes)\n- The UMAP and t-SNE results show clear clustering of the output vectors.\n![umap](./img/umap_deephash.png)\n![tsne](./img/tsne_deephash.png)\n\n### Hash values\n- Here are the list of hash values generated by taking the output vector of the model and encoding as follows:\n\n```python\nif element \u003e= 0:\n    bit = 1\nelse:\n    bit = 0\n```\n\n| class | hash (binary) |\n|---|---|\n| 0 | `0xFB` (1111 1011) |\n| 1 | `0x39` (0011 1001) |\n| 2 | `0x77` (0111 0111) |\n| 3 | `0xF7` (1111 0111) |\n| 4 | `0x5E` (0101 1110) |\n| 5 | `0xED` (1110 1101) |\n| 6 | `0xE9` (1110 1001) |\n| 7 | `0xBE` (1011 1110) |\n| 8 | `0xC7` (1100 0111) |\n| 9 | `0xFE` (1111 1110) |\n\n- There exists variations to the generated hash values, so that the output hashes from the same class do not form an exact match, \nbut they span a space within small Hamming distance.\n- For example, other output hashes for 3 are: `0xE7`, `0xBF`, `0xFF` which are all within 2 Hamming distance with `0xF7`.\n- However, the output hash for 2 and 3 have Hamming distance of 1, as well as that of output hashes of 5 and 6.\n- This problem could be mitigated by telling the model to produce a vector with larger dimensions, \ngenerating larger hash in size.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdansuh17%2Fdeep-supervised-hashing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdansuh17%2Fdeep-supervised-hashing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdansuh17%2Fdeep-supervised-hashing/lists"}