Skip to content

Commit 71544e9

Browse files
committed
feat: Update all the results and complete the code
1 parent 36d5bed commit 71544e9

15 files changed

+70
-48
lines changed

README.md

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,62 @@
1-
# 📸 Nano-Face-PyTorch: Ultra-lightweight Face Detection
1+
# 📸 Tiny-Face: Ultra-lightweight Face Detection
22

3-
[![Downloads](https://img.shields.io/github/downloads/yakhyo/nano-face-pytorch/total)](https://github.com/yakhyo/nano-face-pytorch/releases)
4-
[![GitHub Repo stars](https://img.shields.io/github/stars/yakhyo/nano-face-pytorch)](https://github.com/yakhyo/nano-face-pytorch/stargazers)
5-
[![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/yakhyo/nano-face-pytorch)
6-
[![GitHub License](https://img.shields.io/github/license/yakhyo/nano-face-pytorch)](https://github.com/yakhyo/nano-face-pytorch/blob/main/LICENSE)
3+
[![Downloads](https://img.shields.io/github/downloads/yakhyo/tiny-face-pytorch/total)](https://github.com/yakhyo/tiny-face-pytorch/releases)
4+
[![GitHub Repo stars](https://img.shields.io/github/stars/yakhyo/tiny-face-pytorch)](https://github.com/yakhyo/tiny-face-pytorch/stargazers)
5+
[![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/yakhyo/tiny-face-pytorch)
6+
[![GitHub License](https://img.shields.io/github/license/yakhyo/tiny-face-pytorch)](https://github.com/yakhyo/tiny-face-pytorch/blob/main/LICENSE)
77

8-
<video controls autoplay loop src="https://github.com/user-attachments/assets/ad279fea-33fb-43f1-884f-282e6d54c809" muted="false" width="100%"></video>
8+
<video controls autoplay loop src="https://github.com/user-attachments/assets/faf65b91-db76-4538-beca-87fc65566e51" muted="false" width="100%"></video>
99

10-
Nano-Face-PyTorch is an ultra-lightweight face detection model optimized for mobile and edge devices. Built upon the concepts of RetinaFace, this model achieves high precision and speed in face detection with minimal resource requirements.
10+
Tiny-Face is an ultra-lightweight face detection model optimized for mobile and edge devices. Built upon the concepts of RetinaFace, this model achieves high precision and speed in face detection with minimal resource requirements.
1111

1212
> **Note**
13-
> This repository refines lightweight architectures like Slim and RFB with a focus on Nano-level efficiency.
13+
> This repository refines lightweight architectures like RetinaFace (mobile), Slim and RFB with a focus on Tiny-level efficiency.
1414
1515
<div align="center">
16-
<img src="assets/mv2_test.jpg">
16+
<img src="assets/test_retina.jpg">
1717
</div>
1818

1919
## 📈 Performance on WiderFace
2020

2121
### Multi-scale Image Size
2222

23-
| Models | Pretrained on ImageNet | Easy | Medium | Hard | Model Size |
24-
| ---------- | ---------------------- | ------ | ------ | ------ | ---------- |
25-
| SlimFace | False | 81.65% | 82.12% | 74.35% | 1.39 MB |
26-
| RFB | False | 90.59% | 89.14% | 84.13% | MB |
27-
| RetinaFace | True | 89.00% | 87.50% | 81.00% | MB |
23+
| Models | Pretrained on ImageNet | Easy | Medium | Hard | #Params(M) | Size(MB) |
24+
| ---------- | ---------------------- | ------ | ------ | ------ | ---------- | -------- |
25+
| SlimFace | False | 79.50% | 79.40% | 68.36% | 0.359 | 1.4 |
26+
| RFB | False | 80.49% | 81.51% | 75.73% | 0.343 | 1.5 |
27+
| RetinaFace | True | 87.69% | 86.39% | 80.21% | 0.426 | 1.8 |
2828

2929
### Original Image Size
3030

31-
| Models | Pretrained on ImageNet | Easy | Medium | Hard | Model Size |
31+
| Models | Pretrained on ImageNet | Easy | Medium | Hard | #Params(M) |
3232
| ---------- | ---------------------- | ------ | ------ | ------ | ---------- |
33-
| SlimFace | False | 88.04% | 85.47% | 55.40% | 1.39 MB |
34-
| RFB | False | % | % | % | MB |
35-
| RetinaFace | True | % | % | % | MB |
33+
| SlimFace | False | 87.10% | 84.36% | 67.38% | 0.359 |
34+
| RFB | False | 87.09% | 84.61% | 69.22% | 0.343 |
35+
| RetinaFace | True | 90.26% | 87.48% | 72.85% | 0.426 |
3636

3737
## ✨ Features
3838

39-
- **Nano-sized Efficiency**: Ultra-lightweight and optimized for low-resource devices.
39+
- **Tiny-sized Efficiency**: Ultra-lightweight and optimized for low-resource devices.
4040
- **Mobile-friendly**: Includes Slim, RFB, and MobileNetV1_0.25 configurations.
4141
- **Pretrained Backbones**: Models suitable for mobile and embedded systems.
4242

43-
### Last Updated: November 9, 2024
43+
### Download model weights
44+
45+
All weights are available in [GitHub release v0.0.1](https://github.com/yakhyo/tiny-face-pytorch/releases/tag/v0.0.1).
46+
47+
| Models | PyTorch Weights | ONNX Weights | Input Size |
48+
| ---------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------- |
49+
| SlimFace | [slimface.pth](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/slimface.pth) | [slimface.onnx](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/slimface.onnx) | 640x640 |
50+
| RFB | [rfb.pth](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/rfb.pth) | [rfb.onnx](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/rfb.onnx) | 640x640 |
51+
| RetinaFace | [retinaface.pth](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/retinaface.pth) | [retinaface.onnx](https://github.com/yakhyo/tiny-face-pytorch/releases/download/v0.0.1/retinaface.onnx) | 640x640 |
4452

4553
## ⚙️ Installation
4654

4755
1. Clone the repository:
4856

4957
```bash
50-
git clone https://github.com/yakhyo/nano-face-pytorch.git
51-
cd nano-face-pytorch
58+
git clone https://github.com/yakhyo/tiny-face-pytorch.git
59+
cd tiny-face-pytorch
5260
```
5361

5462
2. Install dependencies:
@@ -93,7 +101,7 @@ python train.py --network slim # Replace 'slim' with your choice of model
93101

94102
**Available Models**:
95103

96-
- `mobilenetv1_0.25`
104+
- `retinaface`
97105
- `slim`
98106
- `rfb`
99107

@@ -102,14 +110,26 @@ python train.py --network slim # Replace 'slim' with your choice of model
102110
Inference the model using:
103111

104112
```bash
105-
python detect.py --network mobilenetv1_0.25 --weights mobilenetv1_0.25.pth
113+
python detect.py --network retinaface --weights weights/retinaface.pth
114+
slim weights/slim.pth
115+
rfb weights/rfb.pth
106116
```
107117

118+
#### Model found following number of faces from large selfi image:
119+
120+
- **RetinaFace**: 459
121+
- **RFB**: 430
122+
- **Slim**: 384
123+
<div align="center">
124+
<img src="assets/largeselfi_retina.jpg">
125+
<p>RetinaFace model inference result.</p>
126+
</div>
127+
108128
## 🧪 Evaluating RetinaFace on WiderFace Dataset
109129

110130
### 1. Get and Install WiderFace Evaluation Tool
111131

112-
1. Clone the WiderFace evaluation repository inside the `nano-face-pytorch` folder:
132+
1. Clone the WiderFace evaluation repository inside the `tiny-face-pytorch` folder:
113133
```bash
114134
git clone https://github.com/yakhyo/widerface_evaluation
115135
```
@@ -118,7 +138,7 @@ python detect.py --network mobilenetv1_0.25 --weights mobilenetv1_0.25.pth
118138
cd widerface_evaluation
119139
python3 setup.py build_ext --inplace
120140
```
121-
3. Return to the `nano-face-pytorch` folder after installation is complete:
141+
3. Return to the `tiny-face-pytorch` folder after installation is complete:
122142
```bash
123143
cd ..
124144
```
@@ -128,7 +148,9 @@ python detect.py --network mobilenetv1_0.25 --weights mobilenetv1_0.25.pth
128148
Run the following command to evaluate your model with WiderFace, specifying the model architecture (`mobilenetv1_0.25` in this example) and the path to the trained weights. Predictions will be stored in `widerface_txt` inside the `widerface_evaluation` folder.
129149

130150
```bash
131-
python evaluate_widerface.py --network mobilenetv1_0.25 --weights weights/mobilenetv1_0.25.pth
151+
python evaluate_widerface.py --network retinaface --weights weights/retinaface.pth
152+
slim weights/slim.pth
153+
rfb weights/rfb.pth
132154
```
133155

134156
### 3. Run the Final Evaluation

assets/largeselfi_retina.jpg

1.17 MB
Loading

assets/out_retina.mp4

2.17 MB
Binary file not shown.

assets/out_rfb.mp4

2.21 MB
Binary file not shown.

assets/out_slim.mp4

2.21 MB
Binary file not shown.

assets/test_retina.jpg

238 KB
Loading

assets/test_rfb.jpg

235 KB
Loading

assets/test_slim.jpg

230 KB
Loading

config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
def get_config(network):
22
configs = {
3-
"mobilenetv1_0.25": cfg_mnet,
3+
"retinaface": cfg_mnet,
44
"slim": cfg_slim,
55
"rfb": cfg_rfb,
66
}
77
return configs.get(network, None)
88

99

1010
cfg_mnet = {
11-
'name': 'mobilenet0.25',
11+
'name': 'retinaface',
1212
'min_sizes': [[16, 32], [64, 128], [256, 512]],
1313
'steps': [8, 16, 32],
1414
'variance': [0.1, 0.2],

detect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def parse_arguments():
2626
parser.add_argument(
2727
'--network',
2828
type=str,
29-
default='mobilenetv1_0.25',
30-
choices=['mobilenetv1_0.25', 'slim', 'rfb'],
29+
default='retinaface',
30+
choices=['retinaface', 'slim', 'rfb'],
3131
help='Select a model architecture for face detection'
3232
)
3333

@@ -103,7 +103,7 @@ def main(params):
103103
resize_factor = 1
104104

105105
# model initialization
106-
if params.network == "mobilenetv1_0.25":
106+
if params.network == "retinaface":
107107
model = RetinaFace(cfg=cfg)
108108
elif params.network == "slim":
109109
model = SlimFace(cfg=cfg)

0 commit comments

Comments
 (0)