예제 #1
0
    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():
        filename = os.path.basename(filepath)
        coverage, x, y = os.path.splitext(filename)[0].split('_')
        x = int(x); y = int(y)
        #print '{coverage}: {is_building}'.format(coverage=coverage, is_building=is_building[0])
        if is_building[0] == 1:
            draw.rectangle([x,y,x+PATCH_SIZE, y+PATCH_SIZE], fill=(0x8a, 0x2b, 0xe2, 0x55), outline='grey')
        else:
예제 #2
0
파일: train.py 프로젝트: ratatatata/ML-OSM
                        FP = 0
                        TN = 0
                        FN = 0

                        R = 0
                        I = 0
                        for f in validation_files:
                            if all_labels[os.path.basename(f)] == 1:
                                R += 1
                            else:
                                I += 1

                        algo.__clear_dir(TMP_DIR_VALIDATION)
                        predictions = algo.predict(
                            SVM_MODEL_FILE + str(len(performances)),
                            currentCodebook,
                            VALIDATIONSET_DIR,
                            TMP_DIR_VALIDATION,
                        )
                        for f, p in predictions.items():
                            if p[0] == 1:
                                if all_labels[os.path.basename(f)] == 1:
                                    TP += 1
                                else:
                                    FP += 1
                            else:
                                if all_labels[os.path.basename(f)] == 1:
                                    FN += 1
                                else:
                                    TN += 1
                        TPR = float(TP) / float(R)
                        FPR = float(FP) / float(I)
예제 #3
0
 # generate patches
 print "---------------------"
 print "## generating patches from '" + IMG_NAME + "' (" + str(IMG_SIZE[0])+"x"+str(IMG_SIZE[1]) + "; " + str(IMG_BBOX) + ")"
 patch_generator.generate_patches(IMG_BBOX, IMG_SIZE,
     patch_size=params['hyperparameters']['patch_size'], 
     offset_steps=params['hyperparameters']['patch_offset'],
     target_folder=DATASET_DIR,
     force_refresh=False,
     data_folder=IMG_NAME,
 )
 print ""
 
 # predict
 print "---------------------"
 print "## predicting"
 predictions = algo.predict(SVM_MODEL_FILE, SIFT_CODEBOOK_FILE, DATASET_DIR, TMP_DIR)
 
 
 # generate visualization
 print "---------------------"
 print "## generating visualization"
 
 img = Image.open(SATELLITE_IMG_VISUALIZATION_INPUT)
 overlay = Image.new('RGB', img.size, 0)
 draw = ImageDraw.Draw(overlay)  
 
 print "\n\nPredictions:"
 for filepath, is_building in predictions.items():
     filename = os.path.basename(filepath)
     print filename
     coverage, x, y = os.path.splitext(filename)[0].split('_')