Ejemplo n.º 1
0
    def get_hmms(self):

        for gesture_type in self.gesture_types:

            print_status("Get_Hmms",
                         "Fitting for gesture_type: " + gesture_type)

            ### Step 1: fill hmm_examples appropriately ###
            hmm_examples = []
            for gesture in self.gestures[gesture_type]:
                hmm_rep = gesture.get_hmm_rep()
                hmm_examples.append(hmm_rep)

            ### Step 2: fit parameters for the hmm ###
            hmm = GaussianHMM(self.num_hmm_states)
            hmm.fit(hmm_examples)

            ### Step 3: store the hmm in self.hmms ###
            self.hmms[gesture_type] = hmm

            print_inner_status(
                gesture_type,
                "predicted the following sequences: (score: sequence)")
            for example in hmm_examples:
                print "		", hmm.score(example), ": ", hmm.predict(example)
Ejemplo n.º 2
0
    def get_correspondences(self):

        print_inner_status("Get correspondences", "getting the intervals")

        ### Step 1: get all of the beat indeces, pop indeces ###
        self.beat_indeces = [
            i for i in range(len(self.original_skeletons))
            if self.original_skeletons[i].beat == 1
        ]

        beat_intervals = []

        ### Step 2: get a list of beat intervals ###
        prev_beat = 0
        for i in range(len(self.beat_indeces) - 1):
            cur_beat = self.beat_indeces[i]
            next_beat = self.beat_indeces[i + 1]

            beat_interval = Beat_Interval(cur_beat, prev_beat, next_beat)
            beat_intervals.append(beat_interval)

            prev_beat = cur_beat

        ### for each beat_interval, iterate through each skeleton and select the top prob ###
        self.correspondences = []
        for beat_interval in beat_intervals:

            best_prob = -1.0
            best_index = -1
            best_class = -1
            for i in range(beat_interval.interval_start,
                           beat_interval.interval_end):
                pop_probability = self.original_skeletons[i].pop_probability
                print i, ": ", pop_probability
                # for index, p in enumerate(pop_probability[1:]): 	#use this for binary classification
                for index, p in enumerate(
                        pop_probability[:-1]
                ):  #use this for multiple-class classification
                    if p > best_prob:
                        best_index = i
                        best_prob = p
                        best_class = index

            self.correspondences.append((beat_interval.beat_index, best_index))
            print "### best_prob: ", best_prob
            print "### best_index: ", best_index
            print "### best_class: ", best_class

        ### Success up to here - correspondences is now filled with (beat, best pop) index pairs ###
        ### Now mark beat/pop and write it out
        self.marked_skeletons = self.original_skeletons
        self.pop_indeces = [i[1] for i in self.correspondences]
        for i in range(len(self.marked_skeletons)):
            if i in set(self.pop_indeces):
                self.marked_skeletons[i].pop = 1
            else:
                self.marked_skeletons[i].pop = 0
Ejemplo n.º 3
0
	def get_correspondences (self):

		print_inner_status ("Get correspondences", "getting the intervals")

		### Step 1: get all of the beat indeces, pop indeces ###
		self.beat_indeces = [i for i in range(len(self.original_skeletons)) if self.original_skeletons[i].beat == 1]

		beat_intervals = []

		### Step 2: get a list of beat intervals ###
		prev_beat = 0
		for i in range (len(self.beat_indeces) - 1):
			cur_beat 	= self.beat_indeces [i]
			next_beat 	= self.beat_indeces [i + 1] 

			beat_interval = Beat_Interval (cur_beat, prev_beat, next_beat)
			beat_intervals.append (beat_interval)

			prev_beat = cur_beat



		### for each beat_interval, iterate through each skeleton and select the top prob ###
		self.correspondences = []
		for beat_interval in beat_intervals:

			best_prob = -1.0
			best_index = -1
			best_class = -1
			for i in range (beat_interval.interval_start, beat_interval.interval_end):
				pop_probability = self.original_skeletons[i].pop_probability
				print i, ": ", pop_probability
				# for index, p in enumerate(pop_probability[1:]): 	#use this for binary classification
				for index, p in enumerate (pop_probability[:-1]):	#use this for multiple-class classification
					if p > best_prob:
						best_index = i
						best_prob = p
						best_class = index



			self.correspondences.append ((beat_interval.beat_index, best_index))
			print "### best_prob: ", best_prob
			print "### best_index: ", best_index
			print "### best_class: ", best_class



		### Success up to here - correspondences is now filled with (beat, best pop) index pairs ###
		### Now mark beat/pop and write it out
		self.marked_skeletons = self.original_skeletons
		self.pop_indeces = [i[1] for i in self.correspondences]
		for i in range(len(self.marked_skeletons)):
			if i in set(self.pop_indeces):
				self.marked_skeletons[i].pop = 1
			else:
				self.marked_skeletons[i].pop = 0
Ejemplo n.º 4
0
    def save_examples (self):

        print_status ("Save Examples", "Begin")
        ### Step 1: save self.all_examples ###
        for meme_type, meme_list in self.all_examples.iteritems ():
            save_filename = self.get_examples_pickle_filename (meme_type)
            print_inner_status ("Save Examples", "Saving to " + save_filename)
            pickle.dump (meme_list, open(save_filename, 'w'))
        print_status ("Save Examples", "End")
Ejemplo n.º 5
0
    def get_examples (self):

        ### Step 1: fill self.all_examples ###
        self.all_examples = {}
        print_status ("Get Examples", "Begin")
        for meme_type, meme_list in self.memes.iteritems():
            print_inner_status ("Get Examples", "Converting to feature vectors: " + meme_type)
            self.all_examples [meme_type] = [m.get_features () for m in meme_list]
        print_status ("Get Examples", "Complete")
Ejemplo n.º 6
0
    def load_memes (self):

        print_status ("Loading memes", "Begin")
        meme_pkl_filenames = [f for f in os.listdir (self.memes_directory) if f[-4:] == '.pkl']
        for meme_pkl_filename in meme_pkl_filenames:

            full_filename = os.path.join (self.memes_directory, meme_pkl_filename)
            meme_type = meme_pkl_filename[:-4]
            print_inner_status ("Load Memes", "Loading " + full_filename)
            self.memes[meme_type]      = pickle.load (open(full_filename, 'r'))
        print_status ("Loading memes", "End")
Ejemplo n.º 7
0
    def load_examples (self):

        print_status ("Load Examples", "Begin")
        self.all_examples = {}
        example_filenames = [f for f in os.listdir (self.examples_directory) if f[-12:] == '.feature_vec'] 
        for example_filename in example_filenames:

            full_filename = os.path.join (self.examples_directory, example_filename)
            meme_type = example_filename[:-12]
            print_inner_status ("Load Examples", "Loading " + meme_type)
            self.all_examples [meme_type] = pickle.load(open(full_filename, 'r'))
        print_status ("Load Examples", "Complete")
Ejemplo n.º 8
0
	def load_gestures (self):

		### Step 1: initialize self.gestures ###
		self.gestures = {}

		### Step 2: get all gesture types ###
		self.get_gesture_types ()

		### Step 3: get all gesture dirs ###
		self.get_gesture_dirs () 

		### Step 4: for each gesture_type, load in all gestures ###
		for gesture_type in self.gesture_types:
			print_inner_status ("Gesture Recognizer (load_gestures)", "Loading gestures of type " + str(gesture_type))
			self.load_gestures_of_type (gesture_type)
Ejemplo n.º 9
0
    def load_gestures(self):

        ### Step 1: initialize self.gestures ###
        self.gestures = {}

        ### Step 2: get all gesture types ###
        self.get_gesture_types()

        ### Step 3: get all gesture dirs ###
        self.get_gesture_dirs()

        ### Step 4: for each gesture_type, load in all gestures ###
        for gesture_type in self.gesture_types:
            print_inner_status("Gesture Recognizer (load_gestures)",
                               "Loading gestures of type " + str(gesture_type))
            self.load_gestures_of_type(gesture_type)
Ejemplo n.º 10
0
	def get_hmms (self):

		for gesture_type in self.gesture_types:

			print_status ("Get_Hmms", "Fitting for gesture_type: " + gesture_type)
			### Step 1: fill hmm_examples appropriately ###
			hmm_examples = []
			for gesture in self.gestures[gesture_type]:
				hmm_rep = gesture.get_hmm_rep ()
				hmm_examples.append (hmm_rep)

			### Step 2: fit parameters for the hmm ###
			hmm = GaussianHMM (self.num_hmm_states)
			hmm.fit (hmm_examples)

			### Step 3: store the hmm in self.hmms ###
			self.hmms[gesture_type] = hmm

			print_inner_status (gesture_type, "predicted the following sequences: (score: sequence)")
			for example in hmm_examples:
				print "		", hmm.score (example), ": ", hmm.predict (example)
Ejemplo n.º 11
0
	def __init__ (self, sync_directory, classifier_name):

		### Step 1: filename management ###
		print_inner_status ("Initialization", "Looking at file " + sync_directory)
		self.jvid_filename_raw 				= os.path.join(sync_directory, 'Raw/video.jvid')
		self.jvid_filename_pops_marked 		= os.path.join(sync_directory, 'Marked/video.jvid')
		self.jvid_filename_synchronized 	= os.path.join(sync_directory, 'Synced/video.jvid')

		### Step 2: load the classifier ###
		print_inner_status ("Initialization", "Unpickling the classifier")
		self.classifier = pickle.load (open('/Users/jhack/Programming/NI/ni_template/python_backend/classifiers/toprock_front_training.obj', 'r'))

		### Step 2: get the original skeletons ###
		print_inner_status ("Initialization", "Getting input skeletons")
		self.original_skeletons = read_in_skeletons (self.jvid_filename_raw)

		### Step 3: add derivatives to them ###
		print_inner_status ("Initialization", "Adding derivatives to skeletons")		
		self.original_skeletons = add_derivatives_to_skeletons(self.original_skeletons, 5, 10, 5, 10)

		### Step 4: add pop probabilities to them ###
		print_inner_status ("Initialization", "Adding pop probabilities to skeletons")
		self.original_skeletons = mark_pop_probabilities (self.original_skeletons, self.classifier)
Ejemplo n.º 12
0
    def __init__(self, sync_directory, classifier_name, mode):

        ### Step 1: filename management ###
        print_inner_status("Initialization",
                           "Looking at file " + sync_directory)
        self.jvid_filename_raw = os.path.join(sync_directory, 'Raw/video.jvid')
        self.jvid_filename_pops_marked = os.path.join(sync_directory,
                                                      'Marked/video.jvid')
        self.jvid_filename_synchronized = os.path.join(sync_directory,
                                                       'Synced/video.jvid')

        ### Step 2: get the original skeletons ###
        print_inner_status("Initialization", "Getting input skeletons")
        self.original_skeletons = read_in_skeletons(self.jvid_filename_raw)

        ### Step 3: add derivatives to them ###
        print_inner_status("Initialization", "Adding derivatives to skeletons")
        self.original_skeletons = add_derivatives_to_skeletons(
            self.original_skeletons, 5, 10, 5, 10)

        ### Step 4: set up the classifier filename ###
        self.classifier_filename = os.path.join(
            os.getcwd(), 'python_backend/classifiers/' + classifier_name)

        ### Step 5.0: if synchronize mode, load the classifier and mark probabilities ###
        if mode == 'synchronize':

            print_inner_status("Initialization", "Loading the classifier")
            self.load_classifier(
                '/Users/jhack/Programming/NI/ni_template/python_backend/classifiers/toprock_front_training.obj'
            )

            print_inner_status("Initialization",
                               "Adding pop probabilities to skeletons")
            self.original_skeletons = mark_pop_probabilities(
                self.original_skeletons, self.classifier)

        ### Step 5.1: if train mode, train the classifier and save it ###
        elif mode == 'train':

            print_inner_status("Initialization", "Training the classifier")
            self.train_classifier()

            print_inner_status("Initialization", "Saving the classifier")
            self.save_classifier()

        return
Ejemplo n.º 13
0
	def __init__ (self, sync_directory, classifier_name, mode):

		### Step 1: filename management ###
		print_inner_status ("Initialization", "Looking at file " + sync_directory)
		self.jvid_filename_raw 				= os.path.join(sync_directory, 'Raw/video.jvid')
		self.jvid_filename_pops_marked 		= os.path.join(sync_directory, 'Marked/video.jvid')
		self.jvid_filename_synchronized 	= os.path.join(sync_directory, 'Synced/video.jvid')

		### Step 2: get the original skeletons ###
		print_inner_status ("Initialization", "Getting input skeletons")
		self.original_skeletons = read_in_skeletons (self.jvid_filename_raw)

		### Step 3: add derivatives to them ###
		print_inner_status ("Initialization", "Adding derivatives to skeletons")		
		self.original_skeletons = add_derivatives_to_skeletons(self.original_skeletons, 5, 10, 5, 10)

		### Step 4: set up the classifier filename ###
		self.classifier_filename = os.path.join (os.getcwd(), 'python_backend/classifiers/' + classifier_name)

		### Step 5.0: if synchronize mode, load the classifier and mark probabilities ###
		if mode == 'synchronize':
	
			print_inner_status ("Initialization", "Loading the classifier")
			self.load_classifier ('/Users/jhack/Programming/NI/ni_template/python_backend/classifiers/toprock_front_training.obj')

			print_inner_status ("Initialization", "Adding pop probabilities to skeletons")			
			self.original_skeletons = mark_pop_probabilities (self.original_skeletons, self.classifier)

		### Step 5.1: if train mode, train the classifier and save it ###
		elif mode == 'train':

			print_inner_status ("Initialization", "Training the classifier")
			self.train_classifier ()

			print_inner_status ("Initialization", "Saving the classifier")
			self.save_classifier ()

		return