2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 from mo.front.common.custom_replacement_registry import CustomReplacementRegistry
17 from mo.front.common.replacement import FrontReplacementPattern
18 from mo.front.tf.replacement import FrontReplacementFromConfigFileOp
19 from mo.graph.graph import Graph
20 from mo.utils.class_registration import update_registration, get_enabled_and_disabled_transforms
23 class TensorflowUseCustomOperationsConfig(FrontReplacementPattern):
25 graph_condition = [lambda graph: graph.graph['cmd_params'].tensorflow_use_custom_operations_config is not None]
28 from extensions.front.pass_separator import FrontStart
34 def find_and_replace_pattern(self, graph: Graph):
35 argv = graph.graph['cmd_params']
36 registry = CustomReplacementRegistry()
37 registry.add_custom_replacement_description_from_config(argv.tensorflow_use_custom_operations_config)
39 # automatically generate sub-classes for custom replacements that replace sub-graph with a single node
40 for replacement_desc in registry.get_all_replacements_descriptions():
41 if replacement_desc.has('op'):
42 type('FrontReplacementFromConfigFileOp' + replacement_desc.op, (FrontReplacementFromConfigFileOp,),
43 {'replacement_id': replacement_desc.id})
44 update_registration([FrontReplacementFromConfigFileOp], *get_enabled_and_disabled_transforms())