docstr: Overwrites TFLoader._graph_def_from_model()
docstr_tok: ["Overwrites","TFLoader._graph_def_from_model","(",")"]
code: def _graph_def_from_model(self, output_names=None):
      """Overwrites TFLoader._graph_def_from_model()"""
      msg = "Expected model format: [tf.Graph | .pb | SavedModel | tf.keras.Model | .h5], got {}"
      if isinstance(self.model, tf.Graph) and hasattr(
          self.model, "as_graph_def"
      ):
          graph_def = self.model.as_graph_def(add_shapes=True)
          return self.extract_sub_graph(graph_def, output_names)
      elif isinstance(self.model, tf.keras.Model):
          graph_def = self._from_tf_keras_model(self.model)
          return self.extract_sub_graph(graph_def, output_names)
      elif isinstance(self.model, str):
          if not os.path.exists(str(self.model)):
              raise ValueError(
                  'Input model "{}" does not exist'.format(self.model)
              )
          elif os.path.isfile(str(self.model)) and self.model.endswith(
              ".pb"
          ):
              if _get_version(tf.__version__) < _StrictVersion(
                  "1.13.1"
              ):
                  with open(self.model, "rb") as f:
                      gd = tf.GraphDef()
                      gd.ParseFromString(f.read())
                  with tf.Graph().as_default() as graph:
                      tf.import_graph_def(gd, name="")
              else:
                  with tf.io.gfile.GFile(self.model, "rb") as f:
                      gd = tf.compat.v1.GraphDef()
                      gd.ParseFromString(f.read())
                  with tf.Graph().as_default() as graph:
                      tf.graph_util.import_graph_def(gd, name="")
              graph_def = graph.as_graph_def(add_shapes=True)
              return self.extract_sub_graph(graph_def, output_names)
          elif os.path.isfile(str(self.model)) and self.model.endswith(
              ".h5"
          ):
              graph_def = self._from_tf_keras_model(self.model)
              return self.extract_sub_graph(graph_def, output_names)
          elif os.path.isdir(str(self.model)):
              graph_def = self._from_saved_model(self.model)
              return self.extract_sub_graph(graph_def, output_names)
          else:
              raise NotImplementedError(msg.format(self.model))
      else:
          raise NotImplementedError(msg.format(self.model))
  
imports: import gc
  import os
  from distutils.version import StrictVersion
  from tempfile import mktemp
  import tensorflow
  from tqdm import tqdm
  from coremltools import _logger
  from coremltools._deps import _get_version
  from coremltools.converters._profile_utils import _profile
  from .._utils import get_output_names
  from .basic_graph_ops import fill_outputs
  from .converter import TFConverter
  from .parsed_tf_node import ParsedTFNode
  from .tf_graph_pass import cond_to_where, constant_propagation, delete_asserts, delete_disconnected_nodes, delete_unnecessary_constant_nodes, functionalize_loops, fuse_dilation_conv, insert_get_tuple, quantization_pass, remove_variable_nodes, tensor_array_resource_removal
  from .tfssa import NetworkEnsemble, SSAFunction
label_desc: Use image node_id 2 for calling the TF1Loader obj's underlying member method code with example usage: obj._graph_def_from_model(output_names) and returns: self, self, self, self, self