# Copyright (c) 2019 Sony Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ..onnx import OnnxExporter
from onnx_tf.backend import prepare


class TensorflowExporter:
    def __init__(self, nnp, batch_size):
        self._nnp = nnp
        self._batch_size = batch_size

    def execute(self, output):
        onnx_model = OnnxExporter(
            self._nnp, self._batch_size).export_model_proto()
        tf_rep = prepare(onnx_model)
        tf_rep.export_graph(output)

@@ -798,16 +798,1824 @@
 tch_size
+%0A        self.check_nnp_variable_name()%0A%0A    def check_nnp_variable_name(self):%0A        def fix_variable_name(variable_name):%0A            if %22%5B%22 in variable_name and %22%5D%22 in variable_name:%0A                variable_name = variable_name.replace(%22%5B%22, %22_%22)%0A                variable_name = variable_name.replace(%22%5D%22, %22%22)%0A            if %22%5C'%22 in variable_name:%0A                variable_name = variable_name.replace(%22%5C'%22, %22%22)%0A            return variable_name%0A%0A        network = self._nnp.protobuf.network%0A        executor = self._nnp.protobuf.executor%0A        network_name = executor%5B0%5D.network_name%0A        parameter_variable = %5B%5D%0A        for net in network:%0A            if net.name == network_name:%0A                for var in net.variable:%0A                    if var.type == 'Parameter':%0A                        parameter_variable.append(var.name)%0A                        continue%0A                    var.name = fix_variable_name(var.name)%0A                for func in net.function:%0A                    if func.name not in parameter_variable:%0A                        func.name = fix_variable_name(func.name)%0A                    for i, name in enumerate(func.input):%0A                        if name not in parameter_variable:%0A                            del func.input%5Bi%5D%0A                            func.input.insert(i, fix_variable_name(name))%0A                    for i, name in enumerate(func.output):%0A                        if name not in parameter_variable:%0A                            del func.output%5Bi%5D%0A                            func.output.insert(i, fix_variable_name(name))%0A        for var in executor%5B0%5D.data_variable:%0A            var.variable_name = fix_variable_name(var.variable_name)%0A        for var in executor%5B0%5D.output_variable:%0A            var.variable_name = fix_variable_name(var.variable_name)
 %0A%0A    de

Fix invalid variable name for tf export