Пример #1
0
    def __init__(self,
                 jvid_filename,
                 recording_name,
                 classifier_name=None,
                 save=True,
                 test=False):

        print_status("Trainer", "Starting")

        ### Step 1: get in the original skeletons ###
        self.skeletons_raw = read_in_skeletons(jvid_filename)

        ### Step 2: add derivatives to them (fills skeletons_with_derivs) ###
        self.skeletons_with_derivs = add_derivatives_to_skeletons(
            self.skeletons_raw, self.fd_interval_1, self.fd_interval_2,
            self.fd_interval_1, self.fd_interval_2)

        ### Step 3: put it into training data form ###
        (X, Y) = self.get_training_data()

        ### Step 4: get it in training data form ###
        all_data = zip(X, Y)
        print "	### Number of examples: ", len(all_data)
        random.shuffle(all_data)

        training = all_data
        # training = all_data[:5000]
        # testing = all_data[5000:]
        #--- training ---
        X_train = [t[0] for t in training]
        Y_train = [t[1] for t in training]
        #--- testing ---
        # X_test = [t[0] for t in testing]
        # Y_test = [t[1] for t in testing]

        #--- get the classifier ---
        print_status("Trainer", "Training the classifier")
        self.classifier = LogisticRegression().fit(X_train, Y_train)

        #--- saving data ----
        if save:
            if classifier_name == None:
                classifier_name = recording_name.split('.')[0] + '.obj'
                classifier_name = os.path.join(os.getcwd(),
                                               'python_backend/classifiers',
                                               classifier_name)
            print_status("Trainer",
                         "Pickling the classifier at " + classifier_name)
            self.save_classifier(classifier_name)
Пример #2
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
Пример #3
0
	def __init__ (self, jvid_filename, recording_name, classifier_name=None, save=True, test=False):

		print_status ("Trainer", "Starting")

		### Step 1: get in the original skeletons ###
		self.skeletons_raw = read_in_skeletons (jvid_filename)

		### Step 2: add derivatives to them (fills skeletons_with_derivs) ###
		self.skeletons_with_derivs = add_derivatives_to_skeletons (self.skeletons_raw, self.fd_interval_1, self.fd_interval_2, self.fd_interval_1, self.fd_interval_2)

		### Step 3: put it into training data form ###
		(X, Y) = self.get_training_data ()

		### Step 4: get it in training data form ###
		all_data = zip(X, Y)
		print "	### Number of examples: ", len(all_data)
		random.shuffle (all_data);

		training = all_data
		# training = all_data[:5000]
		# testing = all_data[5000:]
		#--- training ---
		X_train = [t[0] for t in training]
		Y_train = [t[1] for t in training]
		#--- testing ---
		# X_test = [t[0] for t in testing]
		# Y_test = [t[1] for t in testing]



		#--- get the classifier ---
		print_status ("Trainer", "Training the classifier")
		self.classifier = LogisticRegression().fit(X_train, Y_train)


		#--- saving data ----
		if save:
			if classifier_name == None:
				classifier_name = recording_name.split('.')[0] + '.obj'
				classifier_name = os.path.join (os.getcwd (), 'python_backend/classifiers', classifier_name)
			print_status ("Trainer", "Pickling the classifier at " + classifier_name)
			self.save_classifier (classifier_name)
Пример #4
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
Пример #5
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)
Пример #6
0
    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

    ### Step 2: read in the skeleton timeseries and add derivatives to them ###
    skeletons = read_in_skeletons(infile_name)
    fd_interval_1 = 5
    fd_interval_2 = 10
    sd_interval_1 = 5
    sd_interval_2 = 10
    skeletons = add_derivatives_to_skeletons(skeletons, fd_interval_1,
                                             fd_interval_2, sd_interval_1,
                                             sd_interval_2)

    ### Step 3: put it into training data form ###
    (X, Y) = get_training_data(skeletons)

    ### Step 4: get it in training data form ###
    all_data = zip(X, Y)
    print "	### Number of examples: ", len(all_data)
    random.shuffle(all_data)
Пример #7
0
	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


	### Step 2: read in the skeleton timeseries and add derivatives to them ###
	skeletons = read_in_skeletons (infile_name)
	fd_interval_1 = 5
	fd_interval_2 = 10
	sd_interval_1 = 5
	sd_interval_2 = 10
	skeletons = add_derivatives_to_skeletons (skeletons, fd_interval_1, fd_interval_2, sd_interval_1, sd_interval_2)

	### Step 3: put it into training data form ###
	(X, Y) = get_training_data (skeletons)

	### Step 4: get it in training data form ###
	all_data = zip(X, Y)
	print "	### Number of examples: ", len(all_data)
	random.shuffle (all_data);

	training = all_data