• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Test configs for max_pool_with_argmax."""
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20import tensorflow as tf
21
22from tensorflow.lite.testing.zip_test_utils import create_tensor_data
23from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
24from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
25from tensorflow.lite.testing.zip_test_utils import register_make_test_function
26
27
28@register_make_test_function()
29def make_max_pool_with_argmax_tests(options):
30  """Make a set of tests to do max_pool_with_argmax."""
31
32  test_parameters = [{
33      'input_size': [[2, 4, 2, 2], [2, 4, 3, 2]],
34      'pool_size': [(2, 2), (2, 1)],
35      'strides': [(2, 2)],
36      'padding': ['SAME', 'VALID'],
37  }, {
38      'input_size': [[2, 4, 10, 2], [2, 4, 11, 2], [2, 4, 12, 2]],
39      'pool_size': [(2, 2)],
40      'strides': [(2, 3)],
41      'padding': ['SAME', 'VALID'],
42  }]
43
44  def build_graph(parameters):
45    """Build the exp op testing graph."""
46    input_tensor = tf.compat.v1.placeholder(
47        dtype=tf.float32, name='input', shape=parameters['input_size'])
48    updates, indices = tf.nn.max_pool_with_argmax(
49        input_tensor,
50        ksize=parameters['pool_size'],
51        strides=parameters['strides'],
52        padding=parameters['padding'],
53        output_dtype=tf.dtypes.int32)
54    return [input_tensor], [updates, indices]
55
56  def build_inputs(parameters, sess, inputs, outputs):
57    values = [
58        create_tensor_data(
59            tf.float32, parameters['input_size'], min_value=-10, max_value=10)
60    ]
61    return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
62
63  extra_toco_options = ExtraTocoOptions()
64  extra_toco_options.allow_custom_ops = True
65  make_zip_of_tests(options, test_parameters, build_graph, build_inputs,
66                    extra_toco_options)
67