Make a set of tests to do PReLU.
(options)
| 943 | |
| 944 | @register_make_test_function() |
| 945 | def make_prelu_tests(options): |
| 946 | """Make a set of tests to do PReLU.""" |
| 947 | |
| 948 | test_parameters = [ |
| 949 | { |
| 950 | # The canonical case for image processing is having a 4D `input` |
| 951 | # (NHWC)and `shared_axes`=[1, 2], so the alpha parameter is per |
| 952 | # channel. |
| 953 | "input_shape": [[1, 10, 10, 3], [3, 3, 3, 3]], |
| 954 | "shared_axes": [[1, 2], [1]], |
| 955 | }, |
| 956 | { |
| 957 | # 2D-3D example. Share the 2nd axis. |
| 958 | "input_shape": [[20, 20], [20, 20, 20]], |
| 959 | "shared_axes": [[1]], |
| 960 | } |
| 961 | ] |
| 962 | |
| 963 | def build_graph(parameters): |
| 964 | """Build the graph for the test case.""" |
| 965 | |
| 966 | input_tensor = tf.placeholder( |
| 967 | dtype=tf.float32, name="input", shape=parameters["input_shape"]) |
| 968 | prelu = tf.keras.layers.PReLU(shared_axes=parameters["shared_axes"]) |
| 969 | out = prelu(input_tensor) |
| 970 | return [input_tensor], [out] |
| 971 | |
| 972 | def build_inputs(parameters, sess, inputs, outputs): |
| 973 | """Build the inputs for the test case.""" |
| 974 | |
| 975 | input_shape = parameters["input_shape"] |
| 976 | input_values = create_tensor_data( |
| 977 | np.float32, input_shape, min_value=-10, max_value=10) |
| 978 | shared_axes = parameters["shared_axes"] |
| 979 | |
| 980 | alpha_shape = [] |
| 981 | for dim in range(1, len(input_shape)): |
| 982 | alpha_shape.append(1 if dim in shared_axes else input_shape[dim]) |
| 983 | |
| 984 | alpha_values = create_tensor_data(np.float32, alpha_shape) |
| 985 | |
| 986 | # There should be only 1 trainable variable tensor. |
| 987 | variables = tf.all_variables() |
| 988 | assert len(variables) == 1 |
| 989 | sess.run(variables[0].assign(alpha_values)) |
| 990 | |
| 991 | return [input_values], sess.run( |
| 992 | outputs, feed_dict=dict(zip(inputs, [input_values]))) |
| 993 | |
| 994 | make_zip_of_tests( |
| 995 | options, |
| 996 | test_parameters, |
| 997 | build_graph, |
| 998 | build_inputs, |
| 999 | use_frozen_graph=True) |
| 1000 | |
| 1001 | |
| 1002 | @register_make_test_function() |
nothing calls this directly
no test coverage detected