def mean_scale(src,dst, mean_limb_file): fns, labels = read_labels(src) labels = np.array(labels) labels = np.reshape(labels,[labels.shape[0], labels.shape[1]/3, 3]) labels = mean_limb_scale(labels, mean_limb_file) labels = np.reshape(labels,[labels.shape[0], labels.shape[1] * labels.shape[2]]) with open(dst,'w') as dst_f: for i in range(len(fns)): write_str = labels[i] write_str = [str(x) for x in write_str] write_str = ','.join(write_str) write_str = fns[i] +' ' +write_str dst_f.write(write_str + '\n')
def normalize_label(gt_fn, dst_gt_fn, valid_data=False): max_value, min_value = get_max_min() fns = [] dst_file = open(dst_gt_fn, 'w') sample_id = 0 fns, gt_labels = read_labels(gt_fn) for i in range(len(fns)): if valid_data and np.random.uniform() > valid_ratio: continue if valid_data and sample_id >= num_valid: break fn = fns[i] labels = gt_labels[i] labels = np.array(labels) labels = (labels - min_value) / (max_value - min_value) labels = labels.tolist() labels = [str(x) for x in labels] label_str = ','.join(labels) dst_file.write(fn + ' ' + label_str + '\n') sample_id += 1
def cal_mean_limb(src, dst): parent_node = { 0: 0, 1: 0, 2: 1, 3: 2, 4: 0, 5: 4, 6: 5, 7: 0, 8: 7, 9: 8, 10: 9, 11: 8, 12: 11, 13: 12, 14: 8, 15: 14, 16: 15 } pose_indexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] fns, labels = read_labels(src) labels = np.array(labels) labels = np.reshape(labels, [labels.shape[0], labels.shape[1] / 3, 3]) limb_length = np.zeros((labels.shape[0], labels.shape[1])) for i in range(labels.shape[0]): for j in range(labels.shape[1]): parent_id = parent_node[j] limb_length[i][j] = np.linalg.norm(labels[i][j] - labels[i][parent_id]) mean_limb_length = np.mean(limb_length, axis=0) print(mean_limb_length) with open(dst, 'w') as f: mean_limb_length = mean_limb_length.tolist() mean_limb_length = [str(x) for x in mean_limb_length] line = ','.join(mean_limb_length) f.write(line + '\n') print(line)