def predict(self, sample):
     predicted_line = self.get_interpolating_spline_line(sample)
     try:
         pred = sample_line_all(predicted_line,
                             sample['label']['selected_method'],
                             sample)
         return pred
     except:
         import plot_helper
         automatic_test.output_sample_features(sample)
         plot_helper.plot_intersection(sample, additional_lines=[predicted_line])
Beispiel #2
0
def show_intersection_plot(results, test_samples, results_proba={}, which_algorithms="all", which_samples="all", orientation="preserve"):
    print "Show intersection plot..."
    if which_algorithms == "all":
        which_algorithms = results.keys()
    plot_cases = {} # Contains the indices of the samples to be plotted and a plot title
    if which_samples == "all":
        plot_cases = {i:"Sample %d/%d" % (i, len(test_samples)) for i in range(len(test_samples))}
    if which_samples in ["best-case", "best-worst-case"]:
        for algo in which_algorithms:
            best_case_index = results[algo]['mse'].index(min(results[algo]['mse']))
            try:
                plot_cases[best_case_index] += " | Best case for " + algo.get_name()
            except:
                plot_cases[best_case_index] = "Best case for " + algo.get_name()
    if which_samples in ["worst-case", "best-worst-case"]:
        for algo in which_algorithms:
            worst_case_index = results[algo]['mse'].index(max(results[algo]['mse']))
            try:
                plot_cases[worst_case_index] += " | Worst case for " + algo.get_name()
            except:
                plot_cases[worst_case_index] = "Worst case for " + algo.get_name()
    for plot_index, plot_title in plot_cases.iteritems():
        cmap = plt.get_cmap('Paired')
        rgbcolors = [
        cmap(0.6),
        (0.,0.,1.),
        cmap(0.8)
        ]
        predicted_radii = []
        predicted_proba = []
        labels = []
        s = test_samples[plot_index]
        for algo in which_algorithms:
            predicted_radii.append(results[algo]['predictions'][plot_index])
            labels.append(algo.get_name())
        for algo in results_proba:
            # Append heatmap data together with bin characterstics of algorithm
            predicted_proba.append({
                            'predictions_proba': results_proba[algo]['predictions_proba'][plot_index],
                            'bin_num': results_proba[algo]['bin_num'],
                            'min_radius': results_proba[algo]['min_radius'],
                            'max_radius': results_proba[algo]['max_radius']
                        })
        # output_sample_features(s)
        plot_intersection(s, predicted_radii, rgbcolors=rgbcolors[:len(predicted_radii)], labels=labels, title=plot_title, orientation=orientation)
Beispiel #3
0
# select_label_method(sub_samples, 'y_radii')
# # train_samples, validation_samples = automatic_test.get_cross_validation_samples(sub_samples, 4)
# train_samples, validation_samples = automatic_test.get_partitioned_samples(sub_samples, 0.75)
# # Test 01 and 02
# automatic_test.train([whole_algo], train_samples)
# results = automatic_test.predict_all_estimators([whole_algo], validation_samples)
# for sample, prediction, predictions_all_estimators in zip(validation_samples, results[whole_algo]['predictions'], results[whole_algo]['predictions_all_estimators']):
#     automatic_test.output_sample_features(sample)
#     predicted_distances = [pred[0] for pred in predictions_all_estimators]
#     heatmap = get_heatmap_from_polar_all_predictors(predicted_distances, sample['geometry']['curve_secant'], sample['X'][_feature_types.index('intersection_angle')])
#     plot_intersection(sample, [prediction], rgbcolors=[cmap(0.6)], labels=[whole_algo.get_name()], heatmap=heatmap, orientation="curve-secant")


select_label_method(sub_samples, 'y_distances')
select_label_method(test_samples, 'y_distances')
# train_samples, validation_samples = automatic_test.get_cross_validation_samples(sub_samples, 4)
train_samples, validation_samples = automatic_test.get_partitioned_samples(sub_samples, 0.75)
# Test 03 and 04
automatic_test.train([whole_algo], train_samples)
# results = automatic_test.predict_all_estimators([whole_algo], test_samples)
results = automatic_test.predict_all_estimators([whole_algo], validation_samples)
for sample, prediction, predictions_all_estimators in zip(validation_samples, results[whole_algo]['predictions'], results[whole_algo]['predictions_all_estimators']):
# for sample, prediction, predictions_all_estimators in zip(test_samples, results[whole_algo]['predictions'], results[whole_algo]['predictions_all_estimators']):
    predicted_distances = [pred[0] for pred in predictions_all_estimators]
    half_angle_vec = get_half_angle_vec(sample['geometry']['exit_line'], sample['X'][_feature_types.index('intersection_angle')])
    heatmap = get_heatmap_from_distances_all_predictors(predicted_distances,
                                                    sample['geometry']['entry_line'],
                                                    sample['geometry']['exit_line'],
                                                    half_angle_vec)
    plot_intersection(sample, [prediction], rgbcolors=[cmap(0.6)], labels=[whole_algo.get_name()], heatmap=heatmap, orientation="curve-secant")
Beispiel #4
0
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)

for sample, prediction, predictions_all_estimators in zip(test_samples, results[rf_algo]['predictions'], results[rf_algo]['predictions_all_estimators']):
    predicted_distances = [pred[0] for pred in predictions_all_estimators]


    heatmap = get_heatmap_from_polar_all_predictors(predicted_distances, sample['geometry']['curve_secant'], sample['X'][_feature_types.index('intersection_angle')])

    # half_angle_vec = get_half_angle_vec(sample['geometry']['exit_line'], sample['X'][_feature_types.index('intersection_angle')])
    # heatmap = get_heatmap_from_distances_all_predictors(predicted_distances,
    #                                                 sample['geometry']['entry_line'],
    #                                                 sample['geometry']['exit_line'],
    #                                                 half_angle_vec)
    # plot_intersection(sample, predicted_distances, heatmap=heatmap, orientation="curve-secant")
    plot_intersection(sample, [prediction], rgbcolors=['b'], heatmap=heatmap, orientation="curve-secant")
Beispiel #5
0
#!/usr/bin/python
#coding:utf-8
# Extract single estimator regression predictions from RandomForestAlgorithm and display each line separately
import sys
sys.path.append('../')
import automatic_test
import regressors
import reference_implementations
from extract_features import _feature_types, select_label_method
from plot_helper import plot_intersection, get_heatmap_from_polar_all_predictors

feature_list = _feature_types

rf_algo = regressors.RandomForestAlgorithm(feature_list)
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)

for sample, predictions_all_estimators in zip(test_samples, results[rf_algo]['predictions_all_estimators']):
    predicted_radii = [pred[0] for pred in predictions_all_estimators]
    print predicted_radii
    heatmap = get_heatmap_from_polar_all_predictors(predicted_radii,
                                                    sample['geometry']['curve_secant'],
                                                    sample['X'][_feature_types.index('intersection_angle')])
    plot_intersection(sample, predicted_radii, heatmap=heatmap, orientation="preserve")
    # plot_intersection(sample, predicted_radii, orientation="preserve")
Beispiel #6
0
    "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')])
    heatmap = get_heatmap_from_distances_all_predictors(predicted_distances,
                                                    sample['geometry']['entry_line'],
                                                    sample['geometry']['exit_line'],
                                                    half_angle_vec)
    # plot_intersection(sample, predicted_distances, heatmap=heatmap, orientation="curve-secant")
    automatic_test.output_sample_features(sample, feature_list)
    plot_intersection(sample, [rf_prediction, is_prediction], rgbcolors=['b', 'g'], labels=['RF Algorithm', 'Spline Algorithm'], heatmap=heatmap, orientation="curve-secant")
Beispiel #7
0
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)

    for sample, prediction, predictions_all_estimators, prediction_radii in zip(test_samples_distances, results_distances[rf_algo_distances]['predictions'], results_distances[rf_algo_distances]['predictions_all_estimators'], results_radii[rf_algo_radii]['predictions']):
        automatic_test.output_sample_features(sample, rf_algo_distances.features)
        predicted_distances = [pred[0] for pred in predictions_all_estimators]
        half_angle_vec = get_half_angle_vec(sample['geometry']['exit_line'], sample['X'][_feature_types.index('intersection_angle')])
        heatmap = get_heatmap_from_distances_all_predictors(predicted_distances,
                                                        sample['geometry']['entry_line'],
                                                        sample['geometry']['exit_line'],
                                                        half_angle_vec)
        # plot_intersection(sample, predicted_distances, heatmap=heatmap, orientation="curve-secant")
        plot_intersection(  sample,
                            [prediction, prediction_radii],
                            rgbcolors=['b', 'c'],
                            label_methods=['y_distances', 'y_radii'],
                            labels=['distances', 'radii'],
                            title=sample['pickled_filename'],
                            heatmap=heatmap,
                            orientation="curve-secant")