Make a set of tests to do hardswish.
(options)
| 727 | |
| 728 | @register_make_test_function() |
| 729 | def make_hardswish_tests(options): |
| 730 | """Make a set of tests to do hardswish.""" |
| 731 | |
| 732 | # Chose a set of parameters |
| 733 | test_parameters = [{ |
| 734 | "input_shape": [[], [1], [2, 3], [1, 1, 1, 1], [1, 3, 4, 3], |
| 735 | [3, 15, 14, 3], [3, 1, 2, 4, 6], [2, 2, 3, 4, 5, 6]], |
| 736 | }] |
| 737 | |
| 738 | def build_graph(parameters): |
| 739 | inp = tf.placeholder( |
| 740 | dtype=tf.float32, name="input", shape=parameters["input_shape"]) |
| 741 | |
| 742 | out = inp * tf.nn.relu6(inp + np.float32(3)) * np.float32(1. / 6.) |
| 743 | |
| 744 | return [inp], [out] |
| 745 | |
| 746 | def build_inputs(parameters, sess, inputs, outputs): |
| 747 | input_values = create_tensor_data( |
| 748 | np.float32, parameters["input_shape"], min_value=-10, max_value=10) |
| 749 | return [input_values], sess.run( |
| 750 | outputs, feed_dict=dict(zip(inputs, [input_values]))) |
| 751 | |
| 752 | # Add additional validation if we are using toco. |
| 753 | # Flex and mlir doesn't yet support this. TODO(b/139193008): Fix |
| 754 | if not options.run_with_flex: |
| 755 | options.tflite_convert_function = functools.partial( |
| 756 | _tflite_convert_verify_num_ops, |
| 757 | options.tflite_convert_function, |
| 758 | num_ops=2) |
| 759 | make_zip_of_tests(options, test_parameters, build_graph, build_inputs) |
| 760 | |
| 761 | |
| 762 | def _tflite_convert_verify_num_ops(tflite_convert_function, *args, **kwargs): |
nothing calls this directly
no test coverage detected