-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
38 lines (31 loc) · 1.24 KB
/
helper.py
File metadata and controls
38 lines (31 loc) · 1.24 KB
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
import cv2
import numpy as np
def handle_pose(output, input_shape):
'''
Handles the output of the Pose Estimation model.
Returns ONLY the keypoint heatmaps, and not the Part Affinity Fields.
'''
# TODO 1: Extract only the second blob output (keypoint heatmaps)
heatmaps = output['Mconv7_stage2_L2'] # Shape(1,19,32,57)
# TODO 2: Resize the heatmap back to the size of the input
out_heatmap = np.zeros([heatmaps.shape[1], input_shape[0], input_shape[1]])
for h in range(len(heatmaps[0])):
out_heatmap[h] = cv2.resize(heatmaps[0][h], input_shape[0:2][::-1]) # [0:2][::-1] because of hxw vs wxh
return out_heatmap
'''
The below function is carried over from the previous exercise.
You just need to call it appropriately in `app.py` to preprocess
the input image.
'''
def preprocessing(input_image, height, width):
'''
Given an input image, height and width:
- Resize to width and height
- Transpose the final "channel" dimension to be first
- Reshape the image to add a "batch" of 1 at the start
'''
image = np.copy(input_image)
image = cv2.resize(image, (width, height))
image = image.transpose((2,0,1))
image = image.reshape(1, 3, height, width)
return image