code: def extract_network(instance):
      if isinstance(instance, BaseNetwork):
          return instance.network
  
      if isinstance(instance, LayerGraph):
          return instance
  
      raise TypeError(
          "Invalid input type. Input should be network or optimizer "
          "with network, got `{}` instance instead".format(
              type(instance)
          )
      )
  
imports: import json
  from time import gmtime, strftime
  import six
  import h5py
  import numpy
  import tensorflow
  from six.moves import cPickle
  import neupy
  from neupy.core.docs import shared_docs
  from neupy.layers.graph import LayerGraph
  from neupy.algorithms.base import BaseNetwork
  from neupy.utils import asfloat, tf_utils
label_desc: Use image node_id 1 for calling a global function with example usage: extract_network(instance) and returns: instance, instance