def main(weights, num, batch_file, opt_pose_steps, opt_shape_steps): K.set_session( tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions( allow_growth=True)))) model = Octopus(num=num) with open(batch_file, 'r') as f: reader = csv.reader(f, delimiter=' ') for name, segm_dir, pose_dir, out_dir in reader: print('Processing {}...'.format(name)) model.load(weights) segm_files = sorted(glob(os.path.join(segm_dir, '*.png'))) pose_files = sorted(glob(os.path.join(pose_dir, '*.json'))) if len(segm_files) != len(pose_files) or len(segm_files) == len( pose_files) == 0: print('> Inconsistent input.') continue segmentations = [read_segmentation(f) for f in segm_files] joints_2d, face_2d = [], [] for f in pose_files: j, f = openpose_from_file(f) if len(j) != 25 or len(f) != 70: print('> Invalid keypoints.') continue joints_2d.append(j) face_2d.append(f) if opt_pose_steps: print('> Optimizing for pose...') model.opt_pose(segmentations, joints_2d, opt_steps=opt_pose_steps) if opt_shape_steps: print('> Optimizing for shape...') model.opt_shape(segmentations, joints_2d, face_2d, opt_steps=opt_shape_steps) print('> Estimating shape...') pred = model.predict(segmentations, joints_2d) write_mesh('{}/{}.obj'.format(out_dir, name), pred['vertices'][0], pred['faces']) print('> Done.')
def main(weights, name, segm_dir, pose_dir, out_dir, opt_pose_steps, opt_shape_steps): segm_files = sorted(glob(os.path.join(segm_dir, '*.png'))) pose_files = sorted(glob(os.path.join(pose_dir, '*.json'))) if len(segm_files) != len(pose_files) or len(segm_files) == len(pose_files) == 0: exit('Inconsistent input.') K.set_session(tf.Session(config=tf.ConfigProto( gpu_options=tf.GPUOptions(allow_growth=True)))) model = Octopus(num=len(segm_files)) model.load(weights) segmentations = [read_segmentation(f) for f in segm_files] joints_2d, face_2d = [], [] for f in pose_files: j, f = openpose_from_file(f) assert(len(j) == 25) assert(len(f) == 70) joints_2d.append(j) face_2d.append(f) if opt_pose_steps: print('Optimizing for pose...') model.opt_pose(segmentations, joints_2d, opt_steps=opt_pose_steps) if opt_shape_steps: print('Optimizing for shape...') model.opt_shape(segmentations, joints_2d, face_2d, opt_steps=opt_shape_steps) print('Estimating shape...') pred = model.predict(segmentations, joints_2d) write_mesh('{}/{}.obj'.format(out_dir, name), pred['vertices'][0], pred['faces']) print('Done.')
def main(weights, name, segm_dir, pose_dir, out_dir, opt_pose_steps, opt_shape_steps, opt_size): segm_files = sorted(glob(os.path.join(segm_dir, '*.png'))) pose_files = sorted(glob(os.path.join(pose_dir, '*.json'))) if len(segm_files) != len(pose_files) or len(segm_files) == len( pose_files) == 0: exit('Inconsistent input.') K.set_session( tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions( allow_growth=True)))) model = Octopus(num=len(segm_files)) #Octopus 모델은 그대로 1080,1080 기준으로 생성 model.load(weights) segmentations = [read_segmentation(f) for f in segm_files] joints_2d, face_2d = [], [] for f in pose_files: #pose를 720 기준으로 스케일링 j, f = openpose_from_file(f, resolution=(opt_size, opt_size)) assert (len(j) == 25) assert (len(f) == 70) joints_2d.append(j) face_2d.append(f) if opt_pose_steps: print('Optimizing for pose...') model.opt_pose(segmentations, joints_2d, opt_steps=opt_pose_steps) if opt_shape_steps: print('Optimizing for shape...') model.opt_shape(segmentations, joints_2d, face_2d, opt_steps=opt_shape_steps) print('Estimating shape...') pred = model.predict(segmentations, joints_2d) os.makedirs(out_dir, exist_ok=True) write_mesh_custom(os.path.join(out_dir, name + '.obj'), pred['vertices'][0], pred['faces']) width = 1080 height = 1080 camera_c = [540.0, 540.0] camera_f = [1080, 1080] vertices = pred['vertices'] data_to_save = { 'width': width, 'camera_c': camera_c, 'vertices': vertices, 'camera_f': camera_f, 'height': height } pickle_out = open('{}/frame_data.pkl'.format(out_dir), "wb") pickle.dump(data_to_save, pickle_out) pickle_out.close() print('Done.') print('Done.')
def main(weights, name, segm_dir, pose_dir, out_dir, opt_pose_steps, opt_shape_steps): segm_files = sorted(glob(os.path.join(segm_dir, '*.png'))) pose_files = sorted(glob(os.path.join(pose_dir, '*.json'))) if len(segm_files) != len(pose_files) or len(segm_files) == len( pose_files) == 0: exit('Inconsistent input.') K.set_session( tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions( allow_growth=True)))) model = Octopus(num=len(segm_files)) model.load(weights) segmentations = [read_segmentation(f) for f in segm_files] joints_2d, face_2d = [], [] for f in pose_files: j, f = openpose_from_file(f) assert (len(j) == 25) assert (len(f) == 70) joints_2d.append(j) face_2d.append(f) if opt_pose_steps: print('Optimizing for pose...') model.opt_pose(segmentations, joints_2d, opt_steps=opt_pose_steps) if opt_shape_steps: print('Optimizing for shape...') model.opt_shape(segmentations, joints_2d, face_2d, opt_steps=opt_shape_steps) print('Estimating shape...') pred = model.predict(segmentations, joints_2d) ff = np.load("assets/basicModel_f.npy") ft = np.load("assets/basicModel_ft.npy") vt = np.load("assets/basicModel_vt.npy") v = pred['vertices'][0] # write_mesh('{}/{}.obj'.format(out_dir, name), pred['vertices'][0], pred['faces'],ff,ft,vt) with open('{}/{}.obj'.format(out_dir, name), 'w') as fp: fp.write(('v {:f} {:f} {:f}\n' * len(v)).format(*v.reshape(-1))) # fp.write(('f {:d} {:d} {:d}\n' * len(f)).format(*(f.reshape(-1) + 1))) for i in range(len(vt)): fp.write("vt " + str(vt[i][0]) + " " + str(vt[i][1]) + " " + str(1) + "\n") for i in range(len(ft)): fp.write("f " + str(ff[i][0] + 1) + '/' + str(ft[i][0] + 1) + " " + str(ff[i][1] + 1) + '/' + str(ft[i][1] + 1) + " " + str(ff[i][2] + 1) + '/' + str(ft[i][2] + 1) + "\n") width = 1080 height = 1080 camera_c = [540.0, 540.0] camera_f = [1080, 1080] vertices = pred['vertices'] data_to_save = { 'width': width, 'camera_c': camera_c, 'vertices': vertices, 'camera_f': camera_f, 'height': height } pickle_out = open("5.pkl", "wb") pickle.dump(data_to_save, pickle_out) pickle_out.close() print('Done.') print('Done.')
def main(weights, name, in_dir, segm_dir, pose_dir, out_dir, opt_pose_steps, opt_shape_steps, openpose_model_dir, frame_data_name): segm_files = sorted( glob(os.path.join(segm_dir, '*.png')) + glob(os.path.join(segm_dir, '*.jpg'))) if pose_dir is None and openpose_model_dir is None: exit('No pose information available.') joints_2d, face_2d = [], [] if pose_dir is not None: pose_files = sorted(glob(os.path.join(pose_dir, '*.json'))) if len(segm_files) != len(pose_files) or len(segm_files) == len( pose_files) == 0: exit('Inconsistent input.') for f in pose_files: j, f = openpose_from_file(f) assert (len(j) == 25) assert (len(f) == 70) joints_2d.append(j) face_2d.append(f) elif openpose_model_dir is not None: from lib import openpose joints_2d, face_2d = openpose.process(in_dir, openpose_model_dir) K.set_session( tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions( allow_growth=True)))) model = Octopus(num=len(segm_files)) model.load(weights) segmentations = [read_segmentation(f) for f in segm_files] if opt_pose_steps: print('Optimizing for pose...') model.opt_pose(segmentations, joints_2d, opt_steps=opt_pose_steps) if opt_shape_steps: print('Optimizing for shape...') model.opt_shape(segmentations, joints_2d, face_2d, opt_steps=opt_shape_steps) print('Estimating shape...') pred = model.predict(segmentations, joints_2d) # Include texture coords in mesh vt = np.load('assets/basicModel_vt.npy') ft = np.load('assets/basicModel_ft.npy') write_mesh('{}/{}.obj'.format(out_dir, name), pred['vertices_tposed'], pred['faces'], vt=vt, ft=ft) # Output frame data if specified write_frame_data('{}/{}.pkl'.format(out_dir, frame_data_name), pred['vertices']) print('Done.')