Beispiel #1
0
def invoke_benchmark(batch_size, epochs, num_gpu, mode):
    feature_dimension = 10000
    train_data = mx.test_utils.rand_ndarray((100000, feature_dimension), 'csr',
                                            0.01)
    target_weight = mx.nd.arange(1, feature_dimension + 1).reshape(
        (feature_dimension, 1))
    train_label = mx.nd.dot(train_data, target_weight)
    eval_data = train_data
    eval_label = mx.nd.dot(eval_data, target_weight)

    train_data = prepare_sliced_sparse_data(train_data, batch_size)
    train_label = prepare_sliced_sparse_data(train_label, batch_size)
    eval_data = prepare_sliced_sparse_data(eval_data, batch_size)
    eval_label = prepare_sliced_sparse_data(eval_label, batch_size)

    print("Running Keras benchmark script on sparse data")
    keras_sparse_model.run_benchmark(
        train_data=sparse.csr_matrix(train_data.asnumpy()),
        train_label=train_label.asnumpy(),
        eval_data=sparse.csr_matrix(eval_data.asnumpy()),
        eval_label=eval_label.asnumpy(),
        batch_size=batch_size,
        epochs=epochs,
        num_gpu=num_gpu,
        mode=mode)
def test_prepare_sparse_sliced_data_no_input():
    test_train_data = None
    batch_size = 3

    with pytest.warns(UserWarning):  # Warning is thrown when data is None
        result = prepare_sliced_sparse_data(test_train_data, batch_size)
        assert result is None
Beispiel #3
0
def test_prepare_sparse_sliced_data():
    test_train_data = _generate_test_data()
    batch_size = 2

    result = prepare_sliced_sparse_data(test_train_data, batch_size)

    assert isinstance(result, sparse.csr.csr_matrix)
    assert int(result.shape[0]) % batch_size == 0
def test_prepare_sparse_sliced_data():
    row_ind = np.array([0, 1, 1, 3, 4])
    col_ind = np.array([0, 2, 4, 3, 4])
    data = np.array([1, 2, 3, 4, 5], dtype=float)
    test_train_data = sparse.coo_matrix((data, (row_ind, col_ind)))
    batch_size = 3

    result = prepare_sliced_sparse_data(test_train_data, batch_size)

    assert int(result.shape[0]) % batch_size == 0
Beispiel #5
0
def test_prepare_sparse_sliced_data_incorrect_dimensions():
    row_ind = np.array([0, 1])
    col_ind = np.array([0, 2])
    data = np.array([1, 2], dtype=float)
    test_train_data = sparse.coo_matrix((data, (row_ind, col_ind)))

    batch_size = 5
    with pytest.warns(UserWarning):  # Warning is thrown when data size is smaller than batch size
        result = prepare_sliced_sparse_data(test_train_data, batch_size)

        assert result.shape[0] == test_train_data.shape[0]
        assert result.shape[1] == test_train_data.shape[1]
Beispiel #6
0
def test_prepare_sparse_sliced_data_incorrect_dimensions():
    test_train_data = _generate_test_data()

    batch_size = 5
    with pytest.warns(
            UserWarning
    ):  # Warning is thrown when data size is smaller than batch size
        result = prepare_sliced_sparse_data(test_train_data, batch_size)

        assert isinstance(result, sparse.csr.csr_matrix)
        assert result.shape[0] == test_train_data.shape[0]
        assert result.shape[1] == test_train_data.shape[1]