Пример #1
0
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.')
Пример #2
0
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.')
Пример #3
0
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.')