-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TFLite] Add option to overwrite OperatorConverter class in relay.fro…
…ntend.from_tflite (#9256) * [TFLite] Relay Frontend: Add option to overwrite OperatorConverter class This allows to overwrite the mapping from TFLite Operators to TVM Relay Operators from external python scripts. This has the following advantages: - Adding support for unsupported builtin or even custom operators by adding a hand-written convert function - Enables overwriting of existing convert functions for supported operators by alternative implementations (useful for currently unsupported edge cases) Example Usage: ``` class CustomOperatorConverter(relay.frontend.tflite.OperatorConverter): def __init__(self, model, subgraph, exp_tab): super(CustomOperatorConverter, self).__init__(model, subgraph, exp_tab) convert_map_overwrite = {"SUB": self.convert_sub_custom} self.convert_map.update(convert_map_overwrite) def convert_sub_custom(self, op): ... ... relay_mod = relay.frontend.from_tflite( tflite_model, shape_dict=shape_dict, dtype_dict=dtype_dict, op_converter=CustomOperatorConverter ) ``` [TFLite] Make sure that even DETECTION_POSTPROCESS op can be overwritten This is desirable, because the current implementation of this CUSTOM op is incompatible with MicroTVM targets * Tests: added test case for overwriting op_converter in TFLite relay frontend Kept the test as simple as possible by only comparing 2 different implementations of a SUB TFLite operator: 1. Original: c = a - b 2. Dummy: c = a + (-b) Comparison with TFLite reference output is not necessary because tis is already covered by other test cases. Instead comparisons of the two TVM models are used.
- Loading branch information
Showing
2 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters