{"id":21120749,"url":"https://github.com/ppogg/retinaface_ghost","last_synced_at":"2025-07-04T10:34:53.460Z","repository":{"id":37631205,"uuid":"375911655","full_name":"ppogg/Retinaface_Ghost","owner":"ppogg","description":"This is a project based on retinaface face detection, including ghostnet and mobilenetv3","archived":false,"fork":false,"pushed_at":"2021-12-02T07:10:54.000Z","size":23818,"stargazers_count":60,"open_issues_count":8,"forks_count":47,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-04T18:51:32.962Z","etag":null,"topics":["ghostnet","mobilenetv3","pytorch","retinaface"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ppogg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-11T05:11:29.000Z","updated_at":"2023-01-04T04:29:08.000Z","dependencies_parsed_at":"2022-08-18T03:10:16.458Z","dependency_job_id":null,"html_url":"https://github.com/ppogg/Retinaface_Ghost","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppogg%2FRetinaface_Ghost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppogg%2FRetinaface_Ghost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppogg%2FRetinaface_Ghost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppogg%2FRetinaface_Ghost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppogg","download_url":"https://codeload.github.com/ppogg/Retinaface_Ghost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225459642,"owners_count":17477609,"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":["ghostnet","mobilenetv3","pytorch","retinaface"],"created_at":"2024-11-20T03:18:09.633Z","updated_at":"2024-11-20T03:18:10.244Z","avatar_url":"https://github.com/ppogg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"English |  [简体中文](https://github.com/pengtougu/Retinaface_Ghost/blob/master/README_CH.md)\n\n# RetinaFace in PyTorch\n\n### Chinese detailed blog：https://zhuanlan.zhihu.com/p/379730820\n\n\u003cimg src=\"https://pic1.zhimg.com/80/v2-84f20d3419063adf10bc001f8ae92a1c_720w.jpg\" width=\"600\" alt=\"stream\"/\u003e\u003cbr/\u003e\n\n### Face recognition with masks is still robust-----------------------------------\n\n## Version Run Library Test of pytorch_retinaface\n\nHow well retinaface works can only be verified by comparison experiments. Here we test the pytorch_retinaface version, which is the one with the highest star among all versions in the community.\n\n#### Data set preparation\nThis address contains the clean Wideface dataset：[https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB)\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210609195709924.png)\n\nThe downloaded dataset contains a total of these three.\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210609200347763.png)\n\nAt this point the folder is image only, however the author requires the data in the format of:\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210609200458806.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTgyOTQ2Mg==,size_16,color_FFFFFF,t_70)\n\nSo we are still missing the index file for the data, and this is the time to use the script provided by the author`wider_val.py`. Export the image information to a txt file, the full format of the export is as follows.\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210609200838123.png)\n\nEach dataset has a txt file containing the sample information. The content of the txt file is roughly like this (take train.txt as an example), containing image information and face location information.\n```\n# 0--Parade/0_Parade_marchingband_1_849.jpg\n449 330 122 149 488.906 373.643 0.0 542.089 376.442 0.0 515.031 412.83 0.0 485.174 425.893 0.0 538.357 431.491 0.0 0.82\n# 0--Parade/0_Parade_Parade_0_904.jpg\n361 98 263 339 424.143 251.656 0.0 547.134 232.571 0.0 494.121 325.875 0.0 453.83 368.286 0.0 561.978 342.839 0.0 0.89\n```\n\n#### Model Training\n\n```\npython train.py --network mobile0.25 \n```\nIf necessary, please download the pre-trained model first and put it in the weights folder. If you want to start training from scratch, specify `'pretrain': False,` in the data/config.py file.\n\n#### Model Evaluation\n\n```\ncd ./widerface_evaluate\npython setup.py build_ext --inplace\npython test_widerface.py --trained_model ./weights/mobilenet0.25_Final.pth --network mobile0.25\npython widerface_evaluate/evaluation.py\n```\n\n## GhostNet and MobileNetv3 migration backbone\n\n#### 3.1 pytorch_retinaface source code modification\n\nAfter the test in the previous section, and took a picture containing only one face for detection, it can be found that resnet50 for the detection of a single picture and the picture contains only a single face takes longer, if the project focuses on real-time then mb0.25 is a better choice, but for the face dense and small-scale scenario is more strenuous.\nIf the skeleton is replaced by another backbone, is it possible to balance real-time and accuracy?\nThe backbone replacement here temporarily uses ghostnet and mobilev3 network (mainly also want to test whether the effect of these two networks can be as outstanding as the paper).\n\nWe specify the relevant reference in the parent class of the retinaface.py file，and specify the network layer ID to be called in IntermediateLayerGetter(backbone, cfg['return_layers']), which is specified in the config.py file as follows.\n```\ndef __init__(self, cfg=None, phase='train'):\n    \"\"\"\n    :param cfg:  Network related settings.\n    :param phase: train or test.\n    \"\"\"\n    super(RetinaFace, self).__init__()\n    self.phase = phase\n    backbone = None\n    if cfg['name'] == 'mobilenet0.25':\n        backbone = MobileNetV1()\n        if cfg['pretrain']:\n            checkpoint = torch.load(\"./weights/mobilenetV1X0.25_pretrain.tar\", map_location=torch.device('cpu'))\n            from collections import OrderedDict\n            new_state_dict = OrderedDict()\n            for k, v in checkpoint['state_dict'].items():\n                name = k[7:]  # remove module.\n                new_state_dict[name] = v\n            # load params\n            backbone.load_state_dict(new_state_dict)\n    elif cfg['name'] == 'Resnet50':\n        import torchvision.models as models\n        backbone = models.resnet50(pretrained=cfg['pretrain'])\n    elif cfg['name'] == 'ghostnet':\n        backbone = ghostnet()\n    elif cfg['name'] == 'mobilev3':\n        backbone = MobileNetV3()\n\n    self.body = _utils.IntermediateLayerGetter(backbone, cfg['return_layers'])\n```\nWe specify the number of network channels of the FPN and fix the `in_channels` of each layer for the three-layer FPN structure formulated in the model.\n\n```\nin_channels_stage2 = cfg['in_channel']\n        in_channels_list = [\n            in_channels_stage2 * 2,\n            in_channels_stage2 * 4,\n            in_channels_stage2 * 8,\n        ]\n        out_channels = cfg['out_channel']\n        # self.FPN = FPN(in_channels_list, out_channels)\n        self.FPN = FPN(in_channels_list, out_channels)\n```\n\nWe insert the ghontnet network in models/ghostnet.py, and the network structure comes from the Noah's Ark Labs open source address[https://github.com/huawei-noah/ghostnet](https://github.com/huawei-noah/ghostnet)：\n\n**Lightweight network classification effect comparison：**\n\n\u003cimg src=\"https://img-blog.csdnimg.cn/20210610215038358.png\" width=\"600\" alt=\"stream\"/\u003e\u003cbr/\u003e\n\nBecause of the inclusion of the residual convolution separation module and the SE module, the source code is relatively long, and the source code of the modified network is as follows`models/ghostnet.py`\n\nWe insert the MobileNetv3 network in models/mobilev3.py. The network structure comes from the pytorch version reproduced by github users, so it's really plug-and-play![https://github.com/kuan-wang/pytorch-mobilenet-v3](https://github.com/kuan-wang/pytorch-mobilenet-v3)：\n\nThe modified source code is as follows.`models/mobilenetv3.py`\n\n#### 3.2 Model Training\n\nExecute the command: `python train.py --network ghostnet` to start training\n\n\u003cimg src=\"https://img-blog.csdnimg.cn/20210610221938138.png\" width=\"600\" alt=\"stream\"/\u003e\u003cbr/\u003e\n\nCounting the duration of training a single epoch per network.\n\n - **resnet50\u003e\u003emobilenetv3\u003eghostnet-m\u003eghostnet-s\u003emobilenet0.25**\n\n#### 3.3 Model Testing and Evaluation\n\n**Test GhostNet（se-ratio=0.25）：**\n\n![](https://pic1.zhimg.com/80/v2-85514cc55ce31b937d4fdf85fbbf7670_720w.jpg)\n\nAs you can see, a batch test is about 56ms\n\n**Evaluation GhostNet(se-ratio=0.25）：**\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210610222836784.png)\n\nIt can be seen that ghostnet is relatively poor at recognizing small sample data and face occlusion.\n\n**Test MobileNetV3（se-ratio=1）：**\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210610223025905.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTgyOTQ2Mg==,size_16,color_FFFFFF,t_70)\n\n可以看出，一份batch的测试大概在120ms左右\n\n**Evaluation MobileNetV3（se-ratio=1）：**\n![在这里插入图片描述](https://img-blog.csdnimg.cn/20210610223123787.png)\n\nThe evaluation here outperforms ghostnet on all three subsets (the comparison here is actually a bit unscientific, because the full se_ratio of mbv3 is used to benchmark ghostnet's se_ratio by 1/4, but the full se_ratio of ghostnet will cause the model memory to skyrocket (at se-ratio=0) weights=6M, se-ratio=0.25 when weights=12M, se-ratio=1 when weights=30M, and the accuracy barely exceeds that of MobileNetV3 with se-ratio=1, I personally feel that the cost performance is too low)\n\nTranslated with www.DeepL.com/Translator (free version)\n\n#### 3.4 Model Demo\n\n - Use webcam：\n\n    python detect.py -fourcc 0\n\n - Detect Face：\n \n\n    python detect.py --image img_path\n\n - Detect Face and save：\n\n    python detect.py --image img_path --sava_image True\n\n#### 3.2 comparision of resnet \u0026 mbv3 \u0026 gnet \u0026 mb0.25 \n   **Reasoning Performance Comparison：**\n   \nBackbone | Computing backend | size（MB） | Framework | input_size| Run time\n :-----:|:-----:|:-----:|:----------:|:----:|:----:|\nresnet50| Core i5-4210M |106 | torch| 640| 1571 ms\n$GhostNet-m^{Se=0.25}$| Core i5-4210M |12 | torch| 640| 403 ms\nMobileNet v3| Core i5-4210M | 8 | torch| 640| 576 ms\nMobileNet0.25| Core i5-4210M | 1.7| torch| 640| 187 ms\nMobileNet0.25| Core i5-4210M | 1.7 | onnxruntime| 640| 73 ms\n\n   **Testing performance comparison：**\nBackbone | Easy | Medium | Hard\n :-----:|:-----:|:-----:|:----------:|\nresnet50| 95.48% |94.04% | 84.43%| \n$MobileNet v3^{Se=1}$| 93.48%| 91.23% | 80.19%|\n$GhostNet-m^{Se=0.25}$| 93.35% |90.84% | 76.11%|\nMobileNet0.25| 90.70% | 88.16%| 73.82%| \n\n   **Comparison of the effect of single chart test：**\n\n\u003cimg src=\"https://pic1.zhimg.com/80/v2-84f20d3419063adf10bc001f8ae92a1c_720w.jpg\" width=\"600\" alt=\"stream\"/\u003e\u003cbr/\u003e\n\n### Chinese detailed blog：https://zhuanlan.zhihu.com/p/379730820\n\n## References\n- [FaceBoxes](https://github.com/zisianw/FaceBoxes.PyTorch)\n- [Retinaface (mxnet)](https://github.com/deepinsight/insightface/tree/master/RetinaFace)\n- [biubug6/Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppogg%2Fretinaface_ghost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppogg%2Fretinaface_ghost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppogg%2Fretinaface_ghost/lists"}