示例#1
0
def get_data(input_txt_file, input_image_dir, mean_image, beaconmap,
             mean_beacon, use_fixed_input_mean_std):
    image_filenames = []
    poses = []
    images = []
    beacons = []

    with open(input_txt_file) as f:
        # skip header
        next(f)
        next(f)
        next(f)
        for line in f:
            fname, beaconstr, p0, p1, p2, p3, p4, p5, p6 = line.split()
            quat = posenet_geom_utils.preprocess_quaternion(
                [float(p3), float(p4),
                 float(p5), float(p6)])

            p0 = float(p0)
            p1 = float(p1)
            p2 = float(p2)
            p3 = quat[0]
            p4 = quat[1]
            p5 = quat[2]
            p6 = quat[3]
            poses.append((p0, p1, p2, p3, p4, p5, p6))
            image_filenames.append(os.path.join(input_image_dir, fname))
            beacon = posenet_beacon_utils.parse_beacon_string(
                beaconstr, beaconmap)
            beacons.append(beacon)
    beacons = posenet_beacon_utils.preprocess_test_beacons(
        beacons, mean_beacon, use_fixed_input_mean_std)
    return datasource(image_filenames, beacons, poses), image_filenames
def get_data(input_txt_file, input_image_dir):
    image_filenames = []
    poses = []

    with open(input_txt_file) as f:
        # skip header
        next(f)
        next(f)
        next(f)
        for line in f:
            fname, p0, p1, p2, p3, p4, p5, p6 = line.split()
            quat = posenet_geom_utils.preprocess_quaternion(
                [float(p3), float(p4),
                 float(p5), float(p6)])

            p0 = float(p0)
            p1 = float(p1)
            p2 = float(p2)
            p3 = quat[0]
            p4 = quat[1]
            p5 = quat[2]
            p6 = quat[3]
            poses.append((p0, p1, p2, p3, p4, p5, p6))
            image_filenames.append(os.path.join(input_image_dir, fname))
    return datasource(image_filenames, poses), image_filenames
示例#3
0
def get_beacon_data(input_txt_file, beaconmap, beacon_num,
                    use_fixed_input_mean_std, use_augmentation_beacon):
    poses_index = []
    beacons_index = []
    poses_data = []
    beacons_data = []

    with open(input_txt_file) as f:
        # skip header
        next(f)
        next(f)
        next(f)
        for line in f:
            beaconstr, p0, p1, p2, p3, p4, p5, p6 = line.split()
            quat = posenet_geom_utils.preprocess_quaternion(
                [float(p3), float(p4),
                 float(p5), float(p6)])

            p0 = float(p0)
            p1 = float(p1)
            p2 = float(p2)
            p3 = quat[0]
            p4 = quat[1]
            p5 = quat[2]
            p6 = quat[3]
            poses_data.append((p0, p1, p2, p3, p4, p5, p6))
            poses_index.append(len(poses_data) - 1)

            beacon = posenet_beacon_utils.parse_beacon_string(
                beaconstr, beaconmap)
            beacons_data.append(beacon)
            beacons_index.append(len(beacons_data) - 1)

            if use_augmentation_beacon:
                nonzero_idxs = np.nonzero(beacon)[0]
                num_augment_beacon = int(
                    math.ceil(
                        len(nonzero_idxs) *
                        posenet_config.ratio_beacon_augmentation))
                for idx in range(0, posenet_config.num_beacon_augmentation):
                    poses_index.append(len(poses_data) - 1)

                    augment_beacon = np.copy(beacon)
                    for idx_augment in range(0, num_augment_beacon):
                        random_idx = int(
                            np.random.uniform(0.0, 1.0) *
                            (len(nonzero_idxs) - 1))
                        augment_beacon_idx = nonzero_idxs[random_idx]
                        augment_beacon[augment_beacon_idx][0][0] = math.floor(
                            augment_beacon[augment_beacon_idx][0][0] *
                            np.random.uniform(0.0, 1.0))
                    beacons_data.append(augment_beacon)
                    beacons_index.append(len(beacons_data) - 1)

    beacons_data, mean_beacon = posenet_beacon_utils.preprocess_beacons(
        beacons_data, beacon_num, use_fixed_input_mean_std)
    return beacon_datasource(beacons_index, poses_index, beacons_data,
                             poses_data), mean_beacon
示例#4
0
def get_image_data(input_txt_file,
                   input_image_dir,
                   use_fixed_input_mean_std,
                   image_size=224):
    poses_index = []
    images_index = []
    poses_data = []
    images_data = []

    with open(input_txt_file) as f:
        # skip header
        next(f)
        next(f)
        next(f)
        for line in f:
            fname, p0, p1, p2, p3, p4, p5, p6 = line.split()
            quat = posenet_geom_utils.preprocess_quaternion(
                [float(p3), float(p4),
                 float(p5), float(p6)])

            p0 = float(p0)
            p1 = float(p1)
            p2 = float(p2)
            p3 = quat[0]
            p4 = quat[1]
            p5 = quat[2]
            p6 = quat[3]
            poses_data.append((p0, p1, p2, p3, p4, p5, p6))
            poses_index.append(len(poses_data) - 1)

            images_data.append(os.path.join(input_image_dir, fname))
            images_index.append(len(images_data) - 1)

    images_data, mean_image = posenet_image_utils.preprocess(
        images_data, use_fixed_input_mean_std, image_size=image_size)
    return image_datasource(images_index, poses_index, images_data,
                            poses_data), mean_image