コード例 #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
コード例 #2
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