{"id":18556642,"url":"https://github.com/ahmdtaha/softmax_triplet_loss","last_synced_at":"2025-10-04T16:45:11.034Z","repository":{"id":98612425,"uuid":"204819355","full_name":"ahmdtaha/softmax_triplet_loss","owner":"ahmdtaha","description":"(WACV 2020) Tensorflow implementation of Boosting Standard Classification Architectures Through a Ranking Regularizer","archived":false,"fork":false,"pushed_at":"2021-10-09T23:19:30.000Z","size":366,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T16:53:08.613Z","etag":null,"topics":["classification","classification-performance","feature-embedding","fgvc-aircraft-dataset","resnet","softmax","tensorflow","triplet-loss"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmdtaha.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-08-28T01:10:59.000Z","updated_at":"2023-06-04T03:23:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b3e7375-4d61-403b-82e2-2e398cc19497","html_url":"https://github.com/ahmdtaha/softmax_triplet_loss","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahmdtaha/softmax_triplet_loss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Fsoftmax_triplet_loss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Fsoftmax_triplet_loss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Fsoftmax_triplet_loss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Fsoftmax_triplet_loss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmdtaha","download_url":"https://codeload.github.com/ahmdtaha/softmax_triplet_loss/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmdtaha%2Fsoftmax_triplet_loss/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278343068,"owners_count":25971399,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"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":["classification","classification-performance","feature-embedding","fgvc-aircraft-dataset","resnet","softmax","tensorflow","triplet-loss"],"created_at":"2024-11-06T21:32:34.135Z","updated_at":"2025-10-04T16:45:10.973Z","avatar_url":"https://github.com/ahmdtaha.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Softmax + a Ranking Regularizer\n\nThis repository contains the tensorflow implementation of [**Boosting Standard Classification Architectures Through a Ranking Regularizer** ](https://arxiv.org/abs/1901.08616)\n\u003e (formely known as **In Defense of the Triplet Loss for Visual Recognition**)\n\nThis code employs triplet loss as a feature embedding regularizer to boost classification performance. It extends standard architectures, like ResNet and Inception, to support both losses with minimal hyper-parameter tuning. \nDuring inference, our network supports both classification and embedding tasks without any computational overhead. Quantitative evaluation highlights a steady improvement on five fine-grained recognition datasets. Further evaluation on an imbalanced video dataset achieves significant improvement.\n\n![](./imgs/arch.jpg)\n\n## Requirements\n\n* Python 3+ [Tested on 3.4.7]\n* Tensorflow 1+ [Tested on 1.8]\n\n\n## Usage example\n\nUpdate [`base_config._load_user_setup`](https://github.com/ahmdtaha/softmax_triplet_loss/blob/f8cfa2e08484dfdd2e2c15d47ed634c037c87d90/config/base_config.py#L98) with your machine configurations\n\n- Where is the datasets dir?\n- Where is the pre-trained model dir? I use [TF slim pretrained models](https://github.com/tensorflow/models/tree/master/research/slim)\n- Where to save tf checkpoints?\n\nThe current `main.py` is configured to use [FGVC-Aircraft dataset](http://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/). To run the code smoothly, your `datasets` dir should contain a directory named `aircrafts` with the following structure\n\u003cpre\u003e\n.\n├── fgvc-aircraft-2013b\n│   └── data\n│       └── images\n└── lists\n\u003c/pre\u003e\n\nThis is the default directory structure when you download the [FGVC-Aircraft dataset](http://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/) except for the `lists` dir. The `lists` dir contains csv files that defines the train, validation and testing splits. For the aircraft dataset, the splits are [defined here](https://github.com/ahmdtaha/softmax_triplet_loss/tree/master/datasets_lists/aircrafts/lists). Similar splits format for other datasets is available [in this repos](https://github.com/ahmdtaha/FineGrainedVisualRecognition/tree/master/dataset_sample)\n\nMost of the datasets, pretrained, and checkpoint settings are handled in the base_config.py module. Once you have these configuration and parameters set, you should be able to train the network using `python main.py`\n\nThis code achieves the following classification performance on **ResNet-50**\n\n|                            | Cars  | Flowers | Dogs  | Aircrafts | Birds |\n|----------------------------|-------|---------|-------|-----------|-------|\n| Softmax                    | 85.85 | 85.68   | 69.76 | 83.22     | 64.23 |\n| Two-head-Center            | 88.23 | 85.00   | 70.45 | 84.48     | 65.50 |\n| Two-Head-Semi-Hard Triplet | 88.22 | 85.52   | 70.69 | 85.08     | 65.20 |\n| Two-Head-Hard Triplet      | 89.44 | 86.61   | 72.70 | 87.33     | 66.19 |\n\n\n## Computational Analysis\nThe proposed Two-head architecture is computational very cheap. It's training time increases, over the single head softmax, by approximately 2%. The following images shows a quantitative timing analysis comparing the single head vs two-head architecture using multiple standard architectures\n\n![](./imgs/timing_analysis.jpg)\n\n## Release History\n\n* 0.0.1\n    * CHANGE: Add quantitative results and timing analysis 7 Jan 2020\n    * CHANGE: First commit 27 Aug 2019\n    * CHANGE: Clean code \u0026 Update Readme file 07 Sep 2019\n\n### TODO LIST\n* Add code comments\n* Improve code documentation\n* Report quantitative evaluation\n\n\n## Reference\n\nIf you found this code useful, please cite the following paper:\n\n```\n@inproceedings{taha2020boosting,\n  title={Boosting Standard Classification Architectures Through a Ranking Regularizer},\n  author={Taha, Ahmed and Chen, Yi-Ting and Misu, Teruhisa and Shrivastava, Abhinav and Davis, Larry},\n  booktitle={The IEEE Winter Conference on Applications of Computer Vision},\n  pages={758--766},\n  year={2020}\n}\n```\n## Contributing\n\n**Both tips to improve the code and pull requests to contribute are very welcomed**\n\n### What needs to be done\n1 - Support Tensorflow 1.4 \u0026 2\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmdtaha%2Fsoftmax_triplet_loss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmdtaha%2Fsoftmax_triplet_loss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmdtaha%2Fsoftmax_triplet_loss/lists"}