示例#1
0
import create_segments
import sys
import logging

### Own modules
from general.hog import doHog
from general.pca import runPCA
from general.create_sets import create_sets
from train.svm import runSVM
from train.knn import runKNN

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

for k in range(19):
    k += 1
    avgAcc = 0.0
    for i in range(10):
        print "hog"
        doHog(segmentDir, featureDir, "xeryus")
        print "create sets"
        create_sets(featureDir)
        print "knn"
        kNN, accuracy = runKNN(trainDir, testDir, k, "hog")

        avgAcc += accuracy
    print "Average accuracy for k =", k, ":\t", avgAcc/10
    avgAcc = 0
示例#2
0
import create_segments
import sys
import logging

### Own modules
from general.hog import doHog
from general.pca import runPCA
from general.create_sets import create_sets
from train.svm import runSVM
from train.knn import runKNN

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

for k in range(19):
    k += 1
    avgAcc = 0.0
    for i in range(10):
        print "hog"
        doHog(segmentDir, featureDir, "xeryus")
        print "create sets"
        create_sets(featureDir)
        print "knn"
        kNN, accuracy = runKNN(trainDir, testDir, k, "hog")

        avgAcc += accuracy
    print "Average accuracy for k =", k, ":\t", avgAcc / 10
    avgAcc = 0
示例#3
0
    createSegments = False
    if len(sys.argv) == 2:
        createSegments = True

    ### Directories
    segmentDir = 'tmp/segments/'
    featureDir = 'tmp/features/'
    trainDir = featureDir + 'train/'

    ### First segment the training images
    if createSegments:
        logging.info("Creating segments of the images")
        create_segments.create_seg()

    ### Run hog over the segmented images
    ### Third argument for type of hog ("xeryus" or "other"), default = "xeryus"
    logging.info("Doing the HOG")
    doHog(segmentDir, featureDir)

    ### Create random train and test sets from the hog features
    # logging.info("Creating train and test set")
    create_sets(featureDir)

    ### Receive trained kNN (it also tests it on characters)
    logging.info("Running kNN")
    k = 10
    kNN = runKNN(trainDir, k)
    with open('tmp/knn.pickle', 'w') as f:
        pickle.dump(kNN, f)
示例#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")