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 conv3d_transpose.""" 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20import numpy as np 21import tensorflow.compat.v1 as tf 22 23from tensorflow.lite.testing.zip_test_utils import create_tensor_data 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_conv3d_transpose_tests(options): 30 """Make a set of tests to do conv3d_transpose.""" 31 32 test_parameters = [{ 33 "shape_dtype": [tf.int32, tf.int64], 34 "input_dtype": [tf.float32], 35 "input_shape": [[2, 3, 4, 5, 2], [2, 5, 6, 8, 2]], 36 "filter_shape": [[2, 2, 2, 3, 2], [1, 2, 2, 3, 2]], 37 "strides": [(1, 1, 1, 1, 1), (1, 1, 1, 2, 1), (1, 1, 2, 2, 1), 38 (1, 2, 1, 2, 1), (1, 2, 2, 2, 1)], 39 "dilations": [(1, 1, 1, 1, 1)], 40 "padding": ["SAME", "VALID"], 41 }] 42 43 def build_graph(parameters): 44 """Build the exp op testing graph.""" 45 output_shape = tf.compat.v1.placeholder( 46 dtype=parameters["shape_dtype"], name="input", shape=[5]) 47 input_tensor = tf.compat.v1.placeholder( 48 dtype=parameters["input_dtype"], 49 name="input", 50 shape=parameters["input_shape"]) 51 filter_tensor = tf.compat.v1.placeholder( 52 dtype=parameters["input_dtype"], 53 name="filter", 54 shape=parameters["filter_shape"]) 55 56 out = tf.nn.conv3d_transpose( 57 input_tensor, 58 filter_tensor, 59 output_shape, 60 strides=parameters["strides"], 61 dilations=parameters["dilations"], 62 padding=parameters["padding"]) 63 return [input_tensor, filter_tensor, output_shape], [out] 64 65 def calculate_output_shape(parameters): 66 67 def calculate_shape(idx): 68 input_size = parameters["input_shape"][idx] 69 filter_size = parameters["filter_shape"][idx - 1] 70 stride = parameters["strides"][idx] 71 if parameters["padding"] == "SAME": 72 return (input_size - 1) * stride + 1 73 else: 74 return (input_size - 1) * stride + filter_size 75 76 output_shape_values = [parameters["input_shape"][0]] 77 output_shape_values.append(calculate_shape(1)) 78 output_shape_values.append(calculate_shape(2)) 79 output_shape_values.append(calculate_shape(3)) 80 output_shape_values.append(parameters["filter_shape"][3]) 81 return np.dtype( 82 parameters["shape_dtype"].as_numpy_dtype()).type(output_shape_values) 83 84 def build_inputs(parameters, sess, inputs, outputs): 85 values = [ 86 create_tensor_data( 87 parameters["input_dtype"], 88 parameters["input_shape"], 89 min_value=-100, 90 max_value=9), 91 create_tensor_data( 92 parameters["input_dtype"], 93 parameters["filter_shape"], 94 min_value=-3, 95 max_value=3), 96 calculate_output_shape(parameters) 97 ] 98 return values, sess.run(outputs, feed_dict=dict(zip(inputs, values))) 99 100 make_zip_of_tests(options, test_parameters, build_graph, build_inputs) 101