Ejemplo n.º 1
0
import sys
sys.path.append('../')
import automatic_test
import regressors
import reference_implementations
from extract_features import _feature_types, select_label_method, get_half_angle_vec
import extract_features
from plot_helper import plot_intersection, get_heatmap_from_distances_all_predictors, get_heatmap_from_polar_all_predictors
import numpy.random as random

feature_list = _feature_types

rf_algo = regressors.RandomForestAlgorithm(feature_list)
kitti_samples = automatic_test.load_samples('../data/training_data/samples_kitti/samples.pickle')
darmstadt_samples = automatic_test.load_samples('../data/training_data/samples_darmstadt/samples.pickle')
extract_features.select_label_method(kitti_samples, 'y_radii')
extract_features.select_label_method(darmstadt_samples, 'y_radii')
random.shuffle(kitti_samples)
random.shuffle(darmstadt_samples)
kitti_train_samples, kitti_test_samples = automatic_test.get_partitioned_samples(kitti_samples, 0.7)
darmstadt_train_samples, darmstadt_test_samples = automatic_test.get_partitioned_samples(darmstadt_samples, 0.7)
train_samples = kitti_train_samples + darmstadt_train_samples
test_samples = kitti_test_samples + darmstadt_test_samples

# samples = automatic_test.load_samples('../data/training_data/samples.pickle')
# # samples = automatic_test.normalize_features(samples)
# select_label_method(samples, 'y_distances')
# train_samples, test_samples = automatic_test.get_partitioned_samples(samples, 0.8)
# #automatic_test.test([rf_algo], train_samples, test_samples, cross_validation=False)
automatic_test.train([rf_algo], train_samples)
results = automatic_test.predict_all_estimators([rf_algo], test_samples)
Ejemplo n.º 2
0
    "curvature_entry",                          # Curvature of entry way over INT_DIST
    "curvature_exit",                           # Curvature of exit way over INT_DIST
    "bicycle_designated_entry",                 # Is there a designated bicycle way in the entry street?
    "bicycle_designated_exit",                  # Is there a designated bicycle way in the exit street?
    "lane_count_entry",                         # Total number of lanes in entry way
    "lane_count_exit",                          # Total number of lanes in exit way
    "has_right_of_way",                         # Does the vehicle with the respective manoeuver have right of way at the intersection?
    "curve_secant_dist"                         # Shortest distance from curve secant to intersection center
]

rf_algo = regressors.RandomForestAlgorithm(feature_list)
kitti_samples = automatic_test.load_samples('../data/training_data/samples_kitti/samples.pickle')
darmstadt_samples = automatic_test.load_samples('../data/training_data/samples_darmstadt/samples.pickle')
samples = kitti_samples + darmstadt_samples

select_label_method(samples, 'y_distances')
automatic_test.train([rf_algo], samples)
# Extract importances
importances = rf_algo.regressor.feature_importances_
std = np.std([tree.feature_importances_ for tree in rf_algo.regressor.estimators_], axis=0)
indices = np.argsort(importances)[::-1]
# Print the feature ranking
print("Feature ranking:")

for f in range(len(feature_list)):
    print("%d. %s (%f)" % (f + 1, feature_list[indices[f]], importances[indices[f]]))

# Plot the feature importances of the forest
plt.figure()
plt.title("Feature importances")
plt.bar(range(len(feature_list)), importances[indices],
Ejemplo n.º 3
0
    "lane_distance_along_curve_secant_exit",    # Distance of lane center line to curve secant ceter point at 180 degree angle
    "oneway_entry",                             # Is entry way a oneway street?
    "oneway_exit",                              # Is exit way a oneway street?
    "curvature_entry",                          # Curvature of entry way over INT_DIST
    "curvature_exit",                           # Curvature of exit way over INT_DIST
    "lane_count_entry",                         # Total number of lanes in entry way
    "lane_count_exit",                          # Total number of lanes in exit way
    "has_right_of_way",                         # Does the vehicle with the respective manoeuver have right of way at the intersection?
    "curve_secant_dist"                         # Shortest distance from curve secant to intersection center
]

random.seed(42)

kitti_samples = automatic_test.load_samples('../data/training_data/samples_kitti/samples.pickle')
darmstadt_samples = automatic_test.load_samples('../data/training_data/samples_darmstadt/samples.pickle')
extract_features.select_label_method(kitti_samples, 'y_distances')
extract_features.select_label_method(darmstadt_samples, 'y_distances')
random.shuffle(kitti_samples)
random.shuffle(darmstadt_samples)
kitti_train_samples, kitti_test_samples = automatic_test.get_partitioned_samples(kitti_samples, 0.7)
darmstadt_train_samples, darmstadt_test_samples = automatic_test.get_partitioned_samples(darmstadt_samples, 0.7)
train_samples = kitti_train_samples + darmstadt_train_samples
test_samples = kitti_test_samples + darmstadt_test_samples

parameter = "n_estimators"
values = np.arange(10,211,20)
runs = 10
params_mse = automatic_test.test_parameter_variations(regressors.RandomForestAlgorithm, {"features":feature_list, "random_state":random}, parameter, values, train_samples, test_samples, runs)
plt.plot(values, params_mse, 'b.-')
plt.xlabel(parameter)
plt.show()
Ejemplo n.º 4
0
    "lane_distance_exit_projected_normal",
    "oneway_entry",  # Is entry way a oneway street?
    "oneway_exit",  # Is exit way a oneway street?
    "curvature_entry",  # Curvature of entry way over INT_DIST
    "curvature_exit",  # Curvature of exit way over INT_DIST
    "bicycle_designated_entry",  # Is there a designated bicycle way in the entry street?
    "bicycle_designated_exit",  # Is there a designated bicycle way in the exit street?
    "lane_count_entry",  # Total number of lanes in entry way
    "lane_count_exit",  # Total number of lanes in exit way
    "has_right_of_way",  # Does the vehicle with the respective manoeuver have right of way at the intersection?
    "curve_secant_dist",  # Shortest distance from curve secant to intersection center
]

kitti_samples = automatic_test.load_samples("../data/training_data/samples_15_10_08/samples.pickle")
darmstadt_samples = automatic_test.load_samples("../data/training_data/samples_15_10_20_darmstadt/samples.pickle")
extract_features.select_label_method(kitti_samples, "y_distances")
extract_features.select_label_method(darmstadt_samples, "y_distances")
train_kitti, test_kitti = automatic_test.get_partitioned_samples(kitti_samples, 0.7)
train_darmstadt, test_darmstadt = automatic_test.get_partitioned_samples(darmstadt_samples, 0.7)
train_samples = train_kitti + train_darmstadt
test_samples = test_kitti + test_darmstadt
rf_algo = regressors.RandomForestAlgorithm(feature_list)

print "###### Non-rectified data ######"
print "------ Only KITTI ------"
automatic_test.test([rf_algo], train_kitti, test_kitti, cross_validation=False)
print "------ KITTI + Darmstadt ------"
automatic_test.test([rf_algo], train_samples, test_samples, cross_validation=False)

print "###### Rectified data ######"
kitti_samples_rectified = automatic_test.load_samples("../data/training_data/samples_15_10_08_rectified/samples.pickle")
Ejemplo n.º 5
0
    "oneway_exit",                              # Is exit way a oneway street?
    "curvature_entry",                          # Curvature of entry way over INT_DIST
    "curvature_exit",                           # Curvature of exit way over INT_DIST
    "bicycle_designated_entry",                 # Is there a designated bicycle way in the entry street?
    "bicycle_designated_exit",                  # Is there a designated bicycle way in the exit street?
    "lane_count_entry",                         # Total number of lanes in entry way
    "lane_count_exit",                          # Total number of lanes in exit way
    "has_right_of_way",                         # Does the vehicle with the respective manoeuver have right of way at the intersection?
    "curve_secant_dist"                         # Shortest distance from curve secant to intersection center
]

rf_algo = regressors.RandomForestAlgorithm(feature_list)
is_algo = reference_implementations.InterpolatingSplineAlgorithm()
kitti_samples = automatic_test.load_samples('../data/training_data/samples_15_10_12_rectified/samples.pickle')
darmstadt_samples = automatic_test.load_samples('../data/training_data/samples_15_10_20_darmstadt_rectified/samples.pickle')
select_label_method(kitti_samples, 'y_distances')
select_label_method(darmstadt_samples, 'y_distances')
train_samples_kitti, test_samples_kitti = automatic_test.get_partitioned_samples(kitti_samples, 0.7)
train_samples_darmstadt, test_samples_darmstadt = automatic_test.get_partitioned_samples(darmstadt_samples, 0.7)
train_samples = train_samples_kitti + train_samples_darmstadt
test_samples = test_samples_darmstadt + test_samples_kitti
automatic_test.train([rf_algo], train_samples)
results = automatic_test.predict_all_estimators([rf_algo], test_samples)
is_results = automatic_test.predict([is_algo], test_samples)

for sample, rf_prediction, rf_predictions_all_estimators, is_prediction in zip(test_samples,
                                                            results[rf_algo]['predictions'],
                                                            results[rf_algo]['predictions_all_estimators'],
                                                            is_results[is_algo]['predictions']):
    predicted_distances = [pred[0] for pred in rf_predictions_all_estimators]
    half_angle_vec = get_half_angle_vec(sample['geometry']['exit_line'], sample['X'][_feature_types.index('intersection_angle')])
Ejemplo n.º 6
0
    "oneway_exit",                              # Is exit way a oneway street?
    "curvature_entry",                          # Curvature of entry way over INT_DIST
    "curvature_exit",                           # Curvature of exit way over INT_DIST
    "vehicle_speed_entry",                      # Measured vehicle speed on entry way at INT_DIST
    "bicycle_designated_entry",                 # Is there a designated bicycle way in the entry street?
    "bicycle_designated_exit",                  # Is there a designated bicycle way in the exit street?
    "lane_count_entry",                         # Total number of lanes in entry way
    "lane_count_exit",                          # Total number of lanes in exit way
    "has_right_of_way",                         # Does the vehicle with the respective manoeuver have right of way at the intersection?
    "curve_secant_dist"                         # Shortest distance from curve secant to intersection center
]

rf_algo_distances = regressors.RandomForestAlgorithm(feature_list)
samples_distances = automatic_test.load_samples('../data/training_data/samples.pickle')
# samples = automatic_test.normalize_features(samples)
select_label_method(samples_distances, 'y_distances')
train_sample_sets_distances, test_sample_sets_distances = automatic_test.get_cross_validation_samples(samples_distances, 0.8, 5)

rf_algo_radii = regressors.RandomForestAlgorithm(feature_list)
samples_radii = automatic_test.load_samples('../data/training_data/samples.pickle')
# samples = automatic_test.normalize_features(samples)
select_label_method(samples_radii, 'y_radii')
train_sample_sets_radii, test_sample_sets_radii = automatic_test.get_cross_validation_samples(samples_radii, 0.8, 5)

for train_samples_distances, test_samples_distances, train_samples_radii, test_samples_radii in zip(train_sample_sets_distances, test_sample_sets_distances, train_sample_sets_radii, test_sample_sets_radii):
    automatic_test.train([rf_algo_distances], train_samples_distances)
    results_distances = automatic_test.predict_all_estimators([rf_algo_distances], test_samples_distances)

    automatic_test.train([rf_algo_radii], train_samples_radii)
    results_radii = automatic_test.predict_all_estimators([rf_algo_radii], test_samples_radii)