-
Notifications
You must be signed in to change notification settings - Fork 26
/
demo.py
54 lines (39 loc) · 1.58 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import glob, time, dlib, matplotlib.pyplot as plt, numpy as np
import AUmaps
AUdetector = AUmaps.AUdetector('shape_predictor_68_face_landmarks.dat', enable_cuda=True)
path_imgs = 'example_video'
files = sorted(glob.glob(path_imgs + '/*.png'))
fig = plt.figure(figsize=plt.figaspect(.5))
axs = fig.subplots(5, 2)
# Init subplots and images within
implots = []
for ax in axs.reshape(-1):
ax.axis('off')
implots.append(ax.imshow(np.zeros((256, 256))))
tstart_time = time.time()
nframes = len(files)
for names in files:
start_time = time.time()
img = dlib.load_rgb_image(names)
pred,map,img = AUdetector.detectAU(img)
for j in range(0,5):
resized_map = dlib.resize_image(map[j,:,:].cpu().data.numpy(),rows=256,cols=256)
# Update face image subplot
implots[2*j].set_data(img)
# Update heatmap subplot
implots[2*j+1].set_data(resized_map)
# Set correct heatmap limits
resized_map_flat = resized_map.flatten()
implots[2*j+1].set_clim(min(resized_map_flat), max(resized_map_flat))
# To plot heatmaps the original way - looks identical to the new way!
# ax = fig.add_subplot(5,2,2*j+1)
# ax.imshow(resized_map)
# ax.axis('off')
plt.pause(0.001)
plt.draw()
elapsed_time = time.time() - start_time
print(' ** Frame: {0:s}; FPS Elapsed: {1:.3f}'.format(names, 1.0 / elapsed_time))
# To move upon key press
# input("Press Enter to continue...")
telapsed_time = time.time() - tstart_time
print('\n ** Mean FPS Elapsed: {0:.3f} \n'.format(1.0 / (telapsed_time / nframes)))