Beispiel #1
0
def resolve_test_case(model, data_path, label_path, idp_complete_classes, rD_min, rD_max, rA_min, rA_max, is_plot=True):
    special_replacement = {'Act': '0', 'Spc': '1', 'Bspc': '2', 'Ent': '3'}
    data = pickle.load(open(data_path, 'rb'))
    label = pickle.load(open(label_path, 'rb'))

    sequence = np.reshape(np.array(label), newshape=(-1, 1))
    sequence = np.array([[x[0]] for x in sequence if x[0] in idp_complete_classes])
    valid_indices = np.argmax(encoder.transform(sequence).toarray(), axis=1)
    index_class_dict = dict([(index, clss[0]) for index, clss in zip(valid_indices, sequence)])

    rD_seq = np.array(data['mmw']['range_doppler'])
    rA_seq = np.array(data['mmw']['range_azi'])

    rD_seq = (rD_seq - rD_min) / (rD_max - rD_min)
    rA_seq = (rA_seq - rA_min) / (rA_max - rA_min)

    rA_samples = prepare_x(rA_seq, window_size=120, stride=1)
    rD_samples = prepare_x(rD_seq, window_size=120, stride=1)

    print('predicting on samples')
    y_pred = model.predict([rD_samples, rA_samples], batch_size=32)

    if is_plot:
        matplotlib.rcParams.update({'font.size': 14})
        plt.figure(figsize=(20, 6))
        is_plotted_others = False
        for i, col in enumerate(np.transpose(y_pred)):
            if i in index_class_dict.keys():
                plt.plot(col, label='Predicted gesture: ' + index_class_dict[i], linewidth=3)
            else:
                plt.plot(col, c='gray', label='Gestures for other chars') if not is_plotted_others else plt.plot(col,
                                                                                                                 c='gray')
                is_plotted_others = True

    debouncer_result = debouncer_detection(y_pred, is_plot=is_plot)
    pred_string = replace_special(''.join(debouncer_result), special_replacement)
    grdt_string = replace_special(''.join([s[0] for s in sequence]), special_replacement)
    dist = levenshtein_ratio_and_distance(pred_string, grdt_string, ratio_calc=True)
    print('detected: ' + pred_string)
    print('groundtr: ' + grdt_string)
    print('Distance = ' + str(dist))

    return dist
Beispiel #2
0
    Ent_index + 1
])  # H, E, L, L, O, spc, W, O, R, L, D
ys = np.array([Y[ki] for ki in key_indices])
print('Working with sequence: ' + str(encoder.inverse_transform(ys)))

rA_seq = np.array([X_mmw_rA[i] for i in key_indices])
rA_seq = np.reshape(
    rA_seq, newshape=[-1] + list(rA_seq.shape[2:])
)  # flatten the sample dimension to create temporal sequence
rD_seq = np.array([X_mmw_rD[i] for i in key_indices])
rD_seq = np.reshape(
    rD_seq, newshape=[-1] + list(rD_seq.shape[2:])
)  # flatten the sample dimension to create temporal sequence

# sample from the temporal sequence
rA_samples = prepare_x(rA_seq, window_size=121, stride=1)
rD_samples = prepare_x(rD_seq, window_size=121, stride=1)

y_pred = idp_model.predict([rD_samples, rA_samples], batch_size=32)
y_pred = y_pred[60:len(y_pred) - 60]

# plottings
matplotlib.rcParams.update({'font.size': 14})
plt.figure(figsize=(20, 6))
is_plotted_others = False

for i, col in enumerate(np.transpose(y_pred)):
    if i in valid_indices:
        plt.plot(moving_average(col, n=16),
                 label='Predicted gesture: ' + index_class_dict[i],
                 linewidth=3)