Skip to content

Commit 8ede8bf

Browse files
committed
Add benchmark app and update README
1 parent 34ee586 commit 8ede8bf

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ A conda environment with these packages should suffice: `conda install tensorflo
1515

1616
### Usage
1717

18-
There are two demo apps to try the PoseNet model. They are very basic and could be made more performant.
18+
There are three demo apps in the root that utilize the PoseNet model. They are very basic and could definitely be improved.
1919

20-
The first time these apps are run (or the library is used) model weights will be downloaded for the TFJS version and converted on the fly.
20+
The first time these apps are run (or the library is used) model weights will be downloaded from the TensorFlow.js version and converted on the fly.
2121

22-
For both demos, the model can be specified by using its ordinal id (0-3) or integer depth multiplier (50, 75, 100, 101). The default is the 101 model.
22+
For all demos, the model can be specified with the '--model` argument by using its ordinal id (0-3) or integer depth multiplier (50, 75, 100, 101). The default is the 101 model.
2323

2424
#### image_demo.py
2525

2626
Image demo runs inference on an input folder of images and outputs those images with the keypoints and skeleton overlayed.
2727

2828
`python image_demo.py --model 101 --image_dir ./images --output_dir ./output`
2929

30-
A folder of suitable test images can be downloaded by first running the get_test_images.py script.
30+
A folder of suitable test images can be downloaded by first running the `get_test_images.py` script.
31+
32+
#### benchmark.py
33+
34+
A minimal performance benchmark based on image_demo. Images in `--image_dir` are pre-loaded and inference is run `--num_images` times with no drawing and no text output.
3135

3236
#### webcam_demo.py
3337

benchmark.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import tensorflow as tf
2+
import time
3+
import argparse
4+
import os
5+
6+
import posenet
7+
8+
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('--model', type=int, default=101)
11+
parser.add_argument('--image_dir', type=str, default='./images')
12+
parser.add_argument('--num_images', type=int, default=1000)
13+
args = parser.parse_args()
14+
15+
16+
def main():
17+
18+
with tf.Session() as sess:
19+
model_cfg, model_outputs = posenet.load_model(args.model, sess)
20+
height = model_cfg['height']
21+
width = model_cfg['width']
22+
output_stride = model_cfg['output_stride']
23+
num_images = args.num_images
24+
25+
filenames = [
26+
f.path for f in os.scandir(args.image_dir) if f.is_file() and f.path.endswith(('.png', '.jpg'))]
27+
if len(filenames) > num_images:
28+
filenames = filenames[:num_images]
29+
30+
images = {f: posenet.read_imgfile(f, width, height)[0] for f in filenames}
31+
32+
start = time.time()
33+
for i in range(num_images):
34+
heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = sess.run(
35+
model_outputs,
36+
feed_dict={'image:0': images[filenames[i % len(filenames)]]}
37+
)
38+
39+
output = posenet.decode_multiple_poses(
40+
heatmaps_result.squeeze(axis=0),
41+
offsets_result.squeeze(axis=0),
42+
displacement_fwd_result.squeeze(axis=0),
43+
displacement_bwd_result.squeeze(axis=0),
44+
output_stride=output_stride,
45+
max_pose_detections=10,
46+
min_pose_score=0.25)
47+
48+
print('Average FPS:', num_images / (time.time() - start))
49+
50+
51+
if __name__ == "__main__":
52+
main()

get_test_images.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def main():
4242

4343
for f in TEST_IMAGES:
4444
url = os.path.join(GOOGLE_CLOUD_IMAGE_BUCKET, f)
45+
print('Downloading %s' % f)
4546
urllib.request.urlretrieve(url, os.path.join(args.image_dir, f))
4647

4748

0 commit comments

Comments
 (0)