def load_gestures_of_type(self, gesture_type): ### Step 1: initialize list of gestures of this type ### self.gestures[gesture_type] = [] ### Step 2: get all filenames from the appropriate gesture_dir ### gesture_filenames = [ os.path.join(self.gesture_dirs[gesture_type], g) for g in os.listdir(self.gesture_dirs[gesture_type]) ] ### Step 3: for each filename, load in a gesture from it and add to list ### for gesture_filename in gesture_filenames: ### --- create the gesture --- ### new_gesture = Gesture(name=gesture_type, observations_filepath=gesture_filename) ### --- make sure it is full/clean --- ### if not new_gesture.is_full(): print_error("Loading Gestures", "Encountered a gesture that is not yet full") ### --- add to the list of gestures --- ### self.gestures[gesture_type].append(new_gesture)
def add_derivatives_to_skeletons (skeletons, fd_interval_1, fd_interval_2, sd_interval_1, sd_interval_2): if (fd_interval_1 >= fd_interval_2): print_error ("fd_interval_1 is <= fd_interval_2", "make sure that 1 is smaller than 2") if (sd_interval_1 >= sd_interval_2): print_error ("sd_interval_1 is <= sd_interval_2", "make sure that 1 is smaller than 2") ### Step 1: get the first and second derivatives ### # NOTE: you will want to f**k with this until you seem to be getting it right... joints = [s.joints for s in skeletons] fd_1_raw = get_derivatives (joints, fd_interval_1) fd_2_raw = get_derivatives (joints, fd_interval_2) sd_1_raw = get_derivatives (fd_1_raw, sd_interval_1) sd_2_raw = get_derivatives (sd_1_raw, sd_interval_2) ### Step 4: associate them with the original skeletons ### considering_skeletons = skeletons[fd_interval_2 + sd_interval_2:] fd_1 = fd_1_raw [sd_interval_2:] fd_2 = fd_2_raw [sd_interval_2:] sd_1 = sd_1_raw sd_2 = sd_2_raw for i in range(len(considering_skeletons)): considering_skeletons[i].fd_1 = fd_1[i] considering_skeletons[i].fd_2 = fd_2[i] considering_skeletons[i].sd_1 = sd_1[i] considering_skeletons[i].sd_2 = sd_2[i] return considering_skeletons
def __init__ (self): print_welcome ("Autosynch", "Jay Hack", "Summer 2013") ### Step 1: get the recordings directory ### self.recordings_dir = os.path.join (os.getcwd(), 'Recordings') if not os.path.exists (self.recordings_dir): print_error ("Autosynch_Interface Initialization", "cannot find recordings directory") ### Step 2: get all of the recordings ### self.get_all_recordings ()
def load_gestures_of_type (self, gesture_type): ### Step 1: initialize list of gestures of this type ### self.gestures[gesture_type] = [] ### Step 2: get all filenames from the appropriate gesture_dir ### gesture_filenames = [os.path.join (self.gesture_dirs[gesture_type], g) for g in os.listdir (self.gesture_dirs[gesture_type])] ### Step 3: for each filename, load in a gesture from it and add to list ### for gesture_filename in gesture_filenames: ### --- create the gesture --- ### new_gesture = Gesture (name=gesture_type, observations_filepath=gesture_filename) ### --- make sure it is full/clean --- ### if not new_gesture.is_full (): print_error ("Loading Gestures", "Encountered a gesture that is not yet full") ### --- add to the list of gestures --- ### self.gestures[gesture_type].append (new_gesture)
def create_new_recording (self, recording_name): recording_filepath = os.path.join (recordings_dir, recording_name + '.sync') if (os.path.exists (recording_filepath)): print_error ("create_new_sync_dir", "specified file already exists") ### Step 2: create the top-level '.sync' directory ### os.mkdir (recording_filepath) ### Step 2: make the raw/marked/synced directories, along with jvid directories ### os.mkdir (os.path.join (recording_filepath, "Raw")) os.mkdir (os.path.join (recording_filepath, "Raw/video.jvid")) os.mkdir (os.path.join (recording_filepath, "Marked")) os.mkdir (os.path.join (recording_filepath, "Marked/video.jvid")) os.mkdir (os.path.join (recording_filepath, "Synced")) os.mkdir (os.path.join (recording_filepath, "Synced/video.jvid")) new_recording = Recording (recording_name, recording_filepath) self.all_recordings.append (new_recording) return new_recording
def interface_main (self): viable_options =['r', 't', 's'] ### Step 1: get their requested mode ### print_message ("What mode would you like to enter?") print " - R: record mode" print " - T: train mode" print " - S: synth mode" response = raw_input ("---> ") response = response.lower () if not response in viable_options: print_error ("Main Interface Loop", "did not recognize the mode you selected") if response == 'r': while (True): self.record_main () elif response == 't': self.train_main () else: while (True): self.synth_main ()
def interface_main(self): viable_options = ['r', 't', 's'] ### Step 1: get their requested mode ### print_message("What mode would you like to enter?") print " - R: record mode" print " - T: train mode" print " - S: synth mode" response = raw_input("---> ") response = response.lower() if not response in viable_options: print_error("Main Interface Loop", "did not recognize the mode you selected") if response == 'r': while (True): self.record_main() elif response == 't': self.train_main() else: while (True): self.synth_main()
def check_name (self): if not self.name: print_error ("Initialize", "This spider does not have a name!")
os.remove (color_filename_new) if (os.path.exists (depth_filename_new)): os.remove (depth_filename_new) os.symlink (color_filename_old, color_filename_new); os.symlink (depth_filename_old, depth_filename_new); if __name__ == "__main__": ### Step 1: manage args ### if len(sys.argv) < 3: print_error ("Not enough args", "Usage: ./synchronize.py [.sync file] [classifier_name]") sync_dir = sys.argv[1] classifier_name = sys.argv[2] ### Step 2: get the synchronizer ### synchronizer = Synchronizer (sync_dir, classifier_name) #--- FOR DEBUGGING --- print "\n\n##########[ --- SYNCHRONIZER OUTPUT --- ]##########" pops = [i for i in range(len(synchronizer.skeletons)) if synchronizer.skeletons[i].pop] beats = [i for i in range(len(synchronizer.skeletons)) if synchronizer.skeletons[i].beat] print "--- correspondences ---" print synchronizer.correspondences print "--- BEATS ---"
# Function: print_txt # ------------------- # prints out the skeletons as text files (more primitive...) def record_to_txt(skletons, outfile_name): outfile = open(outfile_name, 'w') for skeleton in skeletons: outfile.write(skeleton.__str__()) return if __name__ == "__main__": ### Step 1: get/sanitize args ### args = sys.argv if len(args) != 3: print_error("Not enough arguments", "Usage: ./convert_to_json.py infile outfile") infile_name = args[1] outfile_name = args[2] ### Step 2: read in infile ### print_status("Main", "Opening infile") entire_infile = open(infile_name, 'r').read() skeletons = read_in_skeletons(entire_infile) ### Step 2: write out skeletons ### print_status("Main", "Writing in txt format to outfile") record_to_txt(skeletons, outfile_name) ### Step 3: get json representation ### # print_status("Main", "Getting json representations") # json_skeletons_list = [s.json () for s in skeletons]
print "true_label | prediction: ", true_label, " | ", prediction_prob, " | ", prediction print "--- RESULTS ---" print 'hits: ', hits print 'misses: ', misses print 'accuracy: ', float(hits) / float(hits + misses) if __name__ == "__main__": print_status("Train Classifier", "Starting") ### Step 1: manage args ### if len(sys.argv) < 3: print_error( "Not enough args", "Usage: ./train_classifier.py [infile] [classifier_name] [(load|save|test)]" ) infile_name = sys.argv[1] classifier_name = sys.argv[2] if 'load' in sys.argv: load = True else: load = False if 'save' in sys.argv: save = True else: save = False if 'test' in sys.argv: test = True else: test = False
print "--- RESULTS ---" print 'hits: ', hits print 'misses: ', misses print 'accuracy: ', float(hits)/float(hits+misses) if __name__ == "__main__": print_status ("Train Classifier", "Starting") ### Step 1: manage args ### if len(sys.argv) < 3: print_error ("Not enough args", "Usage: ./train_classifier.py [infile] [classifier_name] [(load|save|test)]") infile_name = sys.argv[1] classifier_name = sys.argv[2] if 'load' in sys.argv: load = True else: load = False if 'save' in sys.argv: save = True else: save = False if 'test' in sys.argv: test = True else: test = False
def check_name(self): if not self.name: print_error("Initialize", "This spider does not have a name!")
def send_message(self, message): if not self.UDPSock.sendto(message, self.addr): print_error("Max Interface", "Failed to send gesture" + str(message) + " to Max")
# Function: print_txt # ------------------- # prints out the skeletons as text files (more primitive...) def record_to_txt(skletons, outfile_name): outfile = open(outfile_name, "w") for skeleton in skeletons: outfile.write(skeleton.__str__()) return if __name__ == "__main__": ### Step 1: get/sanitize args ### args = sys.argv if len(args) != 3: print_error("Not enough arguments", "Usage: ./convert_to_json.py infile outfile") infile_name = args[1] outfile_name = args[2] ### Step 2: read in infile ### print_status("Main", "Opening infile") entire_infile = open(infile_name, "r").read() skeletons = read_in_skeletons(entire_infile) ### Step 2: write out skeletons ### print_status("Main", "Writing in txt format to outfile") record_to_txt(skeletons, outfile_name) ### Step 3: get json representation ### # print_status("Main", "Getting json representations") # json_skeletons_list = [s.json () for s in skeletons]
#--- copy over the synced files --- # print color_filename_old + " -> " + color_filename_new if (os.path.exists(color_filename_new)): os.remove(color_filename_new) if (os.path.exists(depth_filename_new)): os.remove(depth_filename_new) os.symlink(color_filename_old, color_filename_new) os.symlink(depth_filename_old, depth_filename_new) if __name__ == "__main__": ### Step 1: manage args ### if len(sys.argv) < 3: print_error("Not enough args", "Usage: ./synchronize.py [.sync file] [classifier_name]") sync_dir = sys.argv[1] classifier_name = sys.argv[2] ### Step 2: get the synchronizer ### synchronizer = Synchronizer(sync_dir, classifier_name) #--- FOR DEBUGGING --- print "\n\n##########[ --- SYNCHRONIZER OUTPUT --- ]##########" pops = [ i for i in range(len(synchronizer.skeletons)) if synchronizer.skeletons[i].pop ] beats = [ i for i in range(len(synchronizer.skeletons)) if synchronizer.skeletons[i].beat
def send_message (self, message): if not self.UDPSock.sendto(message, self.addr): print_error ("Max Interface", "Failed to send gesture" + str(message) + " to Max")