{"id":19198352,"url":"https://github.com/deepvac/retinaface","last_synced_at":"2025-02-23T05:13:42.898Z","repository":{"id":49233427,"uuid":"333058707","full_name":"DeepVAC/RetinaFace","owner":"DeepVAC","description":"DeepVAC-compliant RetinaFace implementation ","archived":false,"fork":false,"pushed_at":"2021-06-22T15:31:13.000Z","size":118,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-04T11:12:00.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeepVAC.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}},"created_at":"2021-01-26T11:08:54.000Z","updated_at":"2021-06-22T15:31:16.000Z","dependencies_parsed_at":"2022-09-19T00:30:11.314Z","dependency_job_id":null,"html_url":"https://github.com/DeepVAC/RetinaFace","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/DeepVAC%2FRetinaFace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FRetinaFace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FRetinaFace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FRetinaFace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepVAC","download_url":"https://codeload.github.com/DeepVAC/RetinaFace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271540,"owners_count":19774859,"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":[],"created_at":"2024-11-09T12:21:29.537Z","updated_at":"2025-02-23T05:13:42.664Z","avatar_url":"https://github.com/DeepVAC.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RetinaFace\nDeepVAC-compliant RetinaFace implementation\n\n# 简介\n本项目实现了符合DeepVAC规范的RetinaFace 。\n\n### 项目依赖\n\n- deepvac \u003e= 0.5.7\n- pytorch \u003e= 1.8.0\n- torchvision \u003e= 0.7.0\n- opencv-python\n- numpy\n\n# 如何运行本项目\n\n## 1. 阅读[DeepVAC规范](https://github.com/DeepVAC/deepvac)\n可以粗略阅读，建立起第一印象。\n\n## 2. 准备运行环境\n使用Deepvac规范指定[Docker镜像](https://github.com/DeepVAC/deepvac#2-%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87)。\n\n## 3. 准备数据集\n\n- 获取WIDER Face数据集      \n[WIDER Face Training Images](https://share.weiyun.com/5WjCBWV)\n[WIDER Face Testing Images](https://share.weiyun.com/5vSUomP)\n[Face annotations](http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/example/Submission_example.zip)\n\n- 若想进一步了解WIDER Face数据集，可参考官网上的信息。    \n[WIDER Face官网](http://shuoyang1213.me/WIDERFACE)\n\n- 解压WIDER Face数据集\n\n- 数据集配置\n在config.py文件中作如下配置：     \n```python\n# line 26\nconfig.datasets.RetinaTrainDataset.fileline_path = \u003ctrain-image-dir\u003e\n# line 27\nconfig.datasets.RetinaTrainDataset.sample_path_prefix = \u003ctrain-list-path\u003e\n# line 76\nconfig.sample_path = \u003ctest/val-image-dir\u003e\n```  \n\n- 如果是自己的数据集，那么必须要跟widerface的标注格式一致\n\n## 4. 训练相关配置\n- 指定预训练模型路径(config.core.RetinaTrain.model_path)      \n- 指定Backbone网络结构, 支持ResNet50, MobileNetV3, RegNet, RepVGG(config.core.RetinaTrain.net)\n- 指定loss函数(config.core.RetinaTrain.criterion)\n- 指定训练分类数量(config.core.RetinaTrain.class_num)    \n- 指定优化器optimizer(config.core.RetinaTrain.optimizer)\n- 指定学习率策略scheduler(config.core.RetinaTrain.scheduler)   \n\n```python\nconfig.core.RetinaTrain.model_path = ''\nconfig.core.RetinaTrain.class_num = 2\nconfig.core.RetinaTrain.shuffle = True\nconfig.core.RetinaTrain.batch_size = 24\nconfig.core.RetinaTrain.net = RetinaFaceMobileNet()\nconfig.core.RetinaTrain.criterion = MultiBoxLoss(config.train.cls_num, 0.35, True, 0, True, 7, 0.35, False, config.train.device)\nconfig.core.RetinaTrain.optimizer = torch.optim.SGD(\n        config.core.RetinaTrain.net.parameters(),\n        lr=1e-3,\n        momentum=0.9,\n        weight_decay=5e-4,\n        nesterov=False\n    )\nconfig.core.RetinaTrain.scheduler = optim.lr_scheduler.MultiStepLR(config.core.RetinaTrain.optimizer, [100, 150, 190, 220], 0.1)\n\n```\n## 5. 训练\n\n### 5.1 单卡训练\n执行命令：\n\n```bash\npython3 train.py\n```\n\n### 5.2 分布式训练\n\n在config.py中修改如下配置：\n```python\n#dist_url，单机多卡无需改动，多机训练一定要修改\nconfig.core.RetinaTrain.dist_url = \"tcp://localhost:27030\"\n\n#rank的数量，一定要修改\nconfig.core.RetinaTrain.world_size = 2\n```\n然后执行命令：\n\n```bash\npython train.py --rank 0 --gpu 0\npython train.py --rank 1 --gpu 1\n```\n\n\n## 6. 测试\n\n- 测试相关配置\n\n```python\n# config.core.RetinaTest is config used for post_process and retina_test.\nconfig.core.RetinaTest.model_path = \"\u003cpretrained-model-path\u003e\"\nconfig.core.RetinaTest.confidence_threshold = 0.02\nconfig.core.RetinaTest.nms_threshold = 0.4\nconfig.core.RetinaTest.top_k = 5000\nconfig.core.RetinaTest.keep_top_k = 1\n\n# config.core.FaceTest is config used for face end-to-end test.\n# align type\nconfig.core.FaceTest.align_type = ['align', 'no_align', 'warp_crop']\n# db/ds path and prefix(name)\nconfig.core.FaceTest.test_dirs = ['']\nconfig.core.FaceTest.test_prefix = ['']\nconfig.core.FaceTest.db_dirs = ['']\nconfig.core.FaceTest.db_prefix = ['']\n\n# config.core.FaceRecTest is config used in face recognition module.\nconfig.core.FaceRecTest.jit_model_path = \"\u003cface-recognition-trained-model-path\u003e\"\n\n```\n\n- 加载模型(*.pth)\n\n```python\nconfig.core.RetinaTest.model_path = \u003ctrained-model-path\u003e\n```\n\n- 运行测试脚本：\n\n```bash\npython3 test.py\n```\n## 7. 使用trace模型/script模型\n如果训练过程中开启config.cast.TraceCast（或者config.cast.ScriptCast)开关，可以在测试过程中转化torchscript模型     \n\n- 转换torchscript模型(*.pt)     \n\n```python\n# trace\nconfig.cast.TraceCast = AttrDict()\nconfig.cast.TraceCast.model_dir = \"./trace.pt\"\n\n# script\nconfig.cast.ScriptCast = AttrDict()\nconfig.cast.ScriptCast.model_dir = \"./script.pt\"\n```\n\n按照步骤6完成测试，torchscript模型将保存至model_dir指定文件位置      \n\n- 加载torchscript模型\n\n```python\nconfig.core.RetinaTest.jit_model_path = \u003ctorchscript-model-path\u003e\n```\n\n## 8. 使用静态量化模型\n如果训练过程中未开启config.cast.TraceCast开关，可以在测试过程中转化静态量化模型     \n- 转换静态模型(*.sq)     \n\n```python\n# trace\nconfig.cast.TraceCast.static_quantize_dir = \"./trace.sq\"\n\n# script\nconfig.cast.ScriptCast.static_quantize_dir = \"./script.sq\"\n```\n按照步骤6完成测试，静态量化模型将保存至config.static_quantize_dir指定文件位置      \n\n- 加载静态量化模型\n\n```python\nconfig.core.RetinaTest.jit_model_path = \u003cstatic-quantize-model-path\u003e\n```\n- 动态量化模型对应的配置参数为config.cast.TraceCast.dynamic_quantize_dir(或者config.cast.ScriptCast.dynamic_quantize_dir)\n\n## 9. 更多功能\n如果要在本项目中开启如下功能：\n- 预训练模型加载\n- checkpoint加载\n- 使用tensorboard\n- 启用TorchScript\n- 转换ONNX\n- 转换NCNN\n- 转换CoreML\n- 开启量化\n- 开启自动混合精度训练\n\n请参考[DeepVAC](https://github.com/DeepVAC/deepvac)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fretinaface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepvac%2Fretinaface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fretinaface/lists"}