Beispiel #1
0
def make_rfft2d_tests(options):
    """Make a set of tests to do rfft2d."""

    test_parameters = [{
        "input_dtype": [tf.float32],
        "input_shape": [[8, 8], [3, 8, 8]],
        "fft_length":
        [None, [4, 4], [4, 8], [8, 4], [8, 8], [8, 16], [16, 8], [16, 16]]
    }]

    def build_graph(parameters):
        input_value = tf.compat.v1.placeholder(dtype=parameters["input_dtype"],
                                               name="input",
                                               shape=parameters["input_shape"])
        outs = tf.signal.rfft2d(input_value,
                                fft_length=parameters["fft_length"])
        return [input_value], [outs]

    def build_inputs(parameters, sess, inputs, outputs):
        input_value = create_tensor_data(parameters["input_dtype"],
                                         parameters["input_shape"])
        return [input_value
                ], sess.run(outputs,
                            feed_dict=dict(zip(inputs, [input_value])))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
                      extra_toco_options)
Beispiel #2
0
def make_roll_tests(options):
    """Make a set of tests to do roll."""

    ext_test_parameters = test_parameters + [
        # Scalar axis.
        {
            "input_dtype": [tf.float32, tf.int32],
            "input_shape": [[None, 8, 4]],
            "shift": [-3, 5],
            "axis": [1, 2],
        }
    ]

    def set_dynamic_shape(shape):
        return [4 if x is None else x for x in shape]

    def get_shape(param):
        if np.isscalar(param):
            return []
        return [len(param)]

    def get_value(param, dtype):
        if np.isscalar(param):
            return np.dtype(dtype).type(param)
        return np.array(param).astype(dtype)

    def build_graph(parameters):
        input_tensor = tf.compat.v1.placeholder(
            dtype=parameters["input_dtype"],
            name="input",
            shape=parameters["input_shape"])
        shift_tensor = tf.compat.v1.placeholder(dtype=tf.int64,
                                                name="shift",
                                                shape=get_shape(
                                                    parameters["shift"]))
        axis_tensor = tf.compat.v1.placeholder(dtype=tf.int64,
                                               name="axis",
                                               shape=get_shape(
                                                   parameters["axis"]))
        outs = tf.roll(input_tensor, shift_tensor, axis_tensor)
        return [input_tensor, shift_tensor, axis_tensor], [outs]

    def build_inputs(parameters, sess, inputs, outputs):
        input_value = create_tensor_data(
            parameters["input_dtype"],
            set_dynamic_shape(parameters["input_shape"]))
        shift_value = get_value(parameters["shift"], np.int64)
        axis_value = get_value(parameters["axis"], np.int64)
        return [input_value, shift_value, axis_value], sess.run(
            outputs,
            feed_dict=dict(zip(inputs,
                               [input_value, shift_value, axis_value])))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options, ext_test_parameters, build_graph, build_inputs,
                      extra_toco_options)
Beispiel #3
0
def make_parse_example_tests(options):
    """Make a set of tests to use parse_example."""

    # Chose a set of parameters
    test_parameters = [{
        "feature_dtype": [tf.string, tf.float32, tf.int64],
        "is_dense": [True, False],
        "feature_shape": [[1], [2], [16]],
    }]

    def build_graph(parameters):
        """Build the graph for parse_example tests."""
        feature_dtype = parameters["feature_dtype"]
        feature_shape = parameters["feature_shape"]
        is_dense = parameters["is_dense"]
        input_value = tf.compat.v1.placeholder(dtype=tf.string,
                                               name="input",
                                               shape=[1])
        if is_dense:
            feature_default_value = np.zeros(shape=feature_shape)
            if feature_dtype == tf.string:
                feature_default_value = np.array(["missing"] *
                                                 feature_shape[0])
            features = {
                "x":
                tf.FixedLenFeature(shape=feature_shape,
                                   dtype=feature_dtype,
                                   default_value=feature_default_value)
            }
        else:  # Sparse
            features = {"x": tf.VarLenFeature(dtype=feature_dtype)}
        out = tf.parse_example(input_value, features)
        output_tensor = out["x"]
        if not is_dense:
            output_tensor = out["x"].values
        return [input_value], [output_tensor]

    def build_inputs(parameters, sess, inputs, outputs):
        feature_dtype = parameters["feature_dtype"]
        feature_shape = parameters["feature_shape"]
        input_values = [create_example_data(feature_dtype, feature_shape)]
        return input_values, sess.run(outputs,
                                      feed_dict=dict(zip(inputs,
                                                         input_values)))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
                      extra_toco_options)
Beispiel #4
0
    def f(options, expected_tf_failures=0):
        """Actual function that generates examples.

    Args:
      options: An Options instance.
      expected_tf_failures: number of expected tensorflow failures.
    """

        # Chose a set of parameters
        test_parameters = [
            {
                "ksize": [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 4, 1]],
                "strides": [[1, 1, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 2, 4, 1]],
                "input_shape": [[1, 1, 1, 1, 1], [1, 16, 15, 14, 1],
                                [3, 16, 15, 14, 3]],
                "padding": ["SAME", "VALID"],
                "data_format": ["NDHWC"],
            },
        ]

        def build_graph(parameters):
            input_tensor = tf.compat.v1.placeholder(
                dtype=tf.float32,
                name="input",
                shape=parameters["input_shape"])
            out = pool_op(input_tensor,
                          ksize=parameters["ksize"],
                          strides=parameters["strides"],
                          data_format=parameters["data_format"],
                          padding=parameters["padding"])
            return [input_tensor], [out]

        def build_inputs(parameters, sess, inputs, outputs):
            input_values = create_tensor_data(tf.float32,
                                              parameters["input_shape"])
            return [input_values
                    ], sess.run(outputs,
                                feed_dict=dict(zip(inputs, [input_values])))

        extra_toco_options = ExtraTocoOptions()
        extra_toco_options.allow_custom_ops = True
        make_zip_of_tests(options,
                          test_parameters,
                          build_graph,
                          build_inputs,
                          extra_toco_options,
                          expected_tf_failures=expected_tf_failures)
def make_broadcast_gradient_args_tests(options):
    """Make a set of tests to do broadcast_gradient_args."""

    test_parameters = [{
        'input_case': ['ALL_EQUAL', 'ONE_DIM', 'NON_BROADCASTABLE'],
        'dtype': [tf.dtypes.int32, tf.dtypes.int64],
    }]

    def build_graph(parameters):
        """Build the op testing graph."""
        input1 = tf.compat.v1.placeholder(dtype=parameters['dtype'],
                                          name='input1')
        input2 = tf.compat.v1.placeholder(dtype=parameters['dtype'],
                                          name='input2')
        output1, output2 = tf.raw_ops.BroadcastGradientArgs(s0=input1,
                                                            s1=input2)
        return [input1, input2], [output1, output2]

    def build_inputs(parameters, sess, inputs, outputs):
        dtype = parameters['dtype'].as_numpy_dtype()

        if parameters['input_case'] == 'ALL_EQUAL':
            values = [
                np.array([2, 4, 1, 3], dtype=dtype),
                np.array([2, 4, 1, 3], dtype=dtype)
            ]
        elif parameters['input_case'] == 'ONE_DIM':
            values = [
                np.array([2, 4, 1, 3], dtype=dtype),
                np.array([2, 1, 1, 3], dtype=dtype)
            ]
        elif parameters['input_case'] == 'NON_BROADCASTABLE':
            values = [
                np.array([2, 4, 1, 3], dtype=dtype),
                np.array([2, 5, 1, 3], dtype=dtype)
            ]
        return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options,
                      test_parameters,
                      build_graph,
                      build_inputs,
                      extra_toco_options,
                      expected_tf_failures=2)
def make_max_pool_with_argmax_tests(options):
    """Make a set of tests to do max_pool_with_argmax."""

    test_parameters = [{
        'input_size': [[2, 4, 2, 2], [2, 4, 3, 2]],
        'pool_size': [(2, 2), (2, 1)],
        'strides': [(2, 2)],
        'padding': ['SAME', 'VALID'],
    }, {
        'input_size': [[2, 4, 10, 2], [2, 4, 11, 2], [2, 4, 12, 2]],
        'pool_size': [(2, 2)],
        'strides': [(2, 3)],
        'padding': ['SAME', 'VALID'],
    }]

    def build_graph(parameters):
        """Build the exp op testing graph."""
        input_tensor = tf.compat.v1.placeholder(dtype=tf.float32,
                                                name='input',
                                                shape=parameters['input_size'])
        updates, indices = tf.nn.max_pool_with_argmax(
            input_tensor,
            ksize=parameters['pool_size'],
            strides=parameters['strides'],
            padding=parameters['padding'],
            output_dtype=tf.dtypes.int32)
        return [input_tensor], [updates, indices]

    def build_inputs(parameters, sess, inputs, outputs):
        values = [
            create_tensor_data(tf.float32,
                               parameters['input_size'],
                               min_value=-10,
                               max_value=10)
        ]
        return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
                      extra_toco_options)
Beispiel #7
0
def make_irfft2d_tests(options):
    """Make a set of tests to do irfft2d."""

    test_parameters = [{
        "input_dtype": [tf.complex64],
        "input_shape": [[4, 3]],
        "fft_length": [[4, 4], [2, 2], [2, 4]]
    }, {
        "input_dtype": [tf.complex64],
        "input_shape": [[3, 8, 5]],
        "fft_length": [[2, 4], [2, 8], [8, 8]]
    }, {
        "input_dtype": [tf.complex64],
        "input_shape": [[3, 1, 9]],
        "fft_length": [[1, 8], [1, 16]]
    }]

    def build_graph(parameters):
        input_value = tf.compat.v1.placeholder(dtype=parameters["input_dtype"],
                                               name="input",
                                               shape=parameters["input_shape"])
        outs = tf.signal.irfft2d(input_value,
                                 fft_length=parameters["fft_length"])
        return [input_value], [outs]

    def build_inputs(parameters, sess, inputs, outputs):
        rfft_length = []
        rfft_length.append(parameters["input_shape"][-2])
        rfft_length.append((parameters["input_shape"][-1] - 1) * 2)
        rfft_input = create_tensor_data(np.float32, parameters["input_shape"])
        rfft_result = np.fft.rfft2(rfft_input, rfft_length)

        return [rfft_result
                ], sess.run(outputs,
                            feed_dict=dict(zip(inputs, [rfft_result])))

    extra_toco_options = ExtraTocoOptions()
    extra_toco_options.allow_custom_ops = True
    make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
                      extra_toco_options)
Beispiel #8
0
def make_dense_image_warp_tests(options):
  """Make a set of tests to do dense_image_warp."""

  test_parameters = [{
      'input_size': [[2, 4, 4, 1], [2, 4, 3, 3], [3, 7, 9, 2]],
      'flow_size': [[2, 4, 4, 2], [2, 4, 3, 2], [3, 7, 9, 2]],
  }]

  def build_graph(parameters):
    """Build the exp op testing graph."""
    input_tensor = tf.compat.v1.placeholder(
        dtype=tf.float32, name='input', shape=parameters['input_size'])
    flow_tensor = tf.compat.v1.placeholder(
        dtype=tf.float32, name='flow', shape=parameters['flow_size'])
    output = dense_image_warp_annotated(input_tensor, flow_tensor)
    return [input_tensor, flow_tensor], [output]

  def build_inputs(parameters, sess, inputs, outputs):
    values = [
        create_tensor_data(
            tf.float32, parameters['input_size'], min_value=-10, max_value=10),
        create_tensor_data(
            tf.float32, parameters['flow_size'], min_value=-10, max_value=10)
    ]
    return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))

  extra_toco_options = ExtraTocoOptions()
  extra_toco_options.allow_custom_ops = True
  options.expected_ops_in_converted_model = ['DenseImageWarp']
  make_zip_of_tests(
      options,
      test_parameters,
      build_graph,
      build_inputs,
      extra_toco_options,
      expected_tf_failures=6)