def get_ground_truth(self, meta, mask_miss): stride = self.params_transform['stride'] mode = self.params_transform['mode'] crop_size_y = self.params_transform['crop_size_y'] crop_size_x = self.params_transform['crop_size_x'] num_parts = self.params_transform['np'] nop = meta['numOtherPeople'] grid_y = crop_size_y / stride grid_x = crop_size_x / stride channels = (num_parts + 1) * 2 heatmaps = np.zeros((int(grid_y), int(grid_x), 19)) pafs = np.zeros((int(grid_y), int(grid_x), 38)) mask_miss = cv2.resize(mask_miss, (0, 0), fx=1.0 / stride, fy=1.0 / stride, interpolation=cv2.INTER_CUBIC).astype( np.float32) mask_miss = mask_miss / 255. mask_miss = np.expand_dims(mask_miss, axis=2) heat_mask = np.repeat(mask_miss, 19, axis=2) paf_mask = np.repeat(mask_miss, 38, axis=2) # confidance maps for body parts for i in range(18): if (meta['joint_self'][i, 2] <= 1): center = meta['joint_self'][i, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) for j in range(nop): if (meta['joint_others'][j, i, 2] <= 1): center = meta['joint_others'][j, i, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) # pafs mid_1 = [2, 9, 10, 2, 12, 13, 2, 3, 4, 3, 2, 6, 7, 6, 2, 1, 1, 15, 16] mid_2 = [ 9, 10, 11, 12, 13, 14, 3, 4, 5, 17, 6, 7, 8, 18, 1, 15, 16, 17, 18 ] thre = 1 for i in range(19): # limb count = np.zeros((int(grid_y), int(grid_x)), dtype=np.uint32) if (meta['joint_self'][mid_1[i] - 1, 2] <= 1 and meta['joint_self'][mid_2[i] - 1, 2] <= 1): centerA = meta['joint_self'][mid_1[i] - 1, :2] centerB = meta['joint_self'][mid_2[i] - 1, :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] # print vec_map.shape pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) for j in range(nop): if (meta['joint_others'][j, mid_1[i] - 1, 2] <= 1 and meta['joint_others'][j, mid_2[i] - 1, 2] <= 1): centerA = meta['joint_others'][j, mid_1[i] - 1, :2] centerB = meta['joint_others'][j, mid_2[i] - 1, :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) # background heatmaps[:, :, -1] = np.maximum(1 - np.max(heatmaps[:, :, :18], axis=2), 0.) return heat_mask, heatmaps, paf_mask, pafs
def get_ground_truth(self, meta, mask_miss): stride = self.params_transform['stride'] crop_size_y = self.params_transform['crop_size_y'] crop_size_x = self.params_transform['crop_size_x'] nop = meta['numOtherPeople'] grid_y = crop_size_y / stride grid_x = crop_size_x / stride heatmaps = np.zeros((int(grid_y), int(grid_x), 16)) pafs = np.zeros((int(grid_y), int(grid_x), 32)) mask_miss = cv2.resize(mask_miss, (0, 0), fx=1.0 / stride, fy=1.0 / stride, interpolation=cv2.INTER_CUBIC).astype( np.float32) mask_miss = mask_miss / 255. mask_miss = np.expand_dims(mask_miss, axis=2) heat_mask = np.repeat(mask_miss, 16, axis=2) paf_mask = np.repeat(mask_miss, 32, axis=2) ''' id (0 - r ankle, 1 - r knee, 2 - r hip, 3 - l hip, 4 - l knee, 5 - l ankle, 6 - pelvis, 7 - thorax, 8 - upper neck, 9 - head top, 10 - r wrist, 11 - r elbow, 12 - r shoulder, 13 - l shoulder, 14 - l elbow, 15 - l wrist) ''' # now 6 is the center of person, and thorax was eliminated. ran = [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15] for i in range(15): # the first person' index = ran[i] if (meta['joint_self'][index, 2] <= 1): center = meta['joint_self'][index, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) # the other people in the image for j in range(nop): if (meta['joint_others'][j, index, 2] <= 1): center = meta['joint_others'][j, index, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) mid_1 = [8, 8, 6, 3, 4, 6, 2, 1, 8, 13, 14, 8, 12, 11, 12, 13] mid_2 = [9, 6, 3, 4, 5, 2, 1, 0, 13, 14, 15, 12, 11, 10, 9, 9] for i in range(16): count = np.zeros((int(grid_y), int(grid_x)), dtype=np.uint32) if (meta['joint_self'][mid_1[i], 2] <= 1 and meta['joint_self'][mid_2[i], 2] <= 1): centerA = meta['joint_self'][mid_1[i], :2] centerB = meta['joint_self'][mid_2[i], :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) for j in range(nop): if (meta['joint_others'][j, mid_1[i], 2] <= 1 and meta['joint_others'][j, mid_2[i], 2] <= 1): centerA = meta['joint_others'][j, mid_1[i], :2] centerB = meta['joint_others'][j, mid_2[i], :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) # background heatmaps[:, :, -1] = np.maximum(1 - np.max(heatmaps[:, :, :14], axis=2), 0.) return heat_mask, heatmaps, paf_mask, pafs
def get_ground_truth(self, meta, mask_miss): stride = self.params_transform['stride'] mode = self.params_transform['mode'] crop_size_y = self.params_transform['crop_size_y'] crop_size_x = self.params_transform['crop_size_x'] num_parts = self.params_transform['np'] nop = meta['numOtherPeople'] grid_y = crop_size_y / stride grid_x = crop_size_x / stride channels = (num_parts + 1) * 2 heatmaps = np.zeros((int(grid_y), int(grid_x), 19)) pafs = np.zeros((int(grid_y), int(grid_x), 38)) mask_miss = cv2.resize(mask_miss, (0, 0), fx=1.0 / stride, fy=1.0 / stride, interpolation=cv2.INTER_CUBIC).astype( np.float32) mask_miss = mask_miss / 255. mask_miss = np.expand_dims(mask_miss, axis=2) heat_mask = np.repeat(mask_miss, 19, axis=2) paf_mask = np.repeat(mask_miss, 38, axis=2) # print(meta['joint_self']) # print(meta['joint_self'][0, 2]) # print(meta['joint_self'][0, 0, 2]) # confidance maps for body parts for i in range(18): # the first person if (meta['joint_self'][i, 2] <= 1): center = meta['joint_self'][i, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) # the other people in the image for j in range(nop): # print(meta['joint_others']) # print(meta['joint_others'][j, i, 2] <= 1) if (meta['joint_others'][j, i, 2] <= 1): center = meta['joint_others'][j, i, :2] gaussian_map = heatmaps[:, :, i] heatmaps[:, :, i] = putGaussianMaps( center, gaussian_map, params_transform=self.params_transform) ''' MS COCO annotation order: 0: nose 1: l eye 2: r eye 3: l ear 4: r ear 5: l shoulder 6: r shoulder 7: l elbow 8: r elbow 9: l wrist 10: r wrist 11: l hip 12: r hip 13: l knee 14: r knee 15: l ankle 16: r ankle The order in this work: (0-'nose' 1-'neck' 2-'right_shoulder' 3-'right_elbow' 4-'right_wrist' 5-'left_shoulder' 6-'left_elbow' 7-'left_wrist' 8-'right_hip' 9-'right_knee' 10-'right_ankle' 11-'left_hip' 12-'left_knee' 13-'left_ankle' 14-'right_eye' 15-'left_eye' 16-'right_ear' 17-'left_ear' ) ''' # pafs # neck-r_shoulder neck-l_shoulder r_shoulder-r_elbow r_elbow-r_wrist l_shoulder-l_elbow l_elbow-l_wrist # neck-r_hip r_hip-r_knee r_knee-r_ankle neck-l_hip l_hip-l_knee l_knee-l_ankle neck-nose nose-r_eye r_eye-r_ear # nose-l_eye l_eye-l_ear mid_1 = [2, 9, 10, 2, 12, 13, 2, 3, 4, 3, 2, 6, 7, 6, 2, 1, 1, 15, 16] mid_2 = [ 9, 10, 11, 12, 13, 14, 3, 4, 5, 17, 6, 7, 8, 18, 1, 15, 16, 17, 18 ] thre = 1 for i in range(19): # limb count = np.zeros((int(grid_y), int(grid_x)), dtype=np.uint32) if (meta['joint_self'][mid_1[i] - 1, 2] <= 1 and meta['joint_self'][mid_2[i] - 1, 2] <= 1): centerA = meta['joint_self'][mid_1[i] - 1, :2] centerB = meta['joint_self'][mid_2[i] - 1, :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] # print vec_map.shape pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) for j in range(nop): if (meta['joint_others'][j, mid_1[i] - 1, 2] <= 1 and meta['joint_others'][j, mid_2[i] - 1, 2] <= 1): centerA = meta['joint_others'][j, mid_1[i] - 1, :2] centerB = meta['joint_others'][j, mid_2[i] - 1, :2] vec_map = pafs[:, :, 2 * i:2 * i + 2] pafs[:, :, 2 * i:2 * i + 2], count = putVecMaps( centerA=centerA, centerB=centerB, accumulate_vec_map=vec_map, count=count, params_transform=self.params_transform) # background heatmaps[:, :, -1] = np.maximum(1 - np.max(heatmaps[:, :, :18], axis=2), 0.) return heat_mask, heatmaps, paf_mask, pafs