Exemple #1
0
 def test_pad(test_case):
     arg_dict = OrderedDict()
     arg_dict["device_type"] = ["cpu", "gpu"]
     arg_dict["flow_op"] = [flow.pad]
     arg_dict["tf_op"] = [tf.pad]
     arg_dict["input_shape"] = [(2, 2, 1, 3), (1, 1, 2, 3)]
     arg_dict["op_args"] = [
         Args(
             [([1, 2], [0, 0], [1, 2], [1, 1])],
             tf.constant([([1, 2], [0, 0], [1, 2], [1, 1])]),
         ),
         Args(
             [([0, 0], [30, 0], [0, 1], [1, 0]),
              99999999999999999999999999999999],
             [
                 tf.constant(([0, 0], [30, 0], [0, 1], [1, 0])),
                 "constant",
                 99999999999999999999999999999999,
             ],
         ),
         Args(
             [([10, 0], [0, 0], [10, 20], [0, 0])],
             tf.constant([([10, 0], [0, 0], [10, 20], [0, 0])]),
         ),
     ]
     for arg in GenArgDict(arg_dict):
         CompareOpWithTensorFlow(**arg)
Exemple #2
0
 def test_reshape(test_case):
     arg_dict = OrderedDict()
     arg_dict["device_type"] = ["gpu"]
     arg_dict["flow_op"] = [flow.reshape]
     arg_dict["tf_op"] = [tf.reshape]
     arg_dict["input_shape"] = [(10, 10, 10)]
     arg_dict["op_args"] = [
         Args([(100, 10)]),
         Args([(10, 100)]),
         Args([(5, 20, 10)]),
     ]
     for arg in GenArgDict(arg_dict):
         CompareOpWithTensorFlow(**arg)
Exemple #3
0
 def test_scalar_add(test_case):
     arg_dict = OrderedDict()
     arg_dict["device_type"] = ["gpu", "cpu"]
     arg_dict["flow_op"] = [flow.math.add]
     arg_dict["tf_op"] = [tf.math.add]
     arg_dict["input_shape"] = [(10, 10, 10)]
     arg_dict["op_args"] = [
         Args([1]),
         Args([-1]),
         Args([84223.19348]),
         Args([-3284.139]),
     ]
     for arg in GenArgDict(arg_dict):
         CompareOpWithTensorFlow(**arg)
def test_bias_add_nchw(test_case):
    arg_dict = OrderedDict()
    arg_dict["device_type"] = ["cpu", "gpu"]
    arg_dict["input_shapes"] = [((1, 20, 1, 11), (20, ))]
    arg_dict["op_args"] = [Args(["NCHW"])]
    for arg in GenArgDict(arg_dict):
        CompareBiasAddWithTensorFlow(**arg)
def test_bias_add_nhwc(test_case):
    arg_dict = OrderedDict()
    arg_dict["device_type"] = ["cpu", "gpu"]
    arg_dict["input_shapes"] = [((30, 20, 5, 10), (10, )),
                                ((2, 5, 7, 8), (8, ))]
    arg_dict["op_args"] = [Args(["NHWC"])]
    for arg in GenArgDict(arg_dict):
        CompareBiasAddWithTensorFlow(**arg)
def test_batchnorm_fp16(test_case):
    arg_dict = OrderedDict()
    arg_dict["device_type"] = ["gpu"]
    arg_dict["input_shape"] = [(2, 4, 3, 5)]
    arg_dict["input_minval"] = [-2]
    arg_dict["input_maxval"] = [2]
    arg_dict["op_args"] = [
        Args([1]),
        Args([2]),
        Args([1, 0.95, 0.0001]),
        Args([1, 0.99, 0.001, False]),
        Args([1, 0.99, 0.001, False, False]),
        Args([]),
        Args([1, 0.95, 0.1]),
    ]
    for arg in GenArgDict(arg_dict):
        CompareFp16WithFp32(**arg,
                            training=False,
                            trainable=False,
                            y_rtol=1e-3,
                            y_atol=1e-3)
        CompareFp16WithFp32(**arg,
                            training=True,
                            trainable=True,
                            y_rtol=1e-3,
                            y_atol=1e-3,
                            x_diff_rtol=1e-3,
                            x_diff_atol=1e-3)
        CompareFp16WithFp32(**arg,
                            training=False,
                            trainable=True,
                            y_rtol=1e-3,
                            y_atol=1e-3,
                            x_diff_rtol=1e-3,
                            x_diff_atol=1e-3)
Exemple #7
0
 def test_bias_add_nhwc(test_case):
     arg_dict = OrderedDict()
     arg_dict["data_type"] = ["float16", "float32"]
     arg_dict["device_type"] = ["gpu", "cpu"]
     arg_dict["input_shapes"] = [((30, 20, 5, 10), (10, )),
                                 ((2, 5, 7, 7), (7, ))]
     arg_dict["op_args"] = [Args(["NHWC"])]
     for arg in GenArgDict(arg_dict):
         if arg["data_type"] == "float16" and arg["device_type"] == "cpu":
             continue
         CompareBiasAddWithTensorFlow(**arg)
Exemple #8
0
 def test_bias_add_nchw(test_case):
     arg_dict = OrderedDict()
     arg_dict["data_type"] = ["float16", "float32"]
     arg_dict["device_type"] = ["gpu", "cpu"]
     arg_dict["input_shapes"] = [((1, 20, 1, 11), (20, )),
                                 ((2, 20, 1, 11), (20, ))]
     arg_dict["op_args"] = [Args(["NCHW"])]
     for arg in GenArgDict(arg_dict):
         if arg["data_type"] == "float16" and arg["device_type"] == "cpu":
             continue
         CompareBiasAddWithTensorFlow(**arg)
Exemple #9
0
 def test_pad_5d(test_case):
     arg_dict = OrderedDict()
     arg_dict["device_type"] = ["cpu", "gpu"]
     arg_dict["flow_op"] = [flow.pad]
     arg_dict["tf_op"] = [tf.pad]
     arg_dict["input_shape"] = [(2, 2, 1, 3, 1), (1, 1, 2, 3, 1)]
     arg_dict["op_args"] = [
         Args(
             [([1, 2], [3, 4], [5, 6], [7, 8], [9, 10])],
             tf.constant([([1, 2], [3, 4], [5, 6], [7, 8], [9, 10])]),
         ),
         Args(
             [([1, 1], [2, 2], [3, 3], [4, 4], [5, 5])],
             tf.constant([([1, 1], [2, 2], [3, 3], [4, 4], [5, 5])]),
         ),
         Args(
             [([0, 0], [0, 0], [10, 20], [0, 0], [3, 2])],
             tf.constant([([0, 0], [0, 0], [10, 20], [0, 0], [3, 2])]),
         ),
     ]
     for arg in GenArgDict(arg_dict):
         CompareOpWithTensorFlow(**arg)
Exemple #10
0
 def test_layer_batchnorm(test_case):
     arg_dict = OrderedDict()
     arg_dict["device_type"] = ["cpu", "gpu"]
     arg_dict["data_type"] = ["float32"]
     arg_dict["input_shape"] = [(1, 4, 1, 2)]
     arg_dict["op_args"] = [
         Args([1]),
         Args([2]),
         Args([1, 0.95, 0.0001]),
         Args([1, 0.99, 0.001, False]),
         Args([1, 0.99, 0.001, False, False]),
         Args([]),
         Args([1, 0.95, 0.1]),
     ]
     for arg in GenArgDict(arg_dict):
         CompareBnWithTensorFlow(test_case, **arg)
Exemple #11
0
def test_layer_batchnorm_trainable_without_training(test_case):
    arg_dict = OrderedDict()
    arg_dict["device_type"] = ["cpu", "gpu"]
    arg_dict["data_type"] = ["float32"]
    arg_dict["input_shape"] = [(2, 4, 3, 5)]
    arg_dict["op_args"] = [
        Args([1]),
        Args([2]),
        Args([1, 0.95, 0.0001]),
        Args([1, 0.99, 0.001, False]),
        Args([1, 0.99, 0.001, False, False]),
        Args([]),
        Args([1, 0.95, 0.1]),
    ]
    for arg in GenArgDict(arg_dict):
        CompareBnWithTensorFlow(**arg, training=False, trainable=True)