loaded = np.load(DATA_FILE) raw_training_vectors = loaded['input_geoms'] raw_target_vectors = loaded['intersection'] training_vectors = [] target_vectors = [] # skip non-intersecting geometries for train, target in zip(raw_training_vectors, raw_target_vectors): if not target[0, 0] == 0: # a zero coordinate designates an empty geometry training_vectors.append(train) target_vectors.append(target) means = localized_mean(training_vectors) training_vectors = localized_normal(training_vectors, means, 1e4) target_vectors = localized_normal(target_vectors, means, 1e4) (data_points, max_points, INPUT_VECTOR_LEN) = training_vectors.shape # Expand the target vectors to gaussian mixture model size compatible with the prediction format component_1 = target_vectors[:, :, 0:5] # The first gaussian mixture model component for each point component_1 = np.append(component_1, np.zeros((data_points, max_points, 1)), axis=2) # Add pi feature target_vectors = np.append( np.reshape( np.repeat(component_1, GAUSSIAN_MIXTURE_COMPONENTS, axis=1), (data_points, max_points, 6 * GAUSSIAN_MIXTURE_COMPONENTS)), target_vectors[:, :, 5:], axis=2) output_size = GAUSSIAN_MIXTURE_COMPONENTS * 6 + ONE_HOT_LEN Loss = GaussianMixtureLoss(GAUSSIAN_MIXTURE_COMPONENTS, max_points)
osm_vectors = [] surface_area_vectors = [] combined_geom_vectors = [] # skip non-intersecting geometries for brt, osm, target, combined in zip(raw_brt_vectors, raw_osm_vectors, raw_surface_area_vectors, raw_combined_geom_vectors): if not target[0] == 0: # a zero coordinate designates an empty geometry brt_vectors.append(brt) osm_vectors.append(osm) surface_area_vectors.append(target) combined_geom_vectors.append(combined) # data whitening means = localized_mean(combined_geom_vectors) brt_vectors = localized_normal(brt_vectors, means, 1e4) osm_vectors = localized_normal(osm_vectors, means, 1e4) surface_area_vectors = np.array(surface_area_vectors) # shape determination data_points, brt_max_points, brt_seq_len = brt_vectors.shape _, osm_max_points, osm_seq_len = osm_vectors.shape brt_inputs = Input(shape=(brt_max_points, brt_seq_len)) brt_model = LSTM(brt_max_points * 2, activation='relu')(brt_inputs) osm_inputs = Input(shape=(osm_max_points, osm_seq_len)) osm_model = LSTM(osm_max_points * 2, activation='relu')(osm_inputs) concat = concatenate([brt_model, osm_model])
def test_dummy_geom(self): dummy_means = localized_mean(dummy_geom) dummy_localized = localized_normal(dummy_geom, dummy_means) self.assertEqual(dummy_localized[0, 0, FULL_STOP_INDEX], 1)
0., 0., ]]]) dummy_geom = np.array( [[[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]) means = localized_mean(input_geom) scaled = localized_normal(input_geom, means) class TestGeomScaler(unittest.TestCase): def test_scaling(self): self.assertAlmostEqual(scaled[0, 0, 0], -0.4763) self.assertAlmostEqual(scaled[0, 0, 1], 0.3646) self.assertAlmostEqual(scaled[0, 9, 0], -0.4263) self.assertAlmostEqual(scaled[0, 9, 1], 0.3136) def test_localized_mean(self): self.assertAlmostEqual(means[0, 0, 0], 6.7232059) self.assertAlmostEqual(means[0, 0, 1], 52.1477995) corrected = input_geom corrected[:, 0:10, 0:2] -= means corrected[:, 0:10, 0:2] *= 1e4
raw_intersection_vectors = loaded['intersection'] brt_vectors = [] osm_vectors = [] intersection_vectors = [] # skip non-intersecting geometries for brt, osm, target in zip(raw_brt_vectors, raw_osm_vectors, raw_intersection_vectors): if not target[0, 0] == 0: # a zero coordinate designates an empty geometry brt_vectors.append(brt) osm_vectors.append(osm) intersection_vectors.append(target) # data whitening means = localized_mean(intersection_vectors) brt_vectors = localized_normal(brt_vectors, means, 1e4) osm_vectors = localized_normal(osm_vectors, means, 1e4) intersection_vectors = localized_normal(intersection_vectors, means, 1e4) # shape determination (data_points, brt_max_points, BRT_INPUT_VECTOR_LEN) = brt_vectors.shape (_, osm_max_points, OSM_INPUT_VECTOR_LEN) = osm_vectors.shape target_max_points = intersection_vectors.shape[1] output_seq_length = (GAUSSIAN_MIXTURE_COMPONENTS * 6) + ONE_HOT_LEN output_size_2d = target_max_points * output_seq_length Loss = GaussianMixtureLoss(num_components=GAUSSIAN_MIXTURE_COMPONENTS, num_points=target_max_points) brt_inputs = Input(shape=(brt_max_points, BRT_INPUT_VECTOR_LEN)) brt_model = LSTM(brt_max_points * 2, activation='relu')(brt_inputs)
loaded = np.load(DATA_FILE) raw_training_vectors = loaded['input_geoms'] raw_target_vectors = loaded['intersection'] input_vectors = [] target_vectors = [] # skip non-intersecting geometries for train, target in zip(raw_training_vectors, raw_target_vectors): if not target[0, 0] == 0: # a zero coordinate designates an empty geometry input_vectors.append(train) target_vectors.append(target) print('Preprocessing vectors...') means = localized_mean(input_vectors) input_vectors = localized_normal(input_vectors, means, 1e4) input_vectors = np.array( [GeoVectorizer.interpolate(vector, DENSIFIED) for vector in input_vectors]) target_vectors = localized_normal(target_vectors, means, 1e4) target_vectors = np.array( [GeoVectorizer.interpolate(vector, 50) for vector in target_vectors]) (data_points, max_input_points, INPUT_VECTOR_LEN) = input_vectors.shape (_, max_target_points, _) = target_vectors.shape output_size = GAUSSIAN_MIXTURE_COMPONENTS * 6 + GEOM_TYPE_LEN + RENDER_LEN Loss = GaussianMixtureLoss(GAUSSIAN_MIXTURE_COMPONENTS, max_target_points) inputs = Input(shape=(max_input_points, INPUT_VECTOR_LEN)) model = Dense(INPUT_VECTOR_LEN, activation='relu')(inputs)