path_suffix = clip_path[len(prefix):] # This is same number used to identify pose clip (not sequential!) tmp2_id = video_entry['video_id'] new_name = 'vid%d' % tmp2_id meta_dict[new_name] = {'path_suffix': path_suffix, 'tmp2_id': tmp2_id} meta = meta_dict[vid_name] path_suffix = meta['path_suffix'] tmp2_id = meta['tmp2_id'] tmp2_id = int(re.match(r'^vid(\d+)$', vid_name).groups()[0]) all_frame_fns = load_sorted_paths(os.path.join(FRAME_DIR, path_suffix)) # for some reason there is one video directory with a subdirectory that has # a numeric name frame_paths = [f for f in all_frame_fns if f.endswith('.jpg')] pose_seqs = poses[None, ...] seq_names = ['Full sequence'] action_labels = action_names[actions] assert len(action_labels) == len(poses) print('Action names: ' + ', '.join(action_names)) print('Actions: ' + ', '.join(action_labels)) anims = draw_poses('Original training poses in %s' % H5_PATH, parents, pose_seqs, frame_paths=[frame_paths] * 3, subplot_titles=seq_names, fps=50, action_labels=action_labels) plt.show()
# a numeric name all_frame_fns = [f for f in all_frame_fns if f.endswith('.jpg')] frame_paths = [all_frame_fns[i] for i in d['frame_inds']] pose_seqs = np.stack( (d['true_poses'], d['prior_poses'], d['posterior_poses']), axis=0) seq_names = ['True poses', 'Prior prediction', 'Posterior prediction'] pose_mat_path = os.path.join(POSE_DIR, 'pose_clip_%d.mat' % tmp2_id) pose_mat = loadmat(pose_mat_path, squeeze_me=True) # important not to let return value be gc'd (anims won't run otherwise!) anim = draw_poses('Completed poses in %s' % args.completion_path, d['parents'], pose_seqs, frame_paths=[frame_paths] * 3, subplot_titles=seq_names, fps=50 / 9.0, crossover=d['crossover_time']) if args.vid_dir is not None: # save video print('Saving video') try: os.makedirs(args.vid_dir) except FileExistsError: pass bn = os.path.basename(args.completion_path).rsplit('.')[0] key = d['vid_name'] + '-' + bn anim.save( os.path.join(args.vid_dir, key + '.mp4'),
action_name_map = np.asarray( json.loads(fp['/action_names'].value.tostring().decode('utf8'))) parents = fp['/parents'].value pose_seqs = poses[None, ...] action_labels = action_name_map[action_ids] frame_paths = load_sorted_paths(os.path.join(FRAME_DIR, vid_name)) seq_names = ['True poses'] all_mat_pose_paths = load_sorted_paths(os.path.join(POSE_DIR, vid_name)) mat_fst_pose_path = all_mat_pose_paths[0] with h5py.File(mat_fst_pose_path) as fp: # gives us 2*14 ref_pose = fp['pose'].value[:, :8].astype('float') alpha, beta = alignment_constant(pose_seqs[0, 0], ref_pose) pose_seqs = pose_seqs * alpha + beta[None, None, :, None] assert len(action_labels) == len(poses) print('Action names: ' + ', '.join(action_name_map)) print('Actions: ' + ', '.join(action_labels)) # important not to let return value be gc'd (anims won't run otherwise!) anims = draw_poses('Poses in %s' % vid_name, parents, pose_seqs, frame_paths=[frame_paths] * 3, subplot_titles=seq_names, fps=50 / 9.0, action_labels=action_labels) plt.show()