Beispiel #1
0
def test_confusion_matrix_forward(seed, ctx, axis, func_name):
    ishape = [5, 6, 7]
    rng = np.random.RandomState(seed)

    l_shape = list(ishape)
    l_shape[axis] = 1
    n_class = ishape[axis]

    inputs = [
        rng.rand(5, 6, 7).astype(np.float32),
        rng.randint(0, n_class, size=l_shape).astype(np.int)
    ]

    ref = ref_confusion_matrix(inputs[0], inputs[1], axis)

    x = nn.Variable(ishape)
    l = nn.Variable(l_shape)
    y = F.confusion_matrix(x, l, axis)
    x.d = inputs[0]
    l.d = inputs[1]
    y.forward()
    res = y.d

    atol_f = 1e-6
    assert_allclose(ref, res, atol=atol_f)
Beispiel #2
0
def test_confusion_matrix_forward(seed, ctx, axis, func_name):
    ishape = [5, 6, 7]
    rng = np.random.RandomState(seed)

    l_shape = list(ishape)
    l_shape[axis] = 1
    n_class = ishape[axis]

    inputs = [
        rng.rand(5, 6, 7).astype(np.float32),
        rng.randint(0, n_class, size=l_shape).astype(np.int)]

    ref = ref_confusion_matrix(inputs[0], inputs[1], axis)

    x = nn.Variable(ishape)
    l = nn.Variable(l_shape)
    y = F.confusion_matrix(x, l, axis)
    x.d = inputs[0]
    l.d = inputs[1]
    y.forward()
    res = y.d

    atol_f = 1e-6
    assert np.allclose(ref, res, atol=atol_f)