예제 #1
0
 def test_normalize_scale(self):
     ratios = []
     check_frame = self.frames[0]['jointPositions']['jointPositionDict']
     other_check_frame = normalize_scale(self.frames[:1], 'HipCenter', 'Head')[0]['jointPositions']['jointPositionDict']
     for first_joint in check_frame.keys():
         for second_joint in other_check_frame.keys():
             if first_joint == second_joint:
                 continue
             first_check_vector = check_frame[first_joint]
             second_check_vector = check_frame[second_joint]
             first_other_check_vector = other_check_frame[first_joint]
             second_other_check_vector = other_check_frame[second_joint]
             check_ratio = distance(
                 first_check_vector,
                 second_check_vector)
             other_check_ratio = distance(
                 first_other_check_vector,
                 second_other_check_vector)
             ratios.append(check_ratio / other_check_ratio)
     head = ratios[0]
     for i, ratio in enumerate(ratios):
         self.assertTrue(abs(ratio - head) < 0.0000001, (ratio, head))
예제 #2
0
                    split_items, load_option_info, load_skeleton_data, tweak)
from simanneal import Annealer
from normal import normalize_scale, normalize_origin
from copy import deepcopy

#if __name__ == '__main__': # Emacs doesn't like this.

OPTION_INFO = load_option_info('option.json')

## Build path to file.
EXPERIMENT_FILE_PATH = join(KINECT_EXPERIMENT_DIR, OPTION_INFO['dir_name'],
                            OPTION_INFO['file_name'])

## Open file and extract JSON frames data.
FRAMES = normalize_scale(
    normalize_origin(load_skeleton_data(EXPERIMENT_FILE_PATH), 'HipCenter'),
    'HipCenter', 'Head')


class KinectWeightsProblem(Annealer):
    'A class with methods defined for generating weights for classifying joint data.'

    def __init__(self, frames):
        self.frames = frames
        self.state = {
            joint: random.uniform(0.0, 0.5)
            for joint in self.frames[0]['jointPositions']
            ['jointPositionDict'].keys()
        }
        self.ideal_model = {
            joint: (0, 0, 0)
from random import seed
from time import clock

#if __name__ == '__main__': # Emacs doesn't like this.

OPTION_INFO = load_option_info('option.json')

## Build path to file.
EXPERIMENT_FILE_PATH  = join(
    KINECT_EXPERIMENT_DIR,
    OPTION_INFO['dir_name'],
    OPTION_INFO['file_name']
)

## Open file and extract JSON frames data.
FRAMES = normalize_scale(normalize_origin(load_skeleton_data(EXPERIMENT_FILE_PATH), 'HipCenter'),
                         'HipCenter', 'Head')

## Get the joint distances from the frame data.
DISTANCES = map(generate_distances, FRAMES)

## Split the distance data. Use one half for
## training and the other half for testing.
seed(OPTION_INFO['shuffle_seed'])
shuffle(DISTANCES)
TRAINING_DISTANCES, TESTING_DISTANCES = split_items(DISTANCES, 0.5)

seed(OPTION_INFO['training_seed'])
## Train the weights.
WEIGHTS, _ = KinectWeightsProblem(TRAINING_DISTANCES).anneal()

## Test the weights and display info on how well they work.