Ejemplo n.º 1
0
    all_accuracies_list = []
    all_labels = []
    for current_classifier in selected_classifiers:
        print(
            "~ Running program with {} classifier.".format(current_classifier))
        classifier = Classifier(current_classifier)

        accuracy_list = []
        start_time = time.time()
        for i, (train, test) in enumerate(
                kfold_cross_validation(data, k=int(args["kfold"]))):
            samples, labels = parse_samples_labels(train)
            classifier.fit(samples, labels)

            samples, labels = parse_samples_labels(test)
            accuracy = classifier.accuracy(samples, labels)

            if args["verbose"]:
                print("+ [{:02d}/10] accuracy: {:3d}%".format(
                    i + 1, int(accuracy * 100)))

            if draw_confusion_matrix:
                confusion_matrix = classifier.confusion_matrix(samples, labels)

            accuracy_list.append(accuracy)

        all_accuracies_list.append(accuracy_list)
        all_labels.append(current_classifier)

        if args["verbose"]:
            print("- Took {:.2f} seconds.".format(time.time() - start_time))
Ejemplo n.º 2
0
data = DataProvider(cars_paths,
                    non_cars_paths,
                    car_id=car_id,
                    non_car_id=non_car_id,
                    test_size=0.2)
data.save_labels_info_graph()
data.save_random_images(car_id, "../training_results/random_car_images.png")
data.save_random_images(non_car_id,
                        "../training_results/random_non_car_images.png")

print("Training is in progress...")
clf.train(data.train.features, data.train.labels)

print("Training time: {:.2f} min.".format(clf.training_time / 60))
accuracy = clf.accuracy(data.test.features, data.test.labels)
print("Test accuracy: {:.3f}%.".format(accuracy * 100))

space = "-" * 50
info = [
    "Accuracy: {:.4f}%".format(accuracy * 100), space,
    "\t- Features vector compound parts -", "features_providers: [{}]".format(
        ", ".join([type(i).__name__ for i in features_providers
                   ])), "color_space: {}".format(color_space),
    "classifier_image_size: {}".format(classifier_image_size), space,
    "\t- Spatial binning of color parameters -",
    "spatial_binning_size: {}".format(spatial_binning_size), space,
    "\t- Color histogram parameters -",
    "color_histogram_n_bins: {}".format(color_histogram_n_bins),
    "bins_range: {}".format(bins_range), space,
    "\t- Histogram of oriented gradients parameters -",