예제 #1
0
    elif model == 'lstmbm':
        Model = LSTM_multilayers
        weight_file = 'LSTM_multi5.model'

    elif model == 'grnb1':
        Model = GRN_bitmap
        weight_file = 'GRN_bitmap5.model'

    elif model == 'grnbm':
        Model = GRN_multilayer
        weight_file = 'GRN_multi5.model'

    model_network = Model.get_model()
    model_network.load_weights(weight_file)

    iterator = prepare_data(validate_x_file, validate_y_file)

    results = []
    for validate_x, validate_y in iterator:
        predict_y = model_network.predict_classes(validate_x)
        shape_y = predict_y.shape
        predict_y = predict_y.reshape((shape_y[0] * shape_y[1], shape_y[2]))
        predict_y = (predict_y == [0])[:, 0]
        validate_y = validate_y.reshape((shape_y[0] * shape_y[1], shape_y[2]))
        validate_y = (validate_y == [0])[:, 0]
        a = precision_recall_fscore_support(validate_y, predict_y, average='binary')
        print(a)
        results.append(a[:3])

    results = np.array(results)
    print('final result:')
예제 #2
0
    model.add_input(name='input', input_shape=(200, 10*5))
    model.add_node(LSTM(128, return_sequences=True, input_shape=(200, 10*5)),
                   name='forward', input='input')
    model.add_node(LSTM(128, return_sequences=True, input_shape=(200, 10*5), go_backwards=True),
                   name='backward', input='input')
    model.add_node(Dropout(0.2), name='dropout', inputs=['forward', 'backward'])
    model.add_node(TimeDistributedDense(2, activation='sigmoid'), name='sigmoid', input='dropout')
    model.add_output(name='output', input='sigmoid')
    print('compile')
    model.compile('adam', {'output': 'binary_crossentropy'})
    return model


if __name__ == '__main__':

    train_x_file = '../' + sys.argv[1]
    train_y_file = '../' + sys.argv[2]
    modelfile = sys.argv[3]
    # test_x_file = '../' + sys.argv[3]
    # test_y_file = '../' + sys.argv[4]

    print('loaded')
    model = get_model()
    print("Train...")
    for epoch in range(2):
        iterator = prepare_data(train_x_file, train_y_file)
        print('epoch:', epoch)
        for x, y in iterator:
            model.fit({'input': x, 'output': y}, nb_epoch=1)
    model.save_weights(modelfile)