示例#1
0
            'Do you want to use the model trained on cosine distances [c] or on raw SVM predictions [r]?',
            'c', 'r'):
        cosine = True
        model = load_model(config.lstm_model_1)
    else:
        cosine = False
        model = load_model(config.lstm_model_577)

    time_steps = model.get_config()[0]['config']['batch_input_shape'][1]

    held_out = config.get_seg_data('held_out')

    X_held = np.load(held_out['y'])
    y_held = np.load(held_out['y_true_lm'])

    if cosine:
        print("Computing the distances")
        X_held = compute_distance(X_held, cosine_distances)
    else:
        y_held = np.append(0, y_held)

    X = split_to_time_steps(X_held)
    y_true = split_to_time_steps(y_held)

    y_pred = model.predict(X)

    plot_thresholds(y_true.flatten(),
                    y_pred.flatten(),
                    False,
                    average_type="binary")
    print("Loading the data")
    train = config.get_seg_data('train')
    held_out = config.get_seg_data('held_out')

    X_train_or = np.load(train['y'])
    y_train_or = np.load(train['y_true_lm'])

    X_held_out = np.load(held_out['y'])
    y_held_out = np.load(held_out['y_true_lm'])

    print("Computing the distances on test data")
    X_held_out = compute_distance(X_held_out, cosine_distances)

    # Split the 2D matrix to 3D matrix of dimensions [samples, time_steps, features]
    X_held_out = split_to_time_steps(X_held_out)

    # Split the 1D vector to 2D matrix of dimensions: [samples, time_steps]
    y_held_out = split_to_time_steps(y_held_out)

    y_held_out = np.reshape(y_held_out,
                            (y_held_out.shape[0], y_held_out.shape[1], 1))

    # Append 0 value to the beginning of y so the values represent if there was a boundary between current sample and
    # the previous one, not the current and next
    y_train_or = np.append(0, y_train_or)
    shuffling_epochs = 2
    for i in range(shuffling_epochs):
        print("Shuffling epoch " + str(i) + "/" + str(shuffling_epochs))

        [X_train, y_train] = shuffle_the_data(X_train_or, y_train_or)
示例#3
0
    if first_option('Do you want to use the model trained on cosine distances [c] or on raw SVM predictions [r]?',
                    'c', 'r'):
        cosine = True
        model = load_model(config.lstm_model_1)
        T = 0.41
    else:
        cosine = False
        model = load_model(config.lstm_model_577)
        T = 0.48

    time_steps = model.get_config()[0]['config']['batch_input_shape'][1]

    test = config.get_seg_data('test')

    X_test = np.load(test['y'])
    y_test = np.load(test['y_true_lm'])

    if cosine:
        print("Computing the distances")
        X_test = compute_distance(X_test, cosine_distances)
    else:
        y_test = np.append(0, y_test)

    X = split_to_time_steps(X_test)
    y_true = split_to_time_steps(y_test)

    y_pred = model.predict(X) > T

    print_measurements(y_true, y_pred)
示例#4
0
    # LSTM part
    if first_option(
            'Do you want to use the model trained on cosine distances [c] or on raw SVM predictions [r]?',
            'c', 'r'):
        print("Computing the distances")
        X = compute_distance(X, cosine_distances)
        model = load_model(config.lstm_model_1)
        T = 0.41
        # y_true = y_true[1:]
        assert len(X) == len(
            y_true), "Dimensions do not match: y.shape = " + str(
                y_true.shape) + " X.shape = " + str(X.shape)
    else:
        cosine = False
        model = load_model(config.lstm_model_577)
        T = 0.48

    time_steps = model.get_config()[0]['config']['batch_input_shape'][1]

    X = split_to_time_steps(X)
    y_true = split_to_time_steps(y_true)

    y_pred = model.predict(X) > T

    P, R, F, S = prfs(y_true.flatten(), y_pred.flatten(), average='binary')
    print('F1 = %.3f (P = %.3f, R = %.3f)' % (F, P, R))

    # plot_thresholds_pk(y_true, y_pred)

    print_measurements(y_true, y_pred, k=5)  # TODO: optimize k