Ejemplo n.º 1
0
    def start_menue(self):
        """Starting point of program."""

        utils.clear_screen()
        options = [
            "create NEW classifier", "load EXISTING classifier",
            "test parameters", "show high scores", "segment image",
            "test data manipulation", "settings"
        ]
        input = utils.menue("START MENUE:", options, True, False)

        if input == 1:
            self.create_classifier()
        elif input == 2:
            self.load_classifier()
        elif input == 3:
            self.test_parameters()
        elif input == 4:
            self.show_highscores()
        elif input == 5:
            self.segment_image()
        elif input == 6:
            self.test_data_menue()
        elif input == 7:
            self.show_settings()
        elif input == 8:
            return

        self.start_menue()
Ejemplo n.º 2
0
    def show_setting_SURF(self):
        utils.clear_screen()

        # print current settings
        print "SURF SETTINGS"
        print "Cross Val. k:\t\t", Settings.SU_CROSS_VALIDATION_K
        print "Test Segments:\t\t", Settings.SU_TESTDATA_SEGMENTS
        print "SVM Props:\t\t", Settings.SU_SVM_PARAMS
        print "BOW Dimension:\t\t", Settings.SU_BOW_DIMENSION

        options = ["change cross validation number", "change BOW Dimension"]
        input = utils.menue("OPTIONS:", options, False, True)

        if input == 1:
            Settings.SU_CROSS_VALIDATION_K = utils.value_setting(
                "Cross validation runs", "i", "1 means no cross validation.")
            self.save_settings()
            self.show_setting_SURF()
        elif input == 2:
            Settings.SU_BOW_DIMENSION = utils.value_setting(
                "Change BOW Dimension", "i", "default: 1000")
            self.save_settings()
            self.show_setting_SURF()
        else:
            self.show_settings()
Ejemplo n.º 3
0
    def show_setting_histogram(self):
        utils.clear_screen()

        # print current settings
        print "Histogram SETTINGS"
        print "Cross Val. k:\t\t", Settings.H_CROSS_VALIDATION_K
        print "Test Segments:\t\t", Settings.H_TESTDATA_SEGMENTS
        print "Image Segments:\t\t", Settings.H_IMAGE_SEGMENTS
        print "Bins per Color\t\t", Settings.H_BINS
        print "Range:\t\t\t", Settings.H_COLOR_RANGE
        print "Color Space:\t\t", Settings.H_COLOR_SPACE
        print "SVM Props:\t\t", Settings.H_SVM_PARAMS

        options = [
            "change cross validation number", "change image segmentation",
            "change number of bins", "change color range", "change color space"
        ]
        input = utils.menue("OPTIONS:", options, False, True)

        if input == 1:
            Settings.H_CROSS_VALIDATION_K = utils.value_setting(
                "Cross validation runs", "i", "1 means no cross validation.")
            self.save_settings()
            self.show_setting_histogram()
        elif input == 2:
            Settings.H_IMAGE_SEGMENTS = utils.radio_setting(
                "Number of Image Segments", Settings.H_IMAGE_SEGMENTS,
                ["1", "2", "4", "9", "16", "25"], [1, 2, 4, 9, 16, 25])
            self.save_settings()
            self.show_setting_histogram()
        elif input == 3:
            Settings.H_BINS = utils.value_setting(
                "Number of histogram bins per color", "i", "default: 64 bins")
            self.save_settings()
            self.show_setting_histogram()
        elif input == 4:
            lower = utils.value_setting("Lower range for color values", "i",
                                        "default: 0")
            upper = utils.value_setting("Upper range for color values", "i",
                                        "default: 256")
            Settings.H_COLOR_RANGE = [lower, upper]
            self.save_settings()
            self.show_setting_histogram()
        elif input == 5:
            Settings.H_COLOR_SPACE = utils.radio_setting(
                "Color Space", Settings.H_COLOR_SPACE, ["HSV", "RGB", "BGR"],
                [ColorSpace.HSV, ColorSpace.RGB, ColorSpace.BGR])
            self.save_settings()
            self.show_setting_histogram()
        else:
            self.show_settings()
Ejemplo n.º 4
0
    def show_model_screen(self):
        """
        Prints a model selection screen to the console window.

        Returns:
        ModelId
        """

        utils.clear_screen()
        options = ["SIFT kp/dp + BoW + SVM", "Histogram & SVM", "SURF kp/dp + BoW + SVM", "ORB kp/dp + BoW + SVM", "DAISY [deprecated]", "CenSurE kp, SIFT dp + BoW + SVM", "Late Fusion - SVM-Vectors", "LBP + SVM", "Neural Nets", "Late Fusion Majority Vote", "Random Keypoint Sampling"]
        modelId = utils.menue("Choose model:", options, False)
        if modelId == len(options):
            return -1
        return modelId
Ejemplo n.º 5
0
    def segment_image(self):
        """ Menu for image segmentation."""
        choice = utils.menue("[Image Segmentation",
                             ["Segment imgage", "Learn custom marker"],
                             showBackToMain=True)
        if choice == 2:
            self.learn_marker()
            return
        elif choice == 3:
            return

        im = load_image(utils.get_path_via_file_ui(), 1, 1)
        im = utils.equalize_image_size(im, 564000)
        seg = ObjectSegmentation()
        seg.process_image(im)
        im = seg.visulize_regions()
        cv.imwrite(utils.get_output_path() + "resultsMarker_regions.jpg", im)

        try:
            plt.imshow(cv.cvtColor(im, cv.COLOR_BGR2RGB), 'gray')
            plt.xticks([]), plt.yticks(
                [])  # to hide tick values on X and Y axis
            plt.show()
            utils.save_plt_figure(plt, "image_segments")
        except:
            print "Could not plot / show image. Saving instead."
            utils.save_plt_figure(plt, "image_segments")

        colorSeg = ColorSegmentation()
        colorSeg.process_image(seg.get_meal_image())
        resultImg, images, titles = colorSeg.visulize_regions(seg)

        # if matplotlib does not work use cv
        for i in range(len(images)):
            cv.imwrite(
                "C:/Users/felix/Desktop/Segmentation/results/resultsMarker_regionsArea{0}.jpg"
                .format(titles[i]), images[i])
            cv.imshow("Area {0}".format(titles[i]), images[i])
        cv.imshow("Result", resultImg)
        cv.imwrite(
            "C:/Users/felix/Desktop/Segmentation/results/resultsMarker_resultsImage.jpg",
            resultImg)
        cv.waitKey(0)

        # matplotlib
        utils.display_images([resultImg], titles="Result", columns=1, rows=1)
        utils.display_images(images, titles=titles)
Ejemplo n.º 6
0
    def show_settings(self):
        utils.clear_screen()

        # print current settings
        print "SETTINGS"
        print "DataSet:\t\t", self.show_default_dataset()
        print "High Eval Detail:\t", Settings.G_EVALUATION_DETAIL_HIGH
        print "Detailed output:\t", Settings.G_DETAILED_CONSOLE_OUTPUT
        print "Mail Notifications:\t", MailServer.are_mails_enabled()
        print "Auto report mailing:\t", Settings.G_AUTOMATIC_REPORT_MAILING

        options = [
            "change default data set", "change evaluation detail level",
            "change console output level", "SIFT Settings",
            "Histogram Settings", "SURF Settings", "Configure Mail Settings"
        ]
        input = utils.menue("OPTIONS:", options, False, True)

        if input == 1:
            self.change_default_dataset()
            self.show_settings()
        elif input == 2:
            Settings.G_EVALUATION_DETAIL_HIGH = utils.radio_setting(
                "Detail Level", Settings.G_EVALUATION_DETAIL_HIGH,
                ["High", "Low"], [True, False])
            self.save_settings()
            self.show_settings()
        elif input == 3:
            Settings.G_DETAILED_CONSOLE_OUTPUT = utils.radio_setting(
                "Console Output Detail", Settings.G_DETAILED_CONSOLE_OUTPUT,
                ["High", "Low"], [True, False])
            self.save_settings()
            self.show_settings()
        elif input == 4:
            self.show_setting_SIFT()
            self.show_settings()
        elif input == 5:
            self.show_setting_histogram()
            self.show_settings()
        elif input == 6:
            self.show_setting_SURF()
            self.show_settings()
        elif input == 7:
            self.show_setting_Mail()
            self.show_settings()
        elif input == 8:
            self.start_menue()
Ejemplo n.º 7
0
    def test_data_menue(self):
        utils.clear_screen()
        options = [
            "equalize test data image size", "add prefix to test data",
            "crop bounding boxes", "crop to square", "augment test data size",
            "cherry pick 'test data augmentation' iteration"
        ]
        input = utils.menue("Test data menue", options, False, True)

        if input == 1:
            self.normalize_testdata()
        elif input == 2:
            self.rename_prefix()
        elif input == 3:
            self.crop_bounding_boxes()
        elif input == 4:
            self.crop_test_data_to_square()
        elif input == 5:
            self.augment_test_data()
        elif input == 6:
            self.augment_test_data(True)
        else:
            return
        self.test_data_menue()
Ejemplo n.º 8
0
    def main_menue(self):
        """ Menu that is shown after classifier has been created or loaded."""

        # print params of loaded classifier
        modelUuid = MODEL_CONTROLLER.model.modelSaver.modelUuid
        ml = ModelLoader()
        try:
            params = ml.get_model_param(modelUuid)

            print "\n\nModel type:\t\t", params[0]
            print "Changed:\t\t", params[6]
            print "Name:\t\t\t", params[1]
            print "Model loss:\t\t", params[5]
            print "Model id:\t\t", modelUuid
            print "Model description:\t", params[2]
            print "Trained on:\t\t", params[3]
            print "\n"
        except:
            params = [""]

        options = [
            "mail reports", "predict random", "generate confusion matrix",
            "calculate accuracy results",
            "calculate accuracy results and insert score", "show high scores",
            "delete model", "predict image folder", "start webcam"
        ]

        if params[0].startswith("NN") or params[0].startswith("CNN"):
            options.extend([
                "continue training", "plot training history",
                "export training history to csv"
            ])

        input = utils.menue("MAIN MENUE:", options)

        if input == 1:
            self.predict_random_image()
        elif input == 2:
            self.predict_random_image()
        elif input == 3:
            self.create_confusion_matrix()
        elif input == 4:
            self.calculate_results()
            raw_input("Press any key to continue.")
        elif input == 5:
            self.calculate_results(True)
            raw_input("Press any key to continue.")
        elif input == 6:
            self.show_highscores()
        elif input == 7:
            remove_model(modelUuid)
            print "Model removed."
            return self.start_menue()
        elif input == 8:
            self.predict_image_folder()
            raw_input("Prediction finished. Press any key to continue.")
        elif input == 9:
            self.predict_webcam()
            raw_input("Prediction finished. Press any key to continue.")
        elif input == 10 and (params[0].startswith("NN")
                              or params[0].startswith("CNN")):
            # try to resume training
            MODEL_CONTROLLER.run_and_test(False)
        elif input == 11 and (params[0].startswith("NN")
                              or params[0].startswith("CNN")):
            MODEL_CONTROLLER.model.plot_training_history()
            raw_input("Plotting complete. Press any key to continue.")
        elif input == 12 and (params[0].startswith("NN")
                              or params[0].startswith("CNN")):
            MODEL_CONTROLLER.model.export_training_history_to_csv()
            raw_input("Exporting complete. Press any key to continue.")

        else:
            return self.start_menue()

        self.main_menue()
Ejemplo n.º 9
0
    def initialize(self):
        """ Method to load the classifiers and test them."""

        loader = ModelLoader()

        input = None
        testDataPath = None
        while True:
            input = utils.menue(
                "Majority Vote classifier",
                ["add classifier", "save", "test + finish", "finish"], False,
                True)
            if input == 2:
                self.modelSaver(self, -1)
                continue

            if input > 2:
                break

            # Display loading menu
            model = loader.show_loading_screen()
            if not model is None:
                if testDataPath is None:
                    testDataPath = model.testData.get_root_path()
                    self.modelSaver.datasetPath = testDataPath
                else:
                    # check if the test datasets are the same
                    if testDataPath != model.testData.get_root_path():
                        print "Could not load classifier {0} because the classifier was trained on different test data.".format(
                            model.name)
                        continue
                self.classifiers.append(
                    (1, model)
                )  # Tuple[0] = model weight (1 is default weight) | Tuple[1] = model

        # why did we leave the loop?
        if input == 5:
            print "Cancel"
            return False  # cancel -> back to start
        else:
            # initialize test data for the majority classifier

            # check if test data path has changed
            if not utils.check_if_dir_exists(testDataPath):
                testDataPath = utils.value_question(
                    "[...]", "Root path to new Dataset Path", "s")
            self.testData = TestData(testDataPath, 1, False)
            self.testData.segment_test_data({"test": 1})
            self.testData.new_segmentation()

            self.tester = ModelTester(self)

            # test classifier if input == 3
            if input == 3:
                # Be careful: the results might not reflect the actual accuracy of the classifier.
                # if not changed the tester will test on the whole test data set. This might include images that the
                # classifiers has been trained on. For a real accuracy test the images have to be separated manually.
                results = self.tester.test_classifier(["test"])
                self.tester.save_results(results, exportToCSV=False)
                print self.tester.format_results_string(results)
                testLoss = results["test"][1]
                save = utils.radio_question("[?]", "Save/Update classifier?",
                                            None, ["Yes", "No"], [True, False])
                if save:
                    self.modelSaver(self, testLoss)

            return self.classifiers != [
            ]  # finish. Return True if classifiers where loaded, False if not.