Esempio n. 1
0
def test_multi_scale_loss_kernel():
    """
    Test multi-scale loss kernel returns the appropriate
    loss tensor for same inputs and jaccard cal.
    """
    loss_values = np.asarray([1, 2, 3])
    array_eye = np.identity((3))
    tensor_pred = np.zeros((3, 3, 3, 3))
    tensor_eye = np.zeros((3, 3, 3, 3))

    tensor_eye[:, :, 0:3, 0:3] = array_eye
    tensor_pred[:, :, 0, 0] = array_eye
    tensor_eye = tf.convert_to_tensor(tensor_eye, dtype=tf.double)
    tensor_pred = tf.convert_to_tensor(tensor_pred, dtype=tf.double)
    list_losses = np.array([
        label.single_scale_loss(
            y_true=label.separable_filter3d(tensor_eye,
                                            label.gauss_kernel1d(s)),
            y_pred=label.separable_filter3d(tensor_pred,
                                            label.gauss_kernel1d(s)),
            loss_type="jaccard",
        ) for s in loss_values
    ])
    expect = np.mean(list_losses, axis=0)
    get = label.multi_scale_loss(tensor_eye, tensor_pred, "jaccard",
                                 loss_values)
    assert assertTensorsEqual(get, expect)
Esempio n. 2
0
def test_separable_filter_else():
    """
    Testing separable filter case where non
    zero length tensor is passed to the
    function.
    """
    k = np.ones((3, 3, 3, 3))
    array_eye = np.identity((3))
    tensor_pred = np.zeros((3, 3, 3, 3))
    tensor_pred[:, :, 0, 0] = array_eye

    expect = np.ones((3, 3, 3, 3))

    get = label.separable_filter3d(tensor_pred, k)
    assert assertTensorsEqual(get, expect)
Esempio n. 3
0
def test_separable_filter_else():
    """
    Testing separable filter case where non
    zero length tensor is passed to the
    function.
    """
    k = np.ones((3, 3, 3, 3), dtype=np.float32)
    array_eye = np.identity(3, dtype=np.float32)
    tensor_pred = np.zeros((3, 3, 3, 3), dtype=np.float32)
    tensor_pred[:, :, 0, 0] = array_eye
    tensor_pred = tf.convert_to_tensor(tensor_pred, dtype=tf.float32)
    k = tf.convert_to_tensor(k, dtype=tf.float32)

    expect = np.ones((3, 3, 3, 3), dtype=np.float32)
    expect = tf.convert_to_tensor(expect, dtype=tf.float32)

    get = label.separable_filter3d(tensor_pred, k)
    assert is_equal_tf(get, expect)