Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cleardusk committed May 2, 2019
1 parent 00e41ac commit a0800cc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
18 changes: 17 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ By [Jianzhu Guo](https://guojianzhu.com/aboutme.html).

**\[Updates\]**

- `2019.5.2`: Evaluating inference speed on CPU with PyTorch v1.1.0, see [here](#./CPU) and [speed_cpu.py](./speed_cpu.py).
- `2019.4.27`: A simple render pipline running at ~25ms/frame (720p), see [rendering.py](demo@obama/rendering.py) for more details.
- `2019.4.24`: Providing the demo building of obama, see [demo@obama/readme.md](demo@obama/readme.md) for more details.
- `2019.3.28`: Some updates.
Expand Down Expand Up @@ -79,7 +80,7 @@ Several results on ALFW-2000 dataset (inferenced from model *phase1_wpdc_vdc.pth

## Getting started
### Requirements
- PyTorch >= 0.4.1 (PyTorch v1.1.0 is tested successfully on macOS and Linux.)
- PyTorch >= 0.4.1 (**PyTorch v1.1.0** is tested successfully on macOS and Linux.)
- Python >= 3.6 (Numpy, Scipy, Matplotlib)
- Dlib (Dlib is optionally for face and landmarks detection. There is no need to use Dlib if you can provide face bouding bbox and landmarks. Besides, you can try the two-step inference strategy without initialized landmarks.)
- OpenCV (Python version, for image IO opertations.)
Expand Down Expand Up @@ -178,6 +179,21 @@ In addition, I strongly recommend using Python3.6+ instead of older version for
## Inference speed
### CPU
Just run
```
python3 speed_cpu.py
```
On my MBP (i5-8259U CPU @ 2.30GHz on 13-inch MacBook Pro), based on **PyTorch v1.1.0**, with a single input, the running output is:
```
Inference speed: 14.50±0.11 ms
```
<!-- [speed_cpu.py](./speed_cpu.py) -->
### GPU
When input batch size is 128, the total inference time of MobileNet-V1 takes about 34.7ms. The average speed is about **0.27ms/pic**.
<p align="center">
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
torch==0.4.1
torchvision==0.2.1
numpy==1.15.4
scipy==1.1.0
torch>=0.4.1
torchvision>=0.2.1
numpy>=1.15.4
scipy>=1.1.0
matplotlib==3.0.2
dlib==19.5.0 # 19.15+ version may cause conflict with pytorch, this may take several minutes
opencv-python==3.4.3.18
opencv-python>=3.4.3.18
35 changes: 35 additions & 0 deletions speed_cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# coding: utf-8

import timeit
import numpy as np

SETUP_CODE = '''
import mobilenet_v1
import torch
model = mobilenet_v1.mobilenet_1()
model.eval()
data = torch.rand(1, 3, 120, 120)
'''

TEST_CODE = '''
with torch.no_grad():
model(data)
'''


def main():
repeat, number = 5, 100
res = timeit.repeat(setup=SETUP_CODE,
stmt=TEST_CODE,
repeat=repeat,
number=number)
res = np.array(res, dtype=np.float32)
res /= number
mean, var = np.mean(res), np.std(res)
print('Inference speed: {:.2f}±{:.2f} ms'.format(mean * 1000, var * 1000))


if __name__ == '__main__':
main()

0 comments on commit a0800cc

Please sign in to comment.