Ejemplo n.º 1
0
def agg_movement_intervals(
        file_name,
        has_labels=False,
        train_on=['training1', 'training2', 'training3', 'training4']):
    from models import movement_interval

    df = skeletion_from_archive_cached(file_name)
    df = preprocessed_skeleton(file_name,
                               demain=True,
                               keep_only_top_40=False,
                               train_id=False,
                               drop_lower_joints=True,
                               dummy_gesture=False)

    df_interval = movement_interval(train_on=train_on)
    df_merge = pd.merge(df,
                        df_interval[['sample_id', 'frame', 'movement']],
                        on=['frame', 'sample_id'],
                        how='left')

    df_merge.sort(['sample_id', 'frame'], inplace=True)
    df_merge.fillna(method='ffill', inplace=True)
    df_merge.fillna(method='bfill', inplace=True)

    df_merge['interval'] = (df_merge.movement.shift(1) !=
                            df_merge.movement).astype(int).cumsum()
    # delete break frames tagged with gesture
    df_merge = df_merge[(df_merge.movement != 0)]

    # unify gestures in interval to most frequent one
    def smooth_gesture(df):
        df['gesture'] = df.gesture.value_counts().index[0]
        return df

    agg_functions = ['median', 'var', 'min', 'max']

    if has_labels:
        df_merge = df_merge.groupby(['interval']).apply(smooth_gesture)
        # drop intervalls without movement or if labelt as break
        df_merge = df_merge[(df_merge['gesture'] != 'break')
                            & (df_merge['movement'] == 1)]
        y_gest = df_merge[['sample_id', 'gesture',
                           'interval']].drop_duplicates()
        y_gest['gesture'] = np.array(
            [gesture_to_id[g] for g in y_gest.gesture])

    df_merge = df_merge.drop(['movement', 'frame'], axis=1)
    df_agg = df_merge.groupby(['sample_id', 'JointType', 'interval'
                               ]).agg(agg_functions).unstack('JointType')
    df_agg['_count'] = df_merge.groupby(['sample_id', 'JointType',
                                         'interval']).agg({
                                             'x_p': 'count'
                                         }).unstack('JointType')[('x_p',
                                                                  'HandRight')]

    if has_labels:
        return df_agg, y_gest
    return df_agg, None
Ejemplo n.º 2
0
def train_movement_model_and_merge_on_audio_interval(train_on, predict_on,
        path_to_audio_intervals, path_to_movement_model_with_audio_interval):


    df_out = movement_interval(train_on=train_on, predict_on=predict_on)
    df_out = df_out.groupby('sample_id').apply(pad_smooth, window_len=20)

    middle = pd.read_csv(path_to_audio_intervals, header=None, skiprows=1)
    middle = middle.ix[:, [0, 2]]
    middle.columns = ['sample_id', 'frame']
    middle_probs = pd.merge(middle, df_out, how='left', on=['sample_id', 'frame'])
    middle_probs = middle_probs.drop(['sample_id', 'frame', 0, 'movement'], axis=1)

    middle_probs.to_csv(path_to_movement_model_with_audio_interval, index=False)
def agg_movement_intervals(file_name, has_labels=False,
         train_on=['training1','training2', 'training3', 'training4']):
    from models import movement_interval


    df = skeletion_from_archive_cached(file_name)
    df = preprocessed_skeleton(file_name, demain=True, keep_only_top_40=False,
            train_id=False, drop_lower_joints=True, dummy_gesture=False)


    df_interval = movement_interval(train_on=train_on)
    df_merge = pd.merge(df, df_interval[['sample_id', 'frame', 'movement']], on=['frame', 'sample_id'], how='left')

    df_merge.sort(['sample_id', 'frame'], inplace=True)
    df_merge.fillna(method='ffill', inplace=True)
    df_merge.fillna(method='bfill', inplace=True)

    df_merge['interval'] = (df_merge.movement.shift(1) != df_merge.movement).astype(int).cumsum()
    # delete break frames tagged with gesture
    df_merge = df_merge[(df_merge.movement != 0)]

    # unify gestures in interval to most frequent one
    def smooth_gesture(df):
        df['gesture'] = df.gesture.value_counts().index[0]
        return df

    agg_functions=['median', 'var', 'min', 'max']

    if has_labels:
        df_merge = df_merge.groupby(['interval']).apply(smooth_gesture)
        # drop intervalls without movement or if labelt as break
        df_merge = df_merge[(df_merge['gesture'] != 'break') & (df_merge['movement'] == 1)]
        y_gest = df_merge[['sample_id', 'gesture', 'interval']].drop_duplicates()
        y_gest['gesture'] = np.array([gesture_to_id[g] for g in y_gest.gesture])

    df_merge = df_merge.drop(['movement', 'frame'], axis=1)
    df_agg = df_merge.groupby(['sample_id', 'JointType', 'interval']).agg(agg_functions).unstack('JointType')
    df_agg['_count'] = df_merge.groupby(['sample_id', 'JointType', 'interval']).agg({'x_p': 'count'}).unstack('JointType')[('x_p', 'HandRight')]

    if has_labels:
        return df_agg, y_gest
    return df_agg, None
Ejemplo n.º 4
0
    #window_length=30, retrain=False)
    #eval_gesture_model(window_shift=5,
    #window_length=20, retrain=False)

    #leaderboard_model(retrain=True)
    #leaderboard_model(window_shift=1)
    #leaderboard_model(window_shift=5)
    #eval_seq_model(retrain=True)
    #eval_seq_model(retrain=False, window_shift=1)
    #eval_seq_model(retrain=False, window_shift=5)
    #eval_gesture_model(retrain=True)
    #eval_gesture_model(window_shift=1)
    #eval_gesture_model(window_shift=5)
    from models import movement_interval, agg_movement_intervals, collect_movement_intervalls
    movement_interval(
        train_on=['training1', 'training2', 'training3', 'training4'],
        predict_on=['validation1_lab', 'validation2_lab', 'validation3_lab'])

    movement_interval(train_on=[
        'training1', 'training3', 'training4', 'validation1_lab',
        'validation3_lab'
    ],
                      predict_on=['training2', 'validation2_lab'])

    movement_interval(train_on=[
        'training2', 'training3', 'training4', 'validation2_lab',
        'validation3_lab'
    ],
                      predict_on=['training1', 'validation1_lab'])

    movement_interval(
        #window_length=40, retrain=False)
    #eval_gesture_model(window_shift=5,
        #window_length=30, retrain=False)
    #eval_gesture_model(window_shift=5,
        #window_length=20, retrain=False)

    #leaderboard_model(retrain=True)
    #leaderboard_model(window_shift=1)
    #leaderboard_model(window_shift=5)
    #eval_seq_model(retrain=True)
    #eval_seq_model(retrain=False, window_shift=1)
    #eval_seq_model(retrain=False, window_shift=5)
    #eval_gesture_model(retrain=True)
    #eval_gesture_model(window_shift=1)
    #eval_gesture_model(window_shift=5)
    from models import movement_interval, agg_movement_intervals, collect_movement_intervalls
    movement_interval(train_on=['training1','training2','training3', 'training4'],
        predict_on=['validation1_lab', 'validation2_lab', 'validation3_lab'])

    movement_interval(train_on=['training1','training3', 'training4', 'validation1_lab',
            'validation3_lab'],
        predict_on=['training2', 'validation2_lab'])

    movement_interval(train_on=['training2','training3', 'training4', 'validation2_lab',
            'validation3_lab'],
        predict_on=['training1', 'validation1_lab'])

    movement_interval(train_on=['training1','training2','training3', 'training4',
            'validation1_lab', 'validation2_lab', 'validation3_lab'],
        predict_on=['test1', 'test2', 'test3', 'test4', 'test5', 'test6'])