• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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 pool operators."""
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20import tensorflow.compat.v1 as tf
21from tensorflow.lite.testing.zip_test_utils import create_tensor_data
22from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
23from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
24from tensorflow.lite.testing.zip_test_utils import register_make_test_function
25
26
27def make_pool3d_tests(pool_op):
28  """Make a set of tests to do pooling.
29
30  Args:
31    pool_op: TensorFlow pooling operation to test  i.e. `tf.nn.max_pool3d`.
32
33  Returns:
34    A function representing the true generator (after curried pool_op).
35  """
36
37  def f(options, expected_tf_failures=0):
38    """Actual function that generates examples.
39
40    Args:
41      options: An Options instance.
42      expected_tf_failures: number of expected tensorflow failures.
43    """
44
45    # Chose a set of parameters
46    test_parameters = [
47        {
48            "ksize": [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 4, 1]],
49            "strides": [[1, 1, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 2, 4, 1]],
50            "input_shape": [[1, 1, 1, 1, 1], [1, 16, 15, 14, 1],
51                            [3, 16, 15, 14, 3]],
52            "padding": ["SAME", "VALID"],
53            "data_format": ["NDHWC"],
54        },
55    ]
56
57    def build_graph(parameters):
58      input_tensor = tf.compat.v1.placeholder(
59          dtype=tf.float32, name="input", shape=parameters["input_shape"])
60      out = pool_op(
61          input_tensor,
62          ksize=parameters["ksize"],
63          strides=parameters["strides"],
64          data_format=parameters["data_format"],
65          padding=parameters["padding"])
66      return [input_tensor], [out]
67
68    def build_inputs(parameters, sess, inputs, outputs):
69      input_values = create_tensor_data(tf.float32, parameters["input_shape"])
70      return [input_values], sess.run(
71          outputs, feed_dict=dict(zip(inputs, [input_values])))
72
73    extra_toco_options = ExtraTocoOptions()
74    extra_toco_options.allow_custom_ops = True
75    make_zip_of_tests(
76        options,
77        test_parameters,
78        build_graph,
79        build_inputs,
80        extra_toco_options,
81        expected_tf_failures=expected_tf_failures)
82
83  return f
84
85
86@register_make_test_function()
87def make_avg_pool3d_tests(options):
88  make_pool3d_tests(tf.nn.avg_pool3d)(options, expected_tf_failures=6)
89
90
91@register_make_test_function()
92def make_max_pool3d_tests(options):
93  make_pool3d_tests(tf.nn.max_pool3d)(options, expected_tf_failures=6)
94