Ejemplo n.º 1
0
                clusterCount = hyperparameters["codebook_size"](featureCount)
                hyperparameters["codebook_size"] = clusterCount
                performance["codebook_size"] = clusterCount
                algo.gen_codebook(
                    TMP_DIR_TRAINING,
                    clusterCount,
                    currentCodebook,
                    batch_size=algo.BATCH_SIZE if algo.BATCH_SIZE >= clusterCount else clusterCount,
                )
                print "saved codebook to '" + currentCodebook + "'"
                performance["codebook"] = currentCodebook

                # generate histograms
                print "---------------------"
                print "## generating histograms of the training examples"
                algo.compute_histograms(TMP_DIR_TRAINING, currentCodebook, TMP_DIR_TRAINING)

                # iterate over different svm_c
                for svm_c in HYPERPARAMETERS_OPTIONS["svm_c"]:
                    hyperparameters["svm_c"] = svm_c
                    print "HYPERPARAMETER: svm_c = " + str(svm_c)

                    # iterate over different svm_gamma
                    for svm_gamma in HYPERPARAMETERS_OPTIONS["svm_gamma"]:
                        hyperparameters["svm_gamma"] = svm_gamma
                        print "HYPERPARAMETER: svm_gamma = " + str(svm_gamma)

                        # train svm
                        print "---------------------"
                        print "## training svm"
                        algo.train_svm(
Ejemplo n.º 2
0
        certainty = float(i.replace("\\","/").rpartition("/")[2].partition("_")[0])
        label = 1 if certainty > 0 else 0
        all_labels[i] = label
        all_weights[i] = certainty if label == 1 else 1-certainty


    # extract features
    featureCount = algo.extract_features(all_files, TMP_DIR)

    # generate codebook
    clusterCount = int(sqrt(featureCount))
    algo.gen_codebook(TMP_DIR, clusterCount, SIFT_CODEBOOK,
                      batch_size = algo.BATCH_SIZE if algo.BATCH_SIZE >= clusterCount else clusterCount)

    # generate histograms
    algo.compute_histograms(TMP_DIR, SIFT_CODEBOOK, TMP_DIR)

    # train svm
    algo.train_svm(TMP_DIR, all_labels, SVM_MODEL_FILE, all_weights = all_weights)

    print "calculating predictions"

    predictions = algo.predict(SVM_MODEL_FILE, SIFT_CODEBOOK, DATASETPATH2, TMP_DIR)


    img = Image.open('dop' +f + '/dop-annotated.png').convert('RGBA')
    overlay = Image.new('RGBA', img.size, 0)
    draw = ImageDraw.Draw(overlay)

    print "\n\nPredictions:"
    for filepath, is_building in predictions.items():