code: def _remove_transpose_ops(self, starting_transpose_op):
      perm = list(starting_transpose_op.inputs["perm"].val)
      starting_transpose_op_out_var = starting_transpose_op.outputs[0]
      starting_transpose_op_input_var = starting_transpose_op.inputs[
          "x"
      ]
  
      # update all the "axis_update" ops
      for op in self.transpose_op_to_axis_update_ops.get(
          starting_transpose_op, []
      ):
          if op not in self.ops_updated:
              op_cls = AXIS_UPDATE_OPS.get(op.op_type, None)
              op_cls(**{"op": op, "transpose_axes": perm}).update()
              self.ops_updated.add(op)
  
      # short circuit starting_transpose_op and its cancel ops
  
      to_be_removed_ops = []
      name_changed_vars = set()
  
      for op in [
          starting_transpose_op
      ] + self.transpose_op_to_cancel_ops[starting_transpose_op]:
          if op in self.transpose_ops_removed:
              continue
  
          to_be_removed_ops.append(op)
          self.transpose_ops_removed.add(op)
  
          input_var = op.inputs["x"]  # input to the transpose op
          output_var = op.outputs[0]  # output of the transpose op
          parent_op = input_var.op  # parent op of the transpose op
  
          if output_var in self.old_output_vars:
              # output is a block output, so this must be one of the "edge" transpose compliment ops
              # We need to set `input_var` as the block output var
              # Change the name of the input_var to match the block output if input_var is not changed.
              # If the same input_var is in output twice, we can't rename it twice, therefore we initiate an
              # Identity op to match the name
              if input_var not in name_changed_vars:
                  input_var.name = output_var.name
                  input_var.op.name = output_var.op.name
                  name_changed_vars.update([input_var])
              else:
                  with self.block:
                      input_var = mb.identity(
                          x=input_var,
                          before_op=op,
                          name=output_var.name,
                      )
                      parent_op = input_var.op
  
          # connect all the child ops of the output_var to the parent of the transpose op.
          self.block.replace_uses_of_var_after_op(
              anchor_op=parent_op,
              old_var=output_var,
              new_var=input_var,
              no_check_var_types=True,
          )
  
      """
          Insert a transpose op JUST before each one of the materialize ops
          i.e.
          Given:  %i1 = op(...)
                  ...
                  ... = materialize_op(..., %i1 ,...)
                  ...
  
          Result: %i1 = op(...)
                  ...
                  %i2 = transpose_op(%i1, %perm)
                  ... = materialize_op(..., %i2 ,...)
                  ...
          """
      for op, input_var in self.transpose_op_to_materialize_ops.get(
          starting_transpose_op, []
      ):
          if (op, input_var) in self.materialized_ops_handled:
              continue
  
          self.materialized_ops_handled.add((op, input_var))
          with self.block:
              if input_var == starting_transpose_op_out_var:
                  # materialize op is connected to the starting transpose op
                  # in this case, connect to its parent
                  if op in self.output_sink_ops:
                      continue
                  i1 = starting_transpose_op_input_var
              else:
                  i1 = input_var
  
              if op in self.output_sink_ops:
                  # The input_var of output sink is itself a output. We can safely
                  # modify the name of the input_var since it should only be consumed
                  # by block output here.
                  if i1 not in name_changed_vars:
                      x = mb.transpose(
                          x=i1, perm=perm, before_op=op, name=i1.name
                      )
                      i1.name = "_before_transpose_op_" + x.op.name
                      i1.op.name = "_before_transpose_op_" + x.op.name
                  else:
                      x = mb.transpose(
                          x=i1,
                          perm=perm,
                          before_op=op,
                          name=self.old_output_vars[i1],
                      )
              else:
                  x = mb.transpose(x=i1, perm=perm, before_op=op)
  
          self.block.replace_uses_of_var_after_op(
              anchor_op=x.op,
              end_op=op,
              old_var=i1,
              new_var=x,
              no_check_var_types=True,
          )
  
      self.block.remove_ops(to_be_removed_ops)
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil.var import Var
  import logging
  import numpy
  import copy
  from collections import defaultdict
label_desc: Use image node_id 10 for calling the TransposeOptimization obj's underlying member method code with example usage: obj._remove_transpose_ops(starting_transpose_op) without return types