if __name__ == '__main__':
    logging.config.fileConfig('logging.conf')
    assert IMG_DIR.exists(), "You must first create segmented images"

    block_sizes = ((1, 1), (2, 2), (3, 3), (4, 4))
    cell_sizes  = ((4, 4), (6, 6), (8, 8), (12, 12), (16, 16))

    results = {}

    start_time = time.time()
    for cell_size in cell_sizes:
        for block_size in block_sizes:
            svm_time = time.time()

            logging.info("Block size: %s Cell size: %s", block_size, cell_size)
            logging.debug("Creating HOG features")
            do_hog(block_size=block_size, cell_size=cell_size,
                    char_size=(88, 88), window_size=(96, 96))

            logging.debug("Creating test and training sets")
            create_sets(FEATURE_DIR)

            logging.debug("Training SVM")
            SVM, accuracy = runSVM(FEATURE_DIR + 'train/',
                FEATURE_DIR + 'test/')
            logging.info("SVM training time: %f s", time.time() - svm_time)
            logging.info("SVM accuracy: %f", accuracy)

    logging.info("Total execution time: %f s", time.time() - start_time)
예제 #2
0
            logging.info("Block size: %s Cell size: %s", block_size, cell_size)
            logging.debug("Creating HOG features")
            w = (cell_size[0] - (target_width % cell_size[0])) + target_width
            h = (cell_size[1] - (target_height % cell_size[1])) + target_height

            if cell_size[0] * block_size[0] > w or \
               cell_size[1] * block_size[1] > h:
                logging.info("Skipping parameters")
                continue

            for i in range(10):
                svm_time = time.time()

                do_hog(block_size=block_size,
                       cell_size=cell_size,
                       char_size=(w, h),
                       window_size=(w + cell_size[0], h + cell_size[1]))

                logging.debug("Training SVM")
                SVM, accuracy = runSVM(HOG_DIR + 'train/', HOG_DIR + 'test/')
                logging.info("SVM training time: %f s", time.time() - svm_time)
                logging.info("SVM accuracy: %f", accuracy)

                with open(RESULTS_FILE, 'a') as f:
                    f.write('{},{},{},{},{},{},{},{}\n'.format(
                        num, cell_size[0], cell_size[1], block_size[0],
                        block_size[1], w, h, accuracy))
                num += 1

    logging.info("Total running time: %f s", time.time() - start_time)
예제 #3
0
            h = (cell_size[1] - (target_height % cell_size[1])) + target_height

            if cell_size[0] * block_size[0] > w or cell_size[1] * block_size[1] > h:
                logging.info("Skipping parameters")
                continue

            for i in range(10):
                svm_time = time.time()

                do_hog(
                    block_size=block_size,
                    cell_size=cell_size,
                    char_size=(w, h),
                    window_size=(w + cell_size[0], h + cell_size[1]),
                )

                logging.debug("Training SVM")
                SVM, accuracy = runSVM(HOG_DIR + "train/", HOG_DIR + "test/")
                logging.info("SVM training time: %f s", time.time() - svm_time)
                logging.info("SVM accuracy: %f", accuracy)

                with open(RESULTS_FILE, "a") as f:
                    f.write(
                        "{},{},{},{},{},{},{},{}\n".format(
                            num, cell_size[0], cell_size[1], block_size[0], block_size[1], w, h, accuracy
                        )
                    )
                num += 1

    logging.info("Total running time: %f s", time.time() - start_time)
예제 #4
0
from train.svm import runSVM
import create_segments

if __name__ == '__main__':
    if len(sys.argv) >= 2 and sys.argv[1] != "--create_segments":
        print("Usage: python %s [--create_segments]" % sys.argv[0])

    need_create_segments = len(sys.argv) == 2

    segmentDir = Path('tmp/segments/')
    featureDir = Path('tmp/features/')
    trainDir = featureDir + 'train/'
    testDir  = featureDir + 'test/'

    if need_create_segments:
        logging.info("Create segments of the images")
        create_segments.create_seg()

    logging.info("Creating HOG features")
    doHog(segmentDir, featureDir)

    logging.info("Creating train and test set")
    create_sets(featureDir, 0.7)

    logging.info("Running SVM")
    SVM, accuracy = runSVM(trainDir, testDir)
    logging.info("SVM accuracy: %f" % accuracy)
    with open('tmp/svm.pickle', 'w') as f:
        pickle.dump(SVM, f)
    logging.info("Done")