Example #1
0
def test_MeanVarianceNormalization(tmpdir):
    shape = (3, 5, 7)
    data = np.reshape(np.arange(np.prod(shape), dtype=np.float32), shape)

    input_operand = C.input_variable(shape=shape)

    model0 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=False,
                                           do_variance_scaling=True)
    verify_one_input(model0, data, tmpdir, 'MVN_0')

    model1 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=False,
                                           do_variance_scaling=False)
    verify_one_input(model1, data, tmpdir, 'MVN_1')

    model2 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=True,
                                           do_variance_scaling=True)
    verify_one_input(model2, data, tmpdir, 'MVN_2')

    # The test below tests the round trip with epsilon. We loose always the epsilon value when exporting to ONNX
    # (because ONNX MeanVarianceNormalization does not have an epsilon attribute). When loading back from ONNX, CNTK
    # always uses the default eposilon value (0.00001). That's why test below has the default epsilon value. It is
    # not expected to pass with any other epsilon value until something changes.
    model3 = C.mean_variance_normalization(input_operand,
                                           epsilon=0.00001,
                                           use_stats_across_channels=False,
                                           do_variance_scaling=True)
    verify_one_input(model3, data, tmpdir, 'MVN_3')
Example #2
0
def test_MeanVarianceNormalization(tmpdir):
    shape = (3, 5, 7)
    data = np.reshape(np.arange(np.prod(shape), dtype=np.float32), shape)

    input_operand = C.input_variable(shape=shape)

    model0 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=False,
                                           do_variance_scaling=True)
    verify_one_input(model0, data, tmpdir, 'Pad_0')

    model1 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=False,
                                           do_variance_scaling=False)
    verify_one_input(model1, data, tmpdir, 'Pad_1')

    model2 = C.mean_variance_normalization(input_operand,
                                           use_stats_across_channels=True,
                                           do_variance_scaling=True)
    verify_one_input(model2, data, tmpdir, 'Pad_2')
Example #3
0
def test_op_mean_variance_normalization(input_operand, use_stats_across_channels, do_variance_scaling, epsilon, output_ref, device_id, precision):
    dt_precision = PRECISION_TO_TYPE[precision]
    input_ref = AA(input_operand, dtype=dt_precision)
    a = C.input_variable(shape=input_ref.shape,
                dtype=sanitize_dtype_cntk(precision),
                needs_gradient=False,
                name='a')
    norm_op = C.mean_variance_normalization(a, epsilon=epsilon, use_stats_across_channels=use_stats_across_channels, do_variance_scaling=do_variance_scaling)
    output_test = norm_op.eval({a:input_ref}, device=cntk_device(device_id))

    assert np.allclose(output_test, output_ref, atol=1e-4)
Example #4
0
def test_MeanVarianceNormalization(tmpdir, dtype):
    with C.default_options(dtype = dtype):
        shape = (3, 5, 7)
        data = np.reshape(np.arange(np.prod(shape), dtype = dtype), shape)

        input_operand = C.input_variable(shape=shape)

        model0 = C.mean_variance_normalization(input_operand, use_stats_across_channels=False, do_variance_scaling=True)
        verify_one_input(model0, data, tmpdir, 'MVN_0')

        model1 = C.mean_variance_normalization(input_operand, use_stats_across_channels=False, do_variance_scaling=False)
        verify_one_input(model1, data, tmpdir, 'MVN_1')

        model2 = C.mean_variance_normalization(input_operand, use_stats_across_channels=True, do_variance_scaling=True)
        verify_one_input(model2, data, tmpdir, 'MVN_2')

        # The test below tests the round trip with epsilon. We loose always the epsilon value when exporting to ONNX
        # (because ONNX MeanVarianceNormalization does not have an epsilon attribute). When loading back from ONNX, CNTK
        # always uses the default eposilon value (0.00001). That's why test below has the default epsilon value. It is 
        # not expected to pass with any other epsilon value until something changes.
        model3 = C.mean_variance_normalization(input_operand, epsilon=0.00001, use_stats_across_channels=False, do_variance_scaling=True) 
        verify_one_input(model3, data, tmpdir, 'MVN_3')