Ejemplo n.º 1
0
def test():
    classifiers = []
    classifiers.append(MMClassifier(trainname))

    log = ""
    accuracies = {}
    for i, c in enumerate(classifiers):
        n = 0
        correct = 0
        log += "Testing classifier %d\n" % i
        c.prep()
        print("training")
        c.train()
        print("evaluating")
        testset = dset_ops._load_dset(testname)
        for label, g in testset.gestures.items():
            log += "Testing gesture %s\n" % label
            for seq in g.sequences:
                n += 1
                prediction = c.classify(seq)
                log += "Predicted %s\n" % prediction
                if prediction == label:
                    correct += 1
        acc = float(correct) / n
        accuracies[i] = acc
        log += "Accuracy for classifier %d: %f\n\n" % (i, acc)
        print("PRINTING LOG")
        print(log)
        print("ACCURACIES")
        print(accuracies)
        with open('log.txt', 'w') as outfile:
            outfile.write(log)
Ejemplo n.º 2
0
def make_dsets():
    ds = dset_ops._load_dset(dset_to_test)

    # make temp train and test dsets
    dset_ops.make_dset(trainname, safe=False)
    dset_ops.make_dset(testname, safe=False)

    for label, g in ds.gestures.items():
        train_dset = dset_ops.make_gesture(trainname, label)
        test_dset = dset_ops.make_gesture(testname, label)

        sequences = g.sequences
        random.shuffle(sequences)
        trainseq = sequences[:num_gestures]
        testseq = sequences[num_gestures:]

        for trainelt in trainseq:
            print("adding example train")
            train_dset.store_gesture_example(label, trainelt)
            #dset_ops.add_gesture_example("train", label, trainelt, save=False)

        for testelt in testseq:
            print("adding example test")
            test_dset.store_gesture_example(label, testelt)
            #dset_ops.add_gesture_example("test", label, testelt, save=False)

    dset_ops._save_dset(train_dset)
    dset_ops._save_dset(test_dset)
Ejemplo n.º 3
0
    def __init__(self, dset_name, n_clusters=10):
        self.n_clusters = n_clusters
        self.dset_name = dset_name
        self.cached_dset = dset_ops._load_dset(self.dset_name).gestures
        self.gesture_set = []
        self.labels_array = []
        self.labels = []
        self.label_map = {}

        self.X = []
        self.prep()

        self.cluster_map = self.train(clusters=self.n_clusters)
        self.label()
        df = pd.DataFrame(self.label_map)
        df.to_csv("recognize/cluster_results/" + dset_name + ".csv")
Ejemplo n.º 4
0
    def __init__(self):
        self.CLASSIFIERS_BASE_PATH = "recognize/classifiers/"
        self.CONFIG = None
        self.CLASSIFIER = None
        self.DATASET_NAME = None

        with open('config.json', 'r') as infile:
            self.CONFIG = json.load(infile)

        self.DATASET_NAME = self.CONFIG['dataset']
        print("DATASET_NAME", self.DATASET_NAME)
        start = time()
        self.DATASET = dset_ops._load_dset(self.DATASET_NAME)
        end = time()
        print("time to load", end - start)

        self.wordlist = dset_ops.get_defined_gestures(self.DATASET_NAME)

        self.CLASSIFIER = NNClassifier(self.DATASET_NAME, dset=self.DATASET)
        self.CLASSIFIER.prep()
        self.CLASSIFIER.train()
Ejemplo n.º 5
0
    def _reload(self):
        self.cached_dset = dset_ops._load_dset(self.dset_name)

        # Convert the dataset into a form that is usable by this classifier
        samples, labels = [], []
        self.g_ids_to_names = {}
        self.g_id_count = 0

        for g_name, g in self.cached_dset.gestures.items():
            g_id = self._get_new_gid()
            self.g_ids_to_names[g_id] = g_name

            for seq in g.sequences:
                seq_norm = seq.normalize()
                frames = resize_seq(seq_norm.frames, self.num_frames)
                sample = np.concatenate(
                    list(map(lambda x: x.frame, frames))
                )  # a sample is the concatenation of all the frames in a single seq
                samples.append(sample)
                labels.append(int(g_id))

        self.X, self.Y = np.vstack(samples), np.array(labels)
Ejemplo n.º 6
0
from recognize.dt_classifier import DTClassifier
from data import dset_ops

dtc = DTClassifier("Practice")

print("prepping")
dtc.prep()

print("training")
dtc.train()

# grab a seq from the dset and try to classify it
ds = dset_ops._load_dset("Practice")
for label, g in ds.gestures.items():
    print("label", label)
    seq = g.sequences[0]
    break

print(dtc.classify(seq))
Ejemplo n.º 7
0
 def _reload(self): 
     print("reloading")
     self.cached_dset = dset_ops._load_dset(self.dset_name)