class_docstr: Wraps a SavedModel (or a legacy TF1 Hub format) as a Keras Layer.
  
  This layer wraps a callable object for use as a Keras layer. The callable
  object can be passed directly, or be specified by a Python string with a
  handle that gets passed to `hub.load()`.
  
  This is the preferred API to load a TF2-style SavedModel from TF Hub
  into a Keras model. Calling this function requires TF 1.15 or newer.
  It can be called both in eager and graph mode.
  
  The callable object is expected to follow the conventions detailed below.
  (These are met by TF2-compatible modules loaded from TensorFlow Hub.)
  
  The callable is invoked with a single positional argument set to one tensor
  or a nest of tensors containing the inputs to the layer. If the callable
  accepts a `training` argument, a Python boolean is passed for it. It is True
  if this layer is marked trainable *and* called for training, analogous to
  keras.layers.BatchNormalization. (By contrast, keras.layers.Dropout
  ignores the trainable state and applies the training argument verbatim.)
  
  If present, the following attributes of callable are understood to have
  special meanings:
    variables: a list of all tf.Variable objects that the callable depends on.
    trainable_variables: those elements of `variables` that are reported
      as trainable variables of this Keras Layer when the layer is trainable.
    regularization_losses: a list of callables to be added as losses of this
      Keras Layer when the layer is trainable. Each one must accept zero
      arguments and return a scalar tensor.
  
  Note: to work-around missing shape inference functionalities from functions
  created from FunctionDefs, in rare cases one has to pass an 'output_shape'
  and potentially 'input_shape' and 'dtype'. E.g. the following is a typical
  work-around:
  ```
  hub.KerasLayer(
      "/tmp/text_embedding_model",
      output_shape=[20],  # Outputs a tensor with shape [batch_size, 20].
      input_shape=[],     # Expects a tensor of shape [batch_size] as input.
      dtype=tf.string)    # Expects a tf.string input tensor.
  ```
  
  Note: This layer can be used inside the model_fn of a TF2 Estimator. See the
  [migration guide]
  (https://www.tensorflow.org/beta/guide/migration_guide#using_a_custom_model_fn)
  for guidance on how to pick up trainable variables, losses and updates
  explicitly from Keras objects instead of relying on graph collections.
  This layer class does not support graph collections.
  Distributed training of the Estimator requires setting the option
  `session_config.share_cluster_devices_in_session` within the
  `tf.estimator.RunConfig`. (This option was experimental from TF1.14 to TF2.1.)
  
  Note: The data types used by a saved model have been fixed at saving time.
  Using keras.mixed_precision etc. has no effect on the saved model
  that gets loaded by a hub.KerasLayer.
  
  Attributes:
    handle: A callable object (subject to the conventions above), or a Python
      string to load a saved model via hub.load(). A string is required to save
      the Keras config of this Layer.
    trainable: Optional. A boolean controlling whether this layer is trainable.
      Must not be set to True when using a signature (raises ValueError),
      including the use of legacy TF1 Hub format.
    arguments: Optional. A dict with additional keyword arguments passed to the
      callable. These must be JSON-serializable to save the Keras config of this
      layer, and are not tracked as checkpointing dependencies of this layer.
    _sentinel: Used to prevent further positional arguments.
    tags: Optional. If set indicates which graph variant to use. For legacy
      models in TF1 Hub format leaving unset means to use the empty tags set.
    signature: Optional. If set, KerasLayer will use the requested signature.
      For legacy models in TF1 Hub format leaving unset means to use the
      `default` signature. When using a signature, either
      signature_outputs_as_dict or output_key have to set.
    signature_outputs_as_dict: If set to True, the call to this layer returns a
      dict of all the signature outputs. Can only be used if a signature is
      specified (or default signature is used for legacy models in TF1 Hub
      format).
    output_key: Name of the output item to return if the layer returns a dict.
      For legacy models in TF1 Hub format leaving unset means to return the
      `default` output.
    output_shape: A tuple or a nest of tuples with the (possibly partial) output
      shapes of the callable *without* leading batch size. This must have the
      same nesting structure as the output of the callable object and cover all
      output tensors.
    load_options: Optional, `tf.saved_model.LoadOptions` object that specifies
      options for loading when a Python string is provided as `handle`. This
      argument can only be used from TensorFlow 2.3 onwards.
    **kwargs: Forwarded to Keras' base Layer constructor.
class_docstr_tok: ["Wraps","a","SavedModel","(","or","a","legacy","TF1","Hub","format",")","as","a","Keras","Layer",".","This","layer","wraps","a","callable","object","for","use","as","a","Keras","layer",".","The","callable","object","can","be","passed","directly",",","or","be","specified","by","a","Python","string","with","a","handle","that","gets","passed","to","`","hub.load","(",")","`",".","This","is","the","preferred","API","to","load","a","TF2-style","SavedModel","from","TF","Hub","into","a","Keras","model",".","Calling","this","function","requires","TF","1.15","or","newer",".","It","can","be","called","both","in","eager","and","graph","mode",".","The","callable","object","is","expected","to","follow","the","conventions","detailed","below",".","(","These","are","met","by","TF2-compatible","modules","loaded","from","TensorFlow","Hub",".",")","The","callable","is","invoked","with","a","single","positional","argument","set","to","one","tensor","or","a","nest","of","tensors","containing","the","inputs","to","the","layer",".","If","the","callable","accepts","a","`","training","`","argument",",","a","Python","boolean","is","passed","for","it",".","It","is","True","if","this","layer","is","marked","trainable","*","and","*","called","for","training",",","analogous","to","keras.layers.BatchNormalization",".","(","By","contrast",",","keras.layers.Dropout","ignores","the","trainable","state","and","applies","the","training","argument","verbatim",".",")","If","present",",","the","following","attributes","of","callable","are","understood","to","have","special","meanings",":","variables",":","a","list","of","all","tf.Variable","objects","that","the","callable","depends","on",".","trainable_variables",":","those","elements","of","`","variables","`","that","are","reported","as","trainable","variables","of","this","Keras","Layer","when","the","layer","is","trainable",".","regularization_losses",":","a","list","of","callables","to","be","added","as","losses","of","this","Keras","Layer","when","the","layer","is","trainable",".","Each","one","must","accept","zero","arguments","and","return","a","scalar","tensor",".","Note",":","to","work-around","missing","shape","inference","functionalities","from","functions","created","from","FunctionDefs",",","in","rare","cases","one","has","to","pass","an","'output_shape'","and","potentially","'input_shape","'","and","'dtype","'",".","E.g",".","the","following","is","a","typical","work-around",":","``","`","hub.KerasLayer","(","``","\/tmp\/text_embedding_model","''",",","output_shape=","[","20","]",",","#","Outputs","a","tensor","with","shape","[","batch_size",",","20","]",".","input_shape=","[","]",",","#","Expects","a","tensor","of","shape","[","batch_size","]","as","input",".","dtype=tf.string",")","#","Expects","a","tf.string","input","tensor",".","``","`","Note",":","This","layer","can","be","used","inside","the","model_fn","of","a","TF2","Estimator",".","See","the","[","migration","guide","]","(","https",":","\/\/www.tensorflow.org\/beta\/guide\/migration_guide","#","using_a_custom_model_fn",")","for","guidance","on","how","to","pick","up","trainable","variables",",","losses","and","updates","explicitly","from","Keras","objects","instead","of","relying","on","graph","collections",".","This","layer","class","does","not","support","graph","collections",".","Distributed","training","of","the","Estimator","requires","setting","the","option","`","session_config.share_cluster_devices_in_session","`","within","the","`","tf.estimator.RunConfig","`",".","(","This","option","was","experimental","from","TF1.14","to","TF2.1",".",")","Note",":","The","data","types","used","by","a","saved","model","have","been","fixed","at","saving","time",".","Using","keras.mixed_precision","etc",".","has","no","effect","on","the","saved","model","that","gets","loaded","by","a","hub.KerasLayer",".","Attributes",":","handle",":","A","callable","object","(","subject","to","the","conventions","above",")",",","or","a","Python","string","to","load","a","saved","model","via","hub.load","(",")",".","A","string","is","required","to","save","the","Keras","config","of","this","Layer",".","trainable",":","Optional",".","A","boolean","controlling","whether","this","layer","is","trainable",".","Must","not","be","set","to","True","when","using","a","signature","(","raises","ValueError",")",",","including","the","use","of","legacy","TF1","Hub","format",".","arguments",":","Optional",".","A","dict","with","additional","keyword","arguments","passed","to","the","callable",".","These","must","be","JSON-serializable","to","save","the","Keras","config","of","this","layer",",","and","are","not","tracked","as","checkpointing","dependencies","of","this","layer",".","_sentinel",":","Used","to","prevent","further","positional","arguments",".","tags",":","Optional",".","If","set","indicates","which","graph","variant","to","use",".","For","legacy","models","in","TF1","Hub","format","leaving","unset","means","to","use","the","empty","tags","set",".","signature",":","Optional",".","If","set",",","KerasLayer","will","use","the","requested","signature",".","For","legacy","models","in","TF1","Hub","format","leaving","unset","means","to","use","the","`","default","`","signature",".","When","using","a","signature",",","either","signature_outputs_as_dict","or","output_key","have","to","set",".","signature_outputs_as_dict",":","If","set","to","True",",","the","call","to","this","layer","returns","a","dict","of","all","the","signature","outputs",".","Can","only","be","used","if","a","signature","is","specified","(","or","default","signature","is","used","for","legacy","models","in","TF1","Hub","format",")",".","output_key",":","Name","of","the","output","item","to","return","if","the","layer","returns","a","dict",".","For","legacy","models","in","TF1","Hub","format","leaving","unset","means","to","return","the","`","default","`","output",".","output_shape",":","A","tuple","or","a","nest","of","tuples","with","the","(","possibly","partial",")","output","shapes","of","the","callable","*","without","*","leading","batch","size",".","This","must","have","the","same","nesting","structure","as","the","output","of","the","callable","object","and","cover","all","output","tensors",".","load_options",":","Optional",",","`","tf.saved_model.LoadOptions","`","object","that","specifies","options","for","loading","when","a","Python","string","is","provided","as","`","handle","`",".","This","argument","can","only","be","used","from","TensorFlow","2.3","onwards",".","*","*","kwargs",":","Forwarded","to","Keras","'","base","Layer","constructor","."]
code: def call(self, inputs, training=None):
      # These checks happen here and not in __init__, because self.trainable is
      # a mutable public attribute.
      self._check_trainability()
  
      # We basically want to call this...
      args = []
      kwargs = self._arguments.copy()
      if self._signature and isinstance(inputs, dict):
          kwargs.update(inputs)
      else:
          args.append(inputs)
      f = functools.partial(self._callable, *args, **kwargs)
      # ...but we may also have to pass a Python boolean for `training`, which
      # is the logical "and" of this layer's trainability and what the surrounding
      # model is doing (analogous to keras.layers.BatchNormalization in TF2).
      # For the latter, we have to look in two places: the `training` argument,
      # or else Keras' global `learning_phase`, which might actually be a tensor.
      if not self._has_training_argument:
          result = f()
      else:
          if self.trainable:
              if training is None:
                  training = keras.backend.learning_phase()
          else:
              # Behave like BatchNormalization. (Dropout is different, b/181839368.)
              training = False
          result = smart_cond.smart_cond(
              training,
              lambda: f(training=True),
              lambda: f(training=False),
          )
  
      # Unwrap dicts returned by signatures.
      if self._output_key:
          if not isinstance(result, dict):
              raise ValueError(
                  "Specifying `output_key` is forbidden if output "
                  "type %s is not a dict." % type(result)
              )
          if self._output_key not in result:
              raise ValueError(
                  "KerasLayer output does not contain the output key %s "
                  "(available: %s)." % (self._output_key, result.keys())
              )
          result = result[self._output_key]
  
      result = self._apply_output_shape_if_set(inputs, result)
      return result
  
imports: import functools
  import json
  from absl import logging
  import tensorflow
  from tensorflow_hub import module_v2
  from tensorflow.python.framework import smart_cond
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 5 for calling the KerasLayer obj's underlying member method code with example usage: obj.call(inputs, training) and returns: result