Esempio n. 1
0
                print "---------------------"
                print "## extracting SIFT features"
                algo.__clear_dir(TMP_DIR_TRAINING)
                featureCount = algo.extract_features(training_files, TMP_DIR_TRAINING)
                performance["sift_feature_count"] = featureCount

                # generate codebook
                print "---------------------"
                print "## generating bag-of-words codebook"
                currentCodebook = SIFT_CODEBOOK_FILE + str(len(performances))
                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)
Esempio n. 2
0
    all_files = get_imgfiles(DATASETPATH)
    all_labels = {}
    all_weights = {}
    for i in all_files:
        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)