[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-wy1iu--sphereface":3,"tool-wy1iu--sphereface":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":79,"owner_twitter":81,"owner_website":82,"owner_url":83,"languages":84,"stars":123,"forks":124,"last_commit_at":125,"license":126,"difficulty_score":127,"env_os":128,"env_gpu":129,"env_ram":130,"env_deps":131,"category_tags":140,"github_topics":141,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":148,"updated_at":149,"faqs":150,"releases":186},2880,"wy1iu\u002Fsphereface","sphereface","Implementation for \u003CSphereFace: Deep Hypersphere Embedding for Face Recognition> in CVPR'17.","SphereFace 是一款专为高精度人脸识别设计的开源深度学习框架，源自 CVPR 2017 的经典论文。它主要解决了传统人脸识别方法在应对复杂光照、姿态变化及大规模身份分类时，特征区分度不足的难题。\n\n该工具提供了一套完整的处理流水线，涵盖人脸检测、对齐到最终识别的全过程。其核心技术创新在于提出了“深度超球面嵌入”理念，通过独特的角间隔软最大损失函数（A-Softmax Loss），强制神经网络在超球面流形上学习具有更大类间间隔和更小类内差异的特征表示。与标准残差网络不同，SphereFace 去除了批归一化层并采用预激活单元，从而在几何意义上更纯粹地优化角度特征，显著提升了模型的判别能力。\n\nSphereFace 非常适合计算机视觉领域的研究人员、算法工程师以及希望深入理解度量学习机制的开发者使用。项目不仅提供了基于 Caffe 的完整训练代码和多种深度的预训练模型（如 20 层至 64 层架构），还包含了在 CASIA-WebFace 和 LFW 等主流数据集上的复现指南。对于想要探索角度边界学习前沿技术或构建高鲁棒性人脸系统的团队来说，这是一个极具参考价值的基准实现。","# *SphereFace*: Deep Hypersphere Embedding for Face Recognition\n\nBy Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj and Le Song\n\n### License\n\nSphereFace is released under the MIT License (refer to the LICENSE file for details).\n\n### Update\n- **2022.4.10**: **If you are looking for an easy-to-use and well-performing PyTorch implementation of SphereFace, we now have it! Check out our official SphereFace PyTorch re-implementation [here](https:\u002F\u002Fopensphere.world\u002F).**\n- **2018.8.14**: We recommand an interesting ECCV 2018 paper that comprehensively evaluates SphereFace (A-Softmax) on current widely used face datasets and their proposed noise-controlled IMDb-Face dataset. Interested users can try to train SphereFace on their IMDb-Face dataset. Take a look [here](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1807.11649.pdf).\n- **2018.5.23**: A new *SphereFace+* that explicitly enhances the inter-class separability has been introduced in our technical report. Check it out [here](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09298). Code is released [here](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface-plus).\n- **2018.2.1**: As requested, the prototxt files for SphereFace-64 are released.\n- **2018.1.27**: We updated the appendix of our SphereFace paper with useful experiments and analysis. Take a look [here](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf). The content contains:\n\t- The intuition of removing the last ReLU;\n\t- Why do we want to normalize the weights other than because we need more geometric interpretation?\n\t- Empirical experiment of zeroing out the biases;\n\t- More 2D visualization of A-Softmax loss on MNIST;\n\t- **Angular Fisher score** for evaluating the angular feature discriminativeness, which is a new and straightforward evluation metric other than the final accuracy.\n\t- Experiments of SphereFace on MegaFace with different convolutional layers;\n\t- The annealing optimization strategy for A-Softmax loss;\n\t-  Details of the 3-patch ensemble strategy in MegaFace challenge;\n\n- **2018.1.20**: We updated some resources to summarize the current advances in angular margin learning. Take a look [here](#resources-for-angular-margin-learning).\n\n### Contents\n0. [Introduction](#introduction)\n0. [Citation](#citation)\n0. [Requirements](#requirements)\n0. [Installation](#installation)\n0. [Usage](#usage)\n0. [Models](#models)\n0. [Results](#results)\n0. [Video Demo](#video-demo)\n0. [Note](#note)\n0. [Third-party re-implementation](#third-party-re-implementation)\n0. [Resources for angular margin learning](#resources-for-angular-margin-learning)\n\n\n### Introduction\n\nThe repository contains the entire pipeline (including all the preprocessings) for deep face recognition with **`SphereFace`**. The recognition pipeline contains three major steps: face detection, face alignment and face recognition.\n\nSphereFace is a recently proposed face recognition method. It was initially described in an [arXiv technical report](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.08063) and then published in [CVPR 2017](http:\u002F\u002Fopenaccess.thecvf.com\u002Fcontent_cvpr_2017\u002Fpapers\u002FLiu_SphereFace_Deep_Hypersphere_CVPR_2017_paper.pdf). The most up-to-date paper with more experiments can be found at [arXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.08063) or [here](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf). To facilitate the face recognition research, we give an example of training on [CAISA-WebFace](http:\u002F\u002Fwww.cbsr.ia.ac.cn\u002Fenglish\u002FCASIA-WebFace-Database.html) and testing on [LFW](http:\u002F\u002Fvis-www.cs.umass.edu\u002Flfw\u002F) using the **20-layer CNN architecture** described in the paper (i.e. SphereFace-20). \n\nIn SphereFace, our network architecures use residual units as building blocks, but are quite different from the standrad ResNets  (e.g., BatchNorm is not used, the prelu replaces the relu, different initializations, etc). We proposed 4-layer, 20-layer, 36-layer and 64-layer architectures for face recognition (details can be found in the [paper]((https:\u002F\u002Farxiv.org\u002Fpdf\u002F1704.08063.pdf)) and [prototxt files](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fblob\u002Fmaster\u002Ftrain\u002Fcode\u002Fsphereface_model.prototxt)). We provided the 20-layer architecure as an example here. If our proposed architectures also help your research, please consider to cite our paper.\n\nSphereFace achieves the state-of-the-art verification performance (previously No.1) in [MegaFace Challenge](http:\u002F\u002Fmegaface.cs.washington.edu\u002Fresults\u002Ffacescrub.html#3) under the small training set protocol.\n\n\n### Citation\n\nIf you find **SphereFace** useful in your research, please consider to cite:\n\n\t@InProceedings{Liu_2017_CVPR,\n\t  title = {SphereFace: Deep Hypersphere Embedding for Face Recognition},\n\t  author = {Liu, Weiyang and Wen, Yandong and Yu, Zhiding and Li, Ming and Raj, Bhiksha and Song, Le},\n\t  booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},\n\t  year = {2017}\n\t}\n\nOur another closely-related previous work in ICML'16 ([more](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss)):\n\n\t@InProceedings{Liu_2016_ICML,\n\t  title = {Large-Margin Softmax Loss for Convolutional Neural Networks},\n\t  author = {Liu, Weiyang and Wen, Yandong and Yu, Zhiding and Yang, Meng},\n\t  booktitle = {Proceedings of The 33rd International Conference on Machine Learning},\n\t  year = {2016}\n\t}\n\n\n### Requirements\n1. Requirements for `Matlab`\n2. Requirements for `Caffe` and `matcaffe` (see: [Caffe installation instructions](http:\u002F\u002Fcaffe.berkeleyvision.org\u002Finstallation.html))\n3. Requirements for `MTCNN` (see: [MTCNN - face detection & alignment](https:\u002F\u002Fgithub.com\u002Fkpzhang93\u002FMTCNN_face_detection_alignment)) and `Pdollar toolbox` (see: [Piotr's Image & Video Matlab Toolbox](https:\u002F\u002Fgithub.com\u002Fpdollar\u002Ftoolbox)).\n\n### Installation\n1. Clone the SphereFace repository. We'll call the directory that you cloned SphereFace as **`SPHEREFACE_ROOT`**.\n\n    ```Shell\n    git clone --recursive https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface.git\n    ```\n\n2. Build Caffe and matcaffe\n\n    ```Shell\n    cd $SPHEREFACE_ROOT\u002Ftools\u002Fcaffe-sphereface\n    # Now follow the Caffe installation instructions here:\n    # http:\u002F\u002Fcaffe.berkeleyvision.org\u002Finstallation.html\n    make all -j8 && make matcaffe\n    ```\n\n### Usage\n\n*After successfully completing the [installation](#installation)*, you are ready to run all the following experiments.\n\n#### Part 1: Preprocessing\n**Note:** In this part, we assume you are in the directory **`$SPHEREFACE_ROOT\u002Fpreprocess\u002F`**\n1. Download the training set (`CASIA-WebFace`) and test set (`LFW`) and place them in **`data\u002F`**.\n\n\t```Shell\n\tmv \u002Fyour_path\u002FCASIA_WebFace  data\u002F\n\t.\u002Fcode\u002Fget_lfw.sh\n\ttar xvf data\u002Flfw.tgz -C data\u002F\n\t```\n    Please make sure that the directory of **`data\u002F`** contains two datasets.\n    \n2. Detect faces and facial landmarks in CAISA-WebFace and LFW datasets using `MTCNN` (see: [MTCNN - face detection & alignment](https:\u002F\u002Fgithub.com\u002Fkpzhang93\u002FMTCNN_face_detection_alignment)).\n\n\t```Matlab\n\t# In Matlab Command Window\n\trun code\u002Fface_detect_demo.m\n\t```\n    This will create a file `dataList.mat` in the directory of **`result\u002F`**.\n3. Align faces to a canonical pose using similarity transformation.\n\n\t```Matlab\n\t# In Matlab Command Window\n  \trun code\u002Fface_align_demo.m\n  \t```\n    This will create two folders (**`CASIA-WebFace-112X96\u002F`** and **`lfw-112X96\u002F`**) in the directory of **`result\u002F`**, containing the aligned face images.\n\n#### Part 2: Train\n**Note:** In this part, we assume you are in the directory **`$SPHEREFACE_ROOT\u002Ftrain\u002F`**\n\n1. Get a list of training images and labels.\n\n\t```Shell&Matlab\n\tmv ..\u002Fpreprocess\u002Fresult\u002FCASIA-WebFace-112X96 data\u002F\n\t# In Matlab Command Window\n\trun code\u002Fget_list.m\n\t```\n    The aligned face images in folder **`CASIA-WebFace-112X96\u002F`** are moved from ***preprocess*** folder to ***train*** folder. A list `CASIA-WebFace-112X96.txt` is created in the directory of **`data\u002F`** for the subsequent training.\n\n2. Train the sphereface model.\n\n\t```Shell\n\t.\u002Fcode\u002Fsphereface_train.sh 0,1\n\t```\n    After training, a model `sphereface_model_iter_28000.caffemodel` and a corresponding log file `sphereface_train.log` are placed in the directory of `result\u002Fsphereface\u002F`.\n\n#### Part 3: Test\n**Note:** In this part, we assume you are in the directory **`$SPHEREFACE_ROOT\u002Ftest\u002F`**\n\n1. Get the pair list of LFW ([view 2](http:\u002F\u002Fvis-www.cs.umass.edu\u002Flfw\u002F#views)).\n\n\t```Shell\n\tmv ..\u002Fpreprocess\u002Fresult\u002Flfw-112X96 data\u002F\n\t.\u002Fcode\u002Fget_pairs.sh\n\t```\n\tMake sure that the LFW dataset and`pairs.txt` in the directory of **`data\u002F`**\n\n1. Extract deep features and test on LFW.\n\n\t```Matlab\n\t# In Matlab Command Window\n\trun code\u002Fevaluation.m\n\t```\n    Finally we have the `sphereface_model.caffemodel`, extracted features `pairs.mat` in folder **`result\u002F`**, and accuracy on LFW like this:\n\n\tfold|1|2|3|4|5|6|7|8|9|10|AVE\n\t:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:\n\tACC|99.33%|99.17%|98.83%|99.50%|99.17%|99.83%|99.17%|98.83%|99.83%|99.33%|99.30%\n\n### Models\n1. Visualizations of network architecture (tools from [ethereon](http:\u002F\u002Fethereon.github.io\u002Fnetscope\u002Fquickstart.html)):\n\t- SphereFace-20: [link](http:\u002F\u002Fethereon.github.io\u002Fnetscope\u002F#\u002Fgist\u002F20f6ddf70a35dec5019a539a502bccc5)\n2. Model file\n\t- SphereFace-20: [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegb2F6dmlmOXhWaVk) | [Baidu](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1qY5FTF2)\n\t- Third-party SphereFace-4 & SphereFace-6: [here](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F81) by [zuoqing1988](https:\u002F\u002Fgithub.com\u002Fzuoqing1988)\n\n\n### Results\n1. Following the instruction, we go through the entire pipeline for 5 times. The accuracies on LFW are shown below. Generally, we report the average but we release the [model-3](#models) here.\n\n\tExperiment |#1|#2|#3 (released)|#4|#5\n\t:---:|:---:|:---:|:---:|:---:|:---:\n\tACC|99.24%|99.20%|**99.30%**|99.27%|99.13%\n\n2. Other intermediate results:\n    - LFW features: [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegenU0cGJYZmlRUlU) | [Baidu](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1o8QIMUY)\n    - Training log: [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegcWkxdVV4X1FOaFU) | [Baidu](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1i5QmXrJ)\n\n\n\n### Video Demo\n[![SphereFace Demo](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fwy1iu_sphereface_readme_d8ab9c46fa65.jpg)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=P6jEzzwoYWs)\n\nPlease click the image to watch the Youtube video. For Youku users, click [here](http:\u002F\u002Ft.cn\u002FRCZ0w1c).\n\nDetails:\n1. It is an **open-set** face recognition scenario. The video is processed frame by frame, following the same pipeline in this repository.\n2. Gallery set consists of 6 identities. Each main character has only 1 gallery face image. All the detected faces are included in probe set.\n3. There is no overlap between gallery set and training set (CASIA-WebFace).\n4. The scores between each probe face and gallery set are computed by cosine similarity. If the maximal score of a probe face is smaller than a pre-definded threshold, the probe face would be considered as an outlier.\n5. Main characters are labeled by boxes with different colors. (\n![#ff0000](https:\u002F\u002Fplacehold.it\u002F15\u002Fff0000\u002F000000?text=+)Rachel,\n![#ffff00](https:\u002F\u002Fplacehold.it\u002F15\u002Fffff00\u002F000000?text=+)Monica,\n![#ff80ff](https:\u002F\u002Fplacehold.it\u002F15\u002Fff80ff\u002F000000?text=+)Phoebe,\n![#00ffff](https:\u002F\u002Fplacehold.it\u002F15\u002F00ffff\u002F000000?text=+)Joey,\n![#0000ff](https:\u002F\u002Fplacehold.it\u002F15\u002F0000ff\u002F000000?text=+)Chandler,\n![#00ff00](https:\u002F\u002Fplacehold.it\u002F15\u002F00ff00\u002F000000?text=+)Ross)\n\n\n### Note\n1. **Backward gradient**\n\t- In this implementation, we did not strictly follow the equations in paper. Instead, we normalize the scale of gradient. It can be interpreted as a varying strategy for learning rate to help converge more stably. Similar idea and intuition also appear in [normalized gradients](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1707.04822.pdf) and [projected gradient descent](https:\u002F\u002Fwww.stats.ox.ac.uk\u002F~lienart\u002Fblog_opti_pgd.html).\n\t- More specifically, if the original gradient of ***f*** w.r.t ***x*** can be written as **df\u002Fdx = coeff_w \\*  w + coeff_x \\* x**, we use the normalized version **[df\u002Fdx] = (coeff_w \\* w + coeff_x \\* x) \u002F norm_wx** to perform backward propragation, where **norm_wx** is **sqrt(coeff_w^2 + coeff_x^2)**. The same operation is also applied to the gradient of ***f*** w.r.t ***w***.\n\t- In fact, you do not necessarily need to use the original gradient, since the original gradient sometimes is not an optimal design. One important criterion for modifying the backprop gradient is that the new \"gradient\" (strictly speaking, it is not a gradient anymore) need to make the objective value decrease stably and consistently. (In terms of some failure cases for gradient-based back-prop, I recommand [a great talk](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=jWVZnkTfB3c) by [Shai Shalev-Shwartz](https:\u002F\u002Fwww.cs.huji.ac.il\u002F~shais\u002F))\n\t- If you use the original gradient to do the backprop, you could still make it work but may need different lambda settings, iteration number and learning rate decay strategy. \n\n2. **Lambda** and **Note for training (When the loss becomes 87)**\n\t- Please refer to our previous [note and explanation](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss#notes-for-training).\n\t\n3. **According to recent advances, using feature normalization with a tunable scaling parameter s can significantly improve the performance of SphereFace on MegaFace challenge**\n\t- This is supported by the experiments done by [CosFace](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.09414). Similar idea also appears in [additive margin softmax](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.05599).\n\n4. **Difficulties in convergence**\n        - When you encounter difficulties in convergence (it may appear if you use *SphereFace* in another dataset), usually there are a few easy ways to address it.\n\t- First, try to use large mini-batch size. \n\t- Second, try to use PReLU instead of ReLU. \n\t- Third, increase the width and depth of our network. \n\t- Fourth, try to use better initialization. For example, use the pretrained model from the original softmax loss (it is also equivalent to finetuning).\n\t- Last and the most effective thing you could try is to change the hyper-parameters for lambda_min, lambda and its decay speed.\n\n\n### Third-party re-implementation\n- PyTorch: [code](https:\u002F\u002Fgithub.com\u002Fclcarwin\u002Fsphereface_pytorch) by [clcarwin](https:\u002F\u002Fgithub.com\u002Fclcarwin).\n- PyTorch: [code](https:\u002F\u002Fgithub.com\u002FJoyako\u002FSphereFace-pytorch) by [Joyako](https:\u002F\u002Fgithub.com\u002FJoyako).\n- TensorFlow: [code](https:\u002F\u002Fgithub.com\u002Fpppoe\u002Ftensorflow-sphereface-asoftmax) by [pppoe](https:\u002F\u002Fgithub.com\u002Fpppoe).\n- TensorFlow (with awesome animations): [code](https:\u002F\u002Fgithub.com\u002FYunYang1994\u002FSphereFace) by [YunYang1994](https:\u002F\u002Fgithub.com\u002FYunYang1994).\n- TensorFlow: [code](https:\u002F\u002Fgithub.com\u002Fhujun100\u002Ftensorflow-sphereface) by [hujun100](https:\u002F\u002Fgithub.com\u002Fhujun100).\n- TensorFlow: [code](https:\u002F\u002Fgithub.com\u002FHiKapok\u002Ftf.extra_losses) by [HiKapok](https:\u002F\u002Fgithub.com\u002FHiKapok).\n- TensorFlow: [code](https:\u002F\u002Fgithub.com\u002Fandrewhuman\u002Fsphereloss_tensorflow) by [andrewhuman](https:\u002F\u002Fgithub.com\u002Fandrewhuman).\n- MXNet: [code](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface) by [deepinsight](https:\u002F\u002Fgithub.com\u002Fdeepinsight) (by setting loss-type=1: SphereFace).\n- Model compression for SphereFace: [code](https:\u002F\u002Fgithub.com\u002Fisthatyoung\u002FSphereface-prune) by [Siyang Liu](https:\u002F\u002Fgithub.com\u002Fisthatyoung) (useful in practice)\n- Caffe2: [code](https:\u002F\u002Fgithub.com\u002Ftpys\u002Fface-recognition-caffe2) by [tpys](https:\u002F\u002Fgithub.com\u002Ftpys).\n- Trained on MS-1M: [code](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN\u002FSphereface-Ms-celeb-1M) by [KaleidoZhouYN](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN).\n- System: [A cool face demo system](https:\u002F\u002Fgithub.com\u002Ftpys\u002Fface-everthing) using SphereFace by [tpys](https:\u002F\u002Fgithub.com\u002Ftpys).\n- Third-party pretrained models: [code](https:\u002F\u002Fgithub.com\u002Fgoodluckcwl\u002FSphereface-model) by [goodluckcwl](https:\u002F\u002Fgithub.com\u002Fgoodluckcwl).\n\n### Resources for angular margin learning\n\n[L-Softmax loss](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss) and [SphereFace](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface) present a promising framework for angular representation learning, which is shown very effective in deep face recognition. We are super excited that our works has inspired many well-performing methods (and loss functions). We list a few of them for your potential reference (not very up-to-date):\n\n- Additive margin softmax: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.05599) and [code](https:\u002F\u002Fgithub.com\u002Fhappynear\u002FAMSoftmax)\n- CosFace: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.09414)\n- ArcFace\u002FInsightFace: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.07698) and [code](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface)\n- NormFace: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.06369) and [code](https:\u002F\u002Fgithub.com\u002Fhappynear\u002FNormFace)\n- L2-Softmax: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.09507)\n- von Mises-Fisher Mixture Model: [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F1706.04264)\n- COCO loss: [paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1710.00870.pdf) and [code](https:\u002F\u002Fgithub.com\u002Fsciencefans\u002Fcoco_loss)\n- Angular Triplet Loss: [code](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN\u002FAngular-Triplet-Loss)\n\nTo evaluate the effectiveness of the angular margin learning method, you may consider to use the **angular Fisher score** proposed in [the Appendix E of our SphereFace Paper](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf).\n\nDisclaimer: Some of these methods may not necessarily be inspired by us, but we still list them due to its relevance and excellence.\n\n### Contact\n\n  [Weiyang Liu](https:\u002F\u002Fwyliu.com) and [Yandong Wen](https:\u002F\u002Fydwen.github.io)\n\n  Questions can also be left as issues in the repository. We will be happy to answer them.\n","# *SphereFace*: 用于人脸识别的深度超球嵌入\n\n作者：刘伟阳、温彦东、于志德、李明、Bhiksha Raj 和 宋乐\n\n### 许可证\n\nSphereFace 根据 MIT 许可证发布（详情请参阅 LICENSE 文件）。\n\n### 更新\n- **2022年4月10日**：**如果您正在寻找一个易于使用且性能优异的 SphereFace PyTorch 实现，我们现在有了！请查看我们的官方 SphereFace PyTorch 重实现 [这里](https:\u002F\u002Fopensphere.world\u002F)。**\n- **2018年8月14日**：我们推荐一篇有趣的 ECCV 2018 论文，该论文全面评估了 SphereFace（A-Softmax）在当前广泛使用的人脸数据集以及他们提出的噪声可控 IMDb-Face 数据集上的表现。感兴趣的用户可以尝试在自己的 IMDb-Face 数据集上训练 SphereFace。请参阅 [这里](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1807.11649.pdf)。\n- **2018年5月23日**：我们在技术报告中提出了一种显式增强类间可分性的新方法 *SphereFace+*。请查看 [这里](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09298)。代码已发布 [这里](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface-plus)。\n- **2018年2月1日**：应要求，发布了 SphereFace-64 的 prototxt 文件。\n- **2018年1月27日**：我们更新了 SphereFace 论文的附录，增加了有用的实验和分析。请参阅 [这里](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf)。内容包括：\n\t- 去除最后一个 ReLU 的直观解释；\n\t- 为什么我们要对权重进行归一化，而不仅仅是为了获得更多的几何解释？\n\t- 将偏置置零的实证实验；\n\t- 更多关于 MNIST 数据集上 A-Softmax 损失的二维可视化；\n\t- **角度 Fisher 分数**，用于评估特征的角度判别能力，这是一种新的、直接的评估指标，不同于最终的准确率。\n\t- 在 MegaFace 数据集上使用不同卷积层的 SphereFace 实验；\n\t- A-Softmax 损失的退火优化策略；\n\t- MegaFace 挑战赛中 3 片拼接集成策略的详细说明；\n\n- **2018年1月20日**：我们更新了一些资源，以总结目前角度间隔学习领域的最新进展。请参阅 [这里](#resources-for-angular-margin-learning)。\n\n### 目录\n0. [简介](#introduction)\n0. [引用](#citation)\n0. [要求](#requirements)\n0. [安装](#installation)\n0. [使用](#usage)\n0. [模型](#models)\n0. [结果](#results)\n0. [视频演示](#video-demo)\n0. [注释](#note)\n0. [第三方重实现](#third-party-re-implementation)\n0. [角度间隔学习资源](#resources-for-angular-margin-learning)\n\n\n### 简介\n\n该仓库包含了使用 **`SphereFace`** 进行深度人脸识别的完整流程（包括所有预处理步骤）。识别流程主要分为三个步骤：人脸检测、人脸对齐和人脸识别。\n\nSphereFace 是一种最近提出的人脸识别方法。它最初发表在一篇 [arXiv 技术报告](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.08063) 中，随后又在 [CVPR 2017](http:\u002F\u002Fopenaccess.thecvf.com\u002Fcontent_cvpr_2017\u002Fpapers\u002FLiu_SphereFace_Deep_Hypersphere_CVPR_2017_paper.pdf) 上发表。包含更多实验的最新论文可以在 [arXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.08063) 或 [这里](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf) 找到。为了方便人脸识别研究，我们提供了一个使用论文中描述的 **20 层 CNN 架构**（即 SphereFace-20）在 [CAISA-WebFace](http:\u002F\u002Fwww.cbsr.ia.ac.cn\u002Fenglish\u002FCASIA-WebFace-Database.html) 上训练，并在 [LFW](http:\u002F\u002Fvis-www.cs.umass.edu\u002Flfw\u002F) 上测试的示例。\n\n在 SphereFace 中，我们的网络架构以残差单元为基本构建块，但与标准 ResNet 有很大不同（例如，未使用 BatchNorm，用 PReLU 替代 ReLU，初始化方式也不同等）。我们提出了用于人脸识别的 4 层、20 层、36 层和 64 层架构（详细信息可在 [论文]((https:\u002F\u002Farxiv.org\u002Fpdf\u002F1704.08063.pdf)) 和 [prototxt 文件](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fblob\u002Fmaster\u002Ftrain\u002Fcode\u002Fsphereface_model.prototxt) 中找到）。我们在此提供了 20 层架构作为示例。如果我们的架构对您的研究有所帮助，请考虑引用我们的论文。\n\n在小规模训练集协议下，SphereFace 在 [MegaFace 挑战赛](http:\u002F\u002Fmegaface.cs.washington.edu\u002Fresults\u002Ffacescrub.html#3) 中达到了当时最先进的验证性能（此前排名第一）\n\n\n### 引用\n如果您在研究中发现 **SphereFace** 很有用，请考虑引用：\n\n\t@InProceedings{Liu_2017_CVPR,\n\t  title = {SphereFace: 用于人脸识别的深度超球嵌入},\n\t  author = {刘伟阳、温彦东、于志德、李明、Bhiksha Raj 和 宋乐},\n\t  booktitle = {IEEE 计算机视觉与模式识别会议 (CVPR)},\n\t  year = {2017}\n\t}\n\n我们另一项密切相关的 ICML'16 工作（[更多信息](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss))：\n\n\t@InProceedings{Liu_2016_ICML,\n\t  title = {卷积神经网络的大间隔 Softmax 损失},\n\t  author = {刘伟阳、温彦东、于志德、杨萌},\n\t  booktitle = {第 33 届国际机器学习大会论文集},\n\t  year = {2016}\n\t}\n\n\n### 要求\n1. `Matlab` 的要求\n2. `Caffe` 和 `matcaffe` 的要求（详见：[Caffe 安装说明](http:\u002F\u002Fcaffe.berkeleyvision.org\u002Finstallation.html)）\n3. `MTCNN` 的要求（详见：[MTCNN - 人脸检测与对齐](https:\u002F\u002Fgithub.com\u002Fkpzhang93\u002FMTCNN_face_detection_alignment)) 和 `Pdollar toolbox` 的要求（详见：[Piotr 的图像与视频 Matlab 工具箱](https:\u002F\u002Fgithub.com\u002Fpdollar\u002Ftoolbox)）。\n\n### 安装\n1. 克隆 SphereFace 仓库。我们将您克隆的目录称为 **`SPHEREFACE_ROOT`**。\n\n    ```Shell\n    git clone --recursive https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface.git\n    ```\n\n2. 构建 Caffe 和 matcaffe\n\n    ```Shell\n    cd $SPHEREFACE_ROOT\u002Ftools\u002Fcaffe-sphereface\n    # 现在按照这里的 Caffe 安装说明进行操作：\n    # http:\u002F\u002Fcaffe.berkeleyvision.org\u002Finstallation.html\n    make all -j8 && make matcaffe\n    ```\n\n### 使用方法\n\n*在成功完成[安装](#installation)后*，您就可以运行以下所有实验了。\n\n#### 第一部分：预处理\n**注意**：在此部分中，我们假设您位于目录 **`$SPHEREFACE_ROOT\u002Fpreprocess\u002F`** 下。\n1. 下载训练集（`CASIA-WebFace`）和测试集（`LFW`），并将它们放置在 **`data\u002F`** 目录中。\n\n\t```Shell\n\tmv \u002Fyour_path\u002FCASIA_WebFace  data\u002F\n\t.\u002Fcode\u002Fget_lfw.sh\n\ttar xvf data\u002Flfw.tgz -C data\u002F\n\t```\n    请确保 **`data\u002F`** 目录下包含这两个数据集。\n    \n2. 使用 `MTCNN` 检测 CAISA-WebFace 和 LFW 数据集中的人脸及面部关键点（参见：[MTCNN - 人脸检测与对齐](https:\u002F\u002Fgithub.com\u002Fkpzhang93\u002FMTCNN_face_detection_alignment))。\n\n\t```Matlab\n\t# 在 Matlab 命令窗口中\n\trun code\u002Fface_detect_demo.m\n\t```\n    这将生成一个文件 `dataList.mat`，位于 **`result\u002F`** 目录中。\n3. 使用相似变换将人脸对齐到标准姿态。\n\n\t```Matlab\n\t# 在 Matlab 命令窗口中\n  \trun code\u002Fface_align_demo.m\n  \t```\n    这将创建两个文件夹（**`CASIA-WebFace-112X96\u002F`** 和 **`lfw-112X96\u002F`**），位于 **`result\u002F`** 目录中，其中包含对齐后的 face 图像。\n\n#### 第二部分：训练\n**注意**：在此部分中，我们假设您位于目录 **`$SPHEREFACE_ROOT\u002Ftrain\u002F`** 下。\n\n1. 获取训练图像和标签的列表。\n\n\t```Shell&Matlab\n\tmv ..\u002Fpreprocess\u002Fresult\u002FCASIA-WebFace-112X96 data\u002F\n\t# 在 Matlab 命令窗口中\n\trun code\u002Fget_list.m\n\t```\n    对齐后的 face 图像从 ***preprocess*** 文件夹移动到 ***train*** 文件夹。同时，在 **`data\u002F`** 目录下会生成一个名为 `CASIA-WebFace-112X96.txt` 的列表文件，用于后续的训练。\n    \n2. 训练 sphereface 模型。\n\n\t```Shell\n\t.\u002Fcode\u002Fsphereface_train.sh 0,1\n\t```\n    训练完成后，模型文件 `sphereface_model_iter_28000.caffemodel` 和对应的日志文件 `sphereface_train.log` 将被放置在 **`result\u002Fsphereface\u002F`** 目录中。\n\n#### 第三部分：测试\n**注意**：在此部分中，我们假设您位于目录 **`$SPHEREFACE_ROOT\u002Ftest\u002F`** 下。\n\n1. 获取 LFW 的配对列表（[查看 2](http:\u002F\u002Fvis-www.cs.umass.edu\u002Flfw\u002F#views))。\n\n\t```Shell\n\tmv ..\u002Fpreprocess\u002Fresult\u002Flfw-112X96 data\u002F\n\t.\u002Fcode\u002Fget_pairs.sh\n\t```\n\t确保 LFW 数据集和 `pairs.txt` 文件都位于 **`data\u002F`** 目录中。\n\n1. 提取深度特征并在 LFW 上进行测试。\n\n\t```Matlab\n\t# 在 Matlab 命令窗口中\n\trun code\u002Fevaluation.m\n\t```\n    最终我们会得到 `sphereface_model.caffemodel`、提取的特征 `pairs.mat`（位于 **`result\u002F`** 文件夹中），以及在 LFW 上的准确率如下：\n\n\tfold|1|2|3|4|5|6|7|8|9|10|AVE\n\t:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:\n\tACC|99.33%|99.17%|98.83%|99.50%|99.17%|99.83%|99.17%|98.83%|99.83%|99.33%|99.30%\n\n### 模型\n1. 网络架构可视化（工具来自 [ethereon](http:\u002F\u002Fethereon.github.io\u002Fnetscope\u002Fquickstart.html)）：\n\t- SphereFace-20：[链接](http:\u002F\u002Fethereon.github.io\u002Fnetscope\u002F#\u002Fgist\u002F20f6ddf70a35dec5019a539a502bccc5)\n2. 模型文件\n\t- SphereFace-20：[Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegb2F6dmlmOXhWaVk) | [百度网盘](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1qY5FTF2)\n\t- 第三方提供的 SphereFace-4 和 SphereFace-6：[这里](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F81)，由 [zuoqing1988](https:\u002F\u002Fgithub.com\u002Fzuoqing1988) 提供\n\n\n### 结果\n1. 按照说明，我们完整地执行了整个流程五次。以下是我们在 LFW 上的准确率。总体而言，我们报告的是平均值，但此处发布了 [model-3](#models)。\n\n\t实验 |#1|#2|#3 (已发布)|#4|#5\n\t:---:|:---:|:---:|:---:|:---:|:---:\n\tACC|99.24%|99.20%|**99.30%**|99.27%|99.13%\n\n2. 其他中间结果：\n    - LFW 特征：[Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegenU0cGJYZmlRUlU) | [百度网盘](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1o8QIMUY)\n    - 训练日志：[Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegcWkxdVV4X1FOaFU) | [百度网盘](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1i5QmXrJ)\n\n\n\n### 视频演示\n[![SphereFace 演示](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fwy1iu_sphereface_readme_d8ab9c46fa65.jpg)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=P6jEzzwoYWs)\n\n请点击图片观看 YouTube 视频。对于优酷用户，请点击[这里](http:\u002F\u002Ft.cn\u002FRCZ0w1c)。\n\n详细信息：\n1. 这是一个**开放集**人脸识别场景。视频按帧处理，遵循本仓库中的相同流程。\n2. 库集合包含 6 个身份。每个主要角色仅有一张库集合中的 face 图像。所有检测到的 face 都被纳入探测集合。\n3. 库集合与训练集（CASIA-WebFace）之间没有重叠。\n4. 每个探测 face 与库集合之间的得分是通过余弦相似度计算的。如果某个探测 face 的最高得分低于预定义的阈值，则该探测 face 将被视为异常值。\n5. 主要角色用不同颜色的框标注。（\n![#ff0000](https:\u002F\u002Fplacehold.it\u002F15\u002Fff0000\u002F000000?text=+)瑞秋，\n![#ffff00](https:\u002F\u002Fplacehold.it\u002F15\u002Fffff00\u002F000000?text=+)莫妮卡，\n![#ff80ff](https:\u002F\u002Fplacehold.it\u002F15\u002Fff80ff\u002F000000?text=+)菲比，\n![#00ffff](https:\u002F\u002Fplacehold.it\u002F15\u002F00ffff\u002F000000?text=+)乔伊，\n![#0000ff](https:\u002F\u002Fplacehold.it\u002F15\u002F0000ff\u002F000000?text=+)钱德勒，\n![#00ff00](https:\u002F\u002Fplacehold.it\u002F15\u002F00ff00\u002F000000?text=+)罗斯）\n\n### 注释\n1. **反向梯度**\n\t- 在本次实现中，我们并未严格遵循论文中的公式。相反，我们对梯度的尺度进行了归一化处理。这可以被理解为一种动态调整学习率的策略，有助于更稳定地收敛。类似的想法和直觉也出现在[归一化梯度](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1707.04822.pdf)和[投影梯度下降](https:\u002F\u002Fwww.stats.ox.ac.uk\u002F~lienart\u002Fblog_opti_pgd.html)中。\n\t- 更具体地说，如果函数 ***f*** 关于 ***x*** 的原始梯度可以表示为 **df\u002Fdx = coeff_w \\*  w + coeff_x \\* x**，那么我们在反向传播时会使用归一化的版本 **[df\u002Fdx] = (coeff_w \\* w + coeff_x \\* x) \u002F norm_wx**，其中 **norm_wx** 是 **sqrt(coeff_w^2 + coeff_x^2)**。同样的操作也应用于 ***f*** 关于 ***w*** 的梯度。\n\t- 实际上，你并不一定需要使用原始梯度，因为原始梯度有时并不是最优的设计。修改反向传播梯度的一个重要标准是，新的“梯度”（严格来说，它已经不再是梯度了）需要能够稳定且持续地降低目标函数值。（关于基于梯度的反向传播的一些失败案例，我推荐观看由[Shai Shalev-Shwartz](https:\u002F\u002Fwww.cs.huji.ac.il\u002F~shais\u002F)所作的[精彩演讲](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=jWVZnkTfB3c)）\n\t- 如果你使用原始梯度进行反向传播，仍然可以使其工作，但可能需要调整不同的 lambda 参数设置、迭代次数以及学习率衰减策略。\n\n2. **Lambda** 和 **训练注意事项（当损失变为 87 时）**\n\t- 请参考我们之前的[注释与说明](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss#notes-for-training)。\n\n3. **根据最新进展，使用带有可调缩放参数 s 的特征归一化可以显著提升 SphereFace 在 MegaFace 挑战赛上的性能**\n\t- 这一点得到了[CosFace](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.09414)实验的支持。类似的思想也出现在[加性间隔 softmax](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.05599)中。\n\n4. **收敛困难**\n        - 当你在收敛过程中遇到困难时（例如在其他数据集上使用 *SphereFace* 时可能会出现这种情况），通常有几种简单的方法可以解决。\n\t- 首先，尝试使用较大的小批量大小。\n\t- 其次，尝试使用 PReLU 而不是 ReLU。\n\t- 第三，增加网络的宽度和深度。\n\t- 第四，尝试使用更好的初始化方法。例如，使用从原始 softmax 损失中预训练得到的模型（这也相当于微调）。\n\t- 最后，也是最有效的方法，就是调整 lambda_min、lambda 及其衰减速率等超参数。\n\n\n### 第三方重实现\n- PyTorch：由 [clcarwin](https:\u002F\u002Fgithub.com\u002Fclcarwin) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fclcarwin\u002Fsphereface_pytorch)。\n- PyTorch：由 [Joyako](https:\u002F\u002Fgithub.com\u002FJoyako) 提供的 [代码](https:\u002F\u002Fgithub.com\u002FJoyako\u002FSphereFace-pytorch)。\n- TensorFlow：由 [pppoe](https:\u002F\u002Fgithub.com\u002Fpppoe) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fpppoe\u002Ftensorflow-sphereface-asoftmax)。\n- TensorFlow（附带精彩动画）：由 [YunYang1994](https:\u002F\u002Fgithub.com\u002FYunYang1994) 提供的 [代码](https:\u002F\u002Fgithub.com\u002FYunYang1994\u002FSphereFace)。\n- TensorFlow：由 [hujun100](https:\u002F\u002Fgithub.com\u002Fhujun100) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fhujun100\u002Ftensorflow-sphereface)。\n- TensorFlow：由 [HiKapok](https:\u002F\u002Fgithub.com\u002FHiKapok) 提供的 [代码](https:\u002F\u002Fgithub.com\u002FHiKapok\u002Ftf.extra_losses)。\n- TensorFlow：由 [andrewhuman](https:\u002F\u002Fgithub.com\u002Fandrewhuman) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fandrewhuman\u002Fsphereloss_tensorflow)。\n- MXNet：由 [deepinsight](https:\u002F\u002Fgithub.com\u002Fdeepinsight) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface)，通过设置 loss-type=1: SphereFace。\n- SphereFace 的模型压缩：由 [Siyang Liu](https:\u002F\u002Fgithub.com\u002Fisthatyoung) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fisthatyoung\u002FSphereface-prune)（在实际应用中非常有用）。\n- Caffe2：由 [tpys](https:\u002F\u002Fgithub.com\u002Ftpys) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Ftpys\u002Fface-recognition-caffe2)。\n- 基于 MS-1M 数据集训练：由 [KaleidoZhouYN](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN) 提供的 [代码](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN\u002FSphereface-Ms-celeb-1M)。\n- 系统：由 [tpys](https:\u002F\u002Fgithub.com\u002Ftpys) 使用 SphereFace 构建的[酷炫的人脸演示系统](https:\u002F\u002Fgithub.com\u002Ftpys\u002Fface-everthing)。\n- 第三方预训练模型：由 [goodluckcwl](https:\u002F\u002Fgithub.com\u002Fgoodluckcwl) 提供的 [代码](https:\u002F\u002Fgithub.com\u002Fgoodluckcwl\u002FSphereface-model)。\n\n### 角度间隔学习相关资源\n\n[L-Softmax 损失](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002FLargeMargin_Softmax_Loss)和[SphereFace](https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface)为角度表示学习提供了一个很有前景的框架，在深度人脸识别任务中表现出极高的有效性。我们非常高兴的是，我们的工作启发了许多表现优异的方法（以及损失函数）。以下列出其中一些供您参考（可能并非最新）：\n\n- 加性间隔 softmax：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.05599)和[代码](https:\u002F\u002Fgithub.com\u002Fhappynear\u002FAMSoftmax)。\n- CosFace：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.09414)。\n- ArcFace\u002FInsightFace：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1801.07698)和[代码](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface)。\n- NormFace：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.06369)和[代码](https:\u002F\u002Fgithub.com\u002Fhappynear\u002FNormFace)。\n- L2-Softmax：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.09507)。\n- 冯·米塞斯-费舍尔混合模型：[论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F1706.04264)。\n- COCO 损失：[论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1710.00870.pdf)和[代码](https:\u002F\u002Fgithub.com\u002Fsciencefans\u002Fcoco_loss)。\n- 角度三元组损失：[代码](https:\u002F\u002Fgithub.com\u002FKaleidoZhouYN\u002FAngular-Triplet-Loss)。\n\n为了评估角度间隔学习方法的有效性，您可以考虑使用我们在[SphereFace 论文的附录 E 中提出的角 Fisher 分数](http:\u002F\u002Fwyliu.com\u002Fpapers\u002FLiuCVPR17v3.pdf)。\n\n免责声明：其中一些方法可能并非直接受到我们的启发，但我们仍将其列出，以体现其相关性和卓越性。\n\n### 联系方式\n\n  [Weiyang Liu](https:\u002F\u002Fwyliu.com) 和 [Yandong Wen](https:\u002F\u002Fydwen.github.io)\n\n  您也可以在仓库中留下问题，我们将很乐意为您解答。","# SphereFace 快速上手指南\n\nSphereFace 是一种基于深度超球面嵌入的人脸识别方法，通过引入角度间隔损失（A-Softmax Loss）显著提升了人脸识别的精度。本指南基于官方 Caffe 实现，帮助开发者快速完成环境搭建、模型训练与测试。\n\n## 环境准备\n\n在开始之前，请确保您的系统满足以下要求：\n\n*   **操作系统**: Linux (推荐 Ubuntu)\n*   **核心依赖**:\n    *   **Matlab**: 用于数据预处理和结果评估。\n    *   **Caffe & matcaffe**: 深度学习框架及其 Matlab 接口。\n    *   **MTCNN**: 用于人脸检测与关键点定位 ([GitHub 链接](https:\u002F\u002Fgithub.com\u002Fkpzhang93\u002FMTCNN_face_detection_alignment))。\n    *   **Piotr's Toolbox**: Matlab 图像工具箱 ([GitHub 链接](https:\u002F\u002Fgithub.com\u002Fpdollar\u002Ftoolbox))。\n*   **硬件**: 建议配备 NVIDIA GPU 以加速训练过程。\n\n> **注意**：官方仓库主要基于 Caffe 框架。如果您寻求更易用的 PyTorch 版本，官方已发布重实现版本，请访问 [opensphere.world](https:\u002F\u002Fopensphere.world\u002F)。本指南仅针对原始 Caffe 版本。\n\n## 安装步骤\n\n### 1. 克隆仓库\n首先克隆 SphereFace 代码库（包含子模块），我们将该目录称为 `SPHEREFACE_ROOT`。\n\n```Shell\ngit clone --recursive https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface.git\ncd sphereface\nexport SPHEREFACE_ROOT=$(pwd)\n```\n\n### 2. 编译 Caffe\n进入工具目录并编译 Caffe 及 matcaffe 接口。请确保已安装 Caffe 所需的基础依赖（如 CUDA, cuDNN, OpenCV 等）。\n\n```Shell\ncd $SPHEREFACE_ROOT\u002Ftools\u002Fcaffe-sphereface\n# 参考 Caffe 官方安装说明配置 Makefile.config (如有需要)\n# http:\u002F\u002Fcaffe.berkeleyvision.org\u002Finstallation.html\n\nmake all -j8 && make matcaffe\n```\n\n### 3. 配置 Matlab 路径\n启动 Matlab，将 MTCNN 和 Piotr's Toolbox 添加到 Matlab 搜索路径中，以便后续运行预处理脚本。\n\n## 基本使用\n\n以下流程涵盖从数据预处理、模型训练到测试评估的完整闭环。示例使用 CASIA-WebFace 数据集进行训练，并在 LFW 数据集上进行测试。\n\n### 第一步：数据预处理 (Preprocessing)\n\n进入预处理目录，准备数据并进行人脸对齐。\n\n1.  **准备数据集**\n    下载 [CASIA-WebFace](http:\u002F\u002Fwww.cbsr.ia.ac.cn\u002Fenglish\u002FCASIA-WebFace-Database.html) 和 [LFW](http:\u002F\u002Fvis-www.cs.umass.edu\u002Flfw\u002F) 数据集，并按以下方式组织：\n\n    ```Shell\n    cd $SPHEREFACE_ROOT\u002Fpreprocess\u002F\n    mv \u002Fyour_path\u002FCASIA_WebFace data\u002F\n    .\u002Fcode\u002Fget_lfw.sh\n    tar xvf data\u002Flfw.tgz -C data\u002F\n    ```\n\n2.  **人脸检测与关键点定位**\n    在 Matlab 命令行窗口中运行检测脚本（需确保 MTCNN 已在路径中）：\n\n    ```Matlab\n    % 在 Matlab Command Window 中执行\n    run code\u002Fface_detect_demo.m\n    ```\n    *执行后将生成 `result\u002FdataList.mat`。*\n\n3.  **人脸对齐**\n    运行对齐脚本，将人脸裁剪并归一化为 112x96 尺寸：\n\n    ```Matlab\n    % 在 Matlab Command Window 中执行\n    run code\u002Fface_align_demo.m\n    ```\n    *执行后将在 `result\u002F` 目录下生成 `CASIA-WebFace-112X96\u002F` 和 `lfw-112X96\u002F` 文件夹。*\n\n### 第二步：模型训练 (Train)\n\n进入训练目录，生成训练列表并启动训练。\n\n1.  **生成训练列表**\n    将对齐后的训练数据移至训练目录并生成列表文件：\n\n    ```Shell\n    cd $SPHEREFACE_ROOT\u002Ftrain\u002F\n    mv ..\u002Fpreprocess\u002Fresult\u002FCASIA-WebFace-112X96 data\u002F\n    ```\n\n    然后在 Matlab 中运行：\n    ```Matlab\n    % 在 Matlab Command Window 中执行\n    run code\u002Fget_list.m\n    ```\n\n2.  **开始训练**\n    使用提供的脚本启动训练（示例使用 GPU 0 和 1）：\n\n    ```Shell\n    .\u002Fcode\u002Fsphereface_train.sh 0,1\n    ```\n    *训练完成后，模型文件 `sphereface_model_iter_28000.caffemodel` 和日志将保存在 `result\u002Fsphereface\u002F` 目录中。*\n\n    > **提示**：如需直接下载使用预训练模型，可访问 [Google Drive](https:\u002F\u002Fdrive.google.com\u002Fopen?id=0B_geeR2lTMegb2F6dmlmOXhWaVk) 或 [百度网盘](http:\u002F\u002Fpan.baidu.com\u002Fs\u002F1qY5FTF2) 获取 SphereFace-20 模型。\n\n### 第三步：模型测试 (Test)\n\n进入测试目录，在 LFW 数据集上评估模型性能。\n\n1.  **准备测试数据对**\n    将对齐后的 LFW 数据移至测试目录并生成配对列表：\n\n    ```Shell\n    cd $SPHEREFACE_ROOT\u002Ftest\u002F\n    mv ..\u002Fpreprocess\u002Fresult\u002Flfw-112X96 data\u002F\n    .\u002Fcode\u002Fget_pairs.sh\n    ```\n\n2.  **提取特征并评估**\n    在 Matlab 中运行评估脚本：\n\n    ```Matlab\n    % 在 Matlab Command Window 中执行\n    run code\u002Fevaluation.m\n    ```\n\n    脚本运行结束后，将输出 LFW 上的准确率（通常可达 99.30% 左右），并在 `result\u002F` 目录下生成特征文件 `pairs.mat`。","某安防科技公司的算法团队正在为大型园区的门禁系统升级人脸识别模块，旨在解决复杂光照和角度下员工识别率低的问题。\n\n### 没有 sphereface 时\n- **特征区分度不足**：传统软最大值（Softmax）损失函数仅关注分类正确性，导致不同人脸在特征空间中的夹角区分不明显，难以分辨长相相似的同事。\n- **姿态鲁棒性差**：当员工侧身或低头刷卡时，由于缺乏对角度边界的显式约束，模型极易将同一人的不同角度误判为不同身份。\n- **误识率居高不下**：在百万级底库检索中，因特征分布不够紧凑，系统频繁出现将陌生人误认成授权人员的“假阳性”警报。\n- **调优依赖经验**：工程师不得不花费大量时间手动调整阈值和数据增强策略，却难以从几何本质上提升模型的判别能力。\n\n### 使用 sphereface 后\n- **超球面嵌入增强**：sphereface 引入深度超球面嵌入技术，通过角间隔损失函数（A-Softmax）强制拉大不同类别间的角度距离，显著提升了相似人脸的区分度。\n- **几何一致性提升**：利用归一化权重和偏置为零的策略，模型在超球面上学习到更具几何解释性的特征，即使在大角度姿态下也能精准锁定同一身份。\n- **类间分离性优化**：借助其特有的角费雪评分（Angular Fisher score）指导训练，特征分布更加紧凑，大幅降低了高并发场景下的误识率。\n- **端到端流程简化**：直接复用官方提供的包含检测、对齐到识别的完整流水线，团队无需重复造轮子即可在 CASIA-WebFace 等数据集上复现 SOTA 效果。\n\nsphereface 通过将人脸识别问题转化为超球面上的角度度量学习，从根本上解决了传统方法在特征判别性和几何鲁棒性上的瓶颈。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fwy1iu_sphereface_a3a9db93.png","wy1iu","Weiyang Liu","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fwy1iu_262b391e.jpg","Jialidun",null,"Future Gadget Laboratory","Besteuler","https:\u002F\u002Fwyliu.com\u002F","https:\u002F\u002Fgithub.com\u002Fwy1iu",[85,89,93,97,101,105,109,113,116,120],{"name":86,"color":87,"percentage":88},"Jupyter Notebook","#DA5B0B",57.9,{"name":90,"color":91,"percentage":92},"C++","#f34b7d",33.1,{"name":94,"color":95,"percentage":96},"Python","#3572A5",4.1,{"name":98,"color":99,"percentage":100},"Cuda","#3A4E3A",2.5,{"name":102,"color":103,"percentage":104},"CMake","#DA3434",1.2,{"name":106,"color":107,"percentage":108},"MATLAB","#e16737",0.5,{"name":110,"color":111,"percentage":112},"Shell","#89e051",0.3,{"name":114,"color":115,"percentage":112},"Makefile","#427819",{"name":117,"color":118,"percentage":119},"CSS","#663399",0.1,{"name":121,"color":122,"percentage":119},"HTML","#e34c26",1603,533,"2026-03-31T10:38:53","MIT",4,"Linux","需要支持 CUDA 的 NVIDIA GPU（具体型号和显存未说明，需自行配置 Caffe CUDA 版本）","未说明",{"notes":132,"python":133,"dependencies":134},"该项目原始实现主要依赖 Matlab 和 Caffe 框架，而非 Python。安装步骤包括克隆仓库、编译 Caffe 及 matcaffe 接口。预处理（人脸检测与对齐）需在 Matlab 环境中运行 MTCNN 和相关工具箱脚本。训练和测试通过 Shell 脚本调用编译好的 Caffe 二进制文件执行。README 中提到的 PyTorch 版本为第三方或后续重新实现，需访问外部链接获取，当前文档主要针对 Caffe\u002FMatlab 版本。","未说明 (主要基于 Matlab 和 C++)",[135,136,137,138,139],"Matlab","Caffe","matcaffe","MTCNN (Matlab 版)","Piotr's Image & Video Matlab Toolbox",[13,14],[142,143,67,144,145,146,147],"face-recognition","caffe","cvpr-2017","face-detection","angular-softmax","deep-learning","2026-03-27T02:49:30.150509","2026-04-06T05:36:33.751321",[151,156,161,166,171,176,181],{"id":152,"question_zh":153,"answer_zh":154,"source_url":155},13322,"运行默认配置时，预期的 LFW 准确率是多少？如果损失不下降或准确率低可能是什么原因？","默认配置的批量大小（batch size）为每张 GPU 256，有效批量大小为 512。如果修改了批量大小，可能会导致损失不下降。此外，早期版本的评估脚本中存在 Bug 可能导致准确率偏低，该问题已在后续版本中修复。建议严格使用推荐的批量大小（512）并更新到最新代码。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F3",{"id":157,"question_zh":158,"answer_zh":159,"source_url":160},13323,"人脸对齐使用的 5 个坐标点是如何获取的？它们是基于原始图像还是裁剪后的图像？","这 5 个点的具体绝对位置并不重要，重要的是它们之间的相对位置关系。通常的做法是：使用地标检测器（如 dlib 的 68 点检测器）处理一组已裁剪对齐的人脸图像，计算这些面部关键点的平均位置作为参考点。如果您有 68 点检测器，可以将其映射到所需的 5 点标准位置来进行变换。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F53",{"id":162,"question_zh":163,"answer_zh":164,"source_url":165},13324,"训练时损失值一直停留在 9.3 左右不下降，应该如何解决？","这是因为在测试阶段错误地使用了带边距的损失层。Large Margin Softmax 的一个技巧是：在训练时使用 `MarginInnerProduct` 层（type: QUADRUPLE 等），但在测试时必须切换回传统的 `InnerProduct` 层（type: SINGLE），并将学习率倍数（lr_mult）设为 0 以冻结参数。请检查您的 prototxt 文件，确保测试阶段（phase: TEST）使用的是普通全连接层而非边距层。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F7",{"id":167,"question_zh":168,"answer_zh":169,"source_url":170},13325,"训练 CASIA-WebFace 数据集时，应该使用清洗后的列表（clean_list）还是所有图像？去除与 LFW 重叠的身份会影响结果吗？","对于 LFW 测试集，去除重叠身份对结果影响不大，因为 LFW 包含超过 10,000 个身份，少量重叠可忽略。但是，如果在 MegaFace 等较小测试集上评估，重叠身份的影响会非常显著（例如 FaceScrub set1 中超过一半身份可能重叠），去除后性能会大幅下降。因此，复现论文结果时需注意测试集的选择。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F26",{"id":172,"question_zh":173,"answer_zh":174,"source_url":175},13326,"L-SoftMax 和 A-SoftMax 的主要区别是什么？为什么选择特定的 ψ 函数？","主要区别在于权重的处理方式：L-SoftMax 将权重转换为权重的范数，而 A-SoftMax 将权重转换为归一化权重。ψ 函数的选择是为了替代 cos(θ) 以引入角度边距。实现中使用了泰勒展开式来近似 cos(mθ)，并根据边距值 m 使用不同阶数的级数，这是为了在保证精度的同时优化计算效率。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F1",{"id":177,"question_zh":178,"answer_zh":179,"source_url":180},13327,"论文中提到的多补丁（Multi-patch）方法和镜像（Mirroring）策略具体是如何实现的？","多补丁特征向量是通过拼接每个补丁的特征向量形成的。虽然论文未详述补丁生成细节，但通常做法是对原始图像进行微小的偏移变换或采用不同的对齐策略来提取多个补丁，然后使用同一个网络提取特征。关于镜像，有用户实验发现不拼接镜像图像的特征有时能获得更好的结果，具体策略可根据实际数据集调整。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F19",{"id":182,"question_zh":183,"answer_zh":184,"source_url":185},13328,"参数 lambda 是否等价于更小的 m 值？","从损失函数的形式来看，添加 lambda 可以被视为一种线性插值函数。例如，`lambda=5, m=4` 的曲线表现大约等同于 `m=1.5` 的效果。这表明 lambda 起到了调节边距强度的作用，类似于减小 m 值带来的效果。","https:\u002F\u002Fgithub.com\u002Fwy1iu\u002Fsphereface\u002Fissues\u002F11",[]]