{"id":13564200,"url":"https://github.com/cvqluu/Angular-Penalty-Softmax-Losses-Pytorch","last_synced_at":"2025-04-03T21:30:32.509Z","repository":{"id":63057498,"uuid":"191803357","full_name":"cvqluu/Angular-Penalty-Softmax-Losses-Pytorch","owner":"cvqluu","description":"Angular penalty loss functions in Pytorch (ArcFace, SphereFace, Additive Margin, CosFace) ","archived":false,"fork":false,"pushed_at":"2023-12-13T07:00:32.000Z","size":9803,"stargazers_count":483,"open_issues_count":14,"forks_count":91,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-04T17:47:13.296Z","etag":null,"topics":["am-softmax","arcface","embedding","face-recognition","face-verification","fashion-mnist","fmnist-dataset","loss-function","loss-functions","metric-learning","normface","pytorch","speaker-recognition","sphereface"],"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/cvqluu.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-13T17:09:43.000Z","updated_at":"2024-10-28T02:16:30.000Z","dependencies_parsed_at":"2024-08-01T13:20:07.310Z","dependency_job_id":"372ecbcf-c88e-468e-8756-0aaa1f59f2a6","html_url":"https://github.com/cvqluu/Angular-Penalty-Softmax-Losses-Pytorch","commit_stats":{"total_commits":19,"total_committers":3,"mean_commits":6.333333333333333,"dds":"0.42105263157894735","last_synced_commit":"c41d599622b6a6ba7e5be6faf3a01da1202024ea"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cvqluu","download_url":"https://codeload.github.com/cvqluu/Angular-Penalty-Softmax-Losses-Pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247082832,"owners_count":20880725,"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":["am-softmax","arcface","embedding","face-recognition","face-verification","fashion-mnist","fmnist-dataset","loss-function","loss-functions","metric-learning","normface","pytorch","speaker-recognition","sphereface"],"created_at":"2024-08-01T13:01:27.901Z","updated_at":"2025-04-03T21:30:30.892Z","avatar_url":"https://github.com/cvqluu.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Angular Penalty Softmax Losses Pytorch\nConcise Pytorch implementation of the Angular Penalty Softmax Losses presented in: \n\n* ArcFace: https://arxiv.org/abs/1801.07698 [1]\n* SphereFace: https://arxiv.org/abs/1704.08063 [2]\n* CosFace/Additive Margin: https://arxiv.org/abs/1801.09414 [3] / https://arxiv.org/abs/1801.05599 [4]\n\n(Note: the SphereFace implementation is not exactly as described in their paper but instead uses the 'trick' presented in the ArcFace paper to use arccosine instead of the double angle formula)\n\n```python\n\nfrom loss_functions import AngularPenaltySMLoss\n\nin_features = 512\nout_features = 10 # Number of classes\n\ncriterion = AngularPenaltySMLoss(in_features, out_features, loss_type='arcface') # loss_type in ['arcface', 'sphereface', 'cosface']\n\n# Forward method works similarly to nn.CrossEntropyLoss\n# x of shape (batch_size, in_features), labels of shape (batch_size,)\n# labels should indicate class of each sample, and should be an int, l satisying 0 \u003c= l \u003c out_dim\nloss = criterion(x, labels) \nloss.backward()\n```\n\n## Experiments/Demo\n\nThere are a simple set of experiments on [Fashion-MNIST](https://github.com/zalandoresearch/fashion-mnist) [2] included in `train_fMNIST.py` which compares the use of ordinary Softmax and Additive Margin Softmax loss functions by projecting embedding features onto a 3D sphere.\n\nThe experiments can be run like so:\n\n``\npython train_fMNIST.py --num-epochs 40 --seed 1234 --use-cuda\n``\n\nWhich produces the following results:\n\n### Baseline (softmax)\n![softmax](figs/baseline.png?raw=true \"softmax\")\n\n### Additive Margin Softmax/CosFace\n![cosface](figs/cosface.png?raw=true \"cosface\")\n\n### ArcFace\n![arcface](figs/arcface.png?raw=true \"arcface\")\n\nTODO: fix sphereface results\n\n[1] Deng, J. et al. (2018) ‘ArcFace: Additive Angular Margin Loss for Deep Face Recognition’. Available at: http://arxiv.org/abs/1801.07698.\n\n[2] Liu, W. et al. (2017) ‘SphereFace: Deep hypersphere embedding for face recognition’, in Proceedings - 30th IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2017, pp. 6738–6746. doi: 10.1109/CVPR.2017.713.\n\n[3] Wang, H. et al. (2018) ‘CosFace: Large Margin Cosine Loss for Deep Face Recognition’. Available at: http://openaccess.thecvf.com/content_cvpr_2018/papers/Wang_CosFace_Large_Margin_CVPR_2018_paper.pdf (Accessed: 12 August 2019).\n\n[4] “Additive Margin Softmax for Face Verification.” Wang, Feng, Jian Cheng, Weiyang Liu and Haijun Liu. IEEE Signal Processing Letters 25 (2018): 926-930.\n\n[5] \"Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms.\" Han Xiao, Kashif Rasul, Roland Vollgraf. arXiv:1708.07747\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcvqluu%2FAngular-Penalty-Softmax-Losses-Pytorch/lists"}