當前位置: 首頁>>代碼示例>>Python>>正文


Python tf_inspect.getfullargspec方法代碼示例

本文整理匯總了Python中tensorflow.python.util.tf_inspect.getfullargspec方法的典型用法代碼示例。如果您正苦於以下問題:Python tf_inspect.getfullargspec方法的具體用法?Python tf_inspect.getfullargspec怎麽用?Python tf_inspect.getfullargspec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.util.tf_inspect的用法示例。


在下文中一共展示了tf_inspect.getfullargspec方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate

# 需要導入模塊: from tensorflow.python.util import tf_inspect [as 別名]
# 或者: from tensorflow.python.util.tf_inspect import getfullargspec [as 別名]
def validate(host_calls):
    """Validates the `eval_metrics` and `host_call` in `TPUEstimatorSpec`."""

    for name, host_call in host_calls.items():
      if not isinstance(host_call, (tuple, list)):
        raise ValueError('{} should be tuple or list'.format(name))
      if len(host_call) != 2:
        raise ValueError('{} should have two elements.'.format(name))
      if not callable(host_call[0]):
        raise TypeError('{}[0] should be callable.'.format(name))
      if not isinstance(host_call[1], (tuple, list, dict)):
        raise ValueError('{}[1] should be tuple or list, or dict.'.format(name))

      if isinstance(host_call[1], (tuple, list)):
        fullargspec = tf_inspect.getfullargspec(host_call[0])
        fn_args = function_utils.fn_args(host_call[0])
        # wrapped_hostcall_with_global_step uses varargs, so we allow that.
        if fullargspec.varargs is None and len(host_call[1]) != len(fn_args):
          raise RuntimeError(
              'In TPUEstimatorSpec.{}, length of tensors {} does not match '
              'method args of the function, which takes {}.'.format(
                  name, len(host_call[1]), len(fn_args))) 
開發者ID:ymcui,項目名稱:Chinese-XLNet,代碼行數:24,代碼來源:tpu_estimator.py

示例2: hook_loaded_model

# 需要導入模塊: from tensorflow.python.util import tf_inspect [as 別名]
# 或者: from tensorflow.python.util.tf_inspect import getfullargspec [as 別名]
def hook_loaded_model(cls, loaded_model):
        try:
            from tensorflow.python.util import tf_inspect
            from tensorflow.python.eager import def_function
        except ImportError:
            raise MissingDependencyException(
                "Tensorflow package is required to use TfSavedModelArtifact"
            )

        for k in dir(loaded_model):
            v = getattr(loaded_model, k, None)
            if isinstance(v, def_function.Function):
                fullargspec = tf_inspect.getfullargspec(v)
                setattr(loaded_model, k, cls(v, fullargspec)) 
開發者ID:bentoml,項目名稱:BentoML,代碼行數:16,代碼來源:tf_savedmodel_artifact.py

示例3: func_has_training_argument

# 需要導入模塊: from tensorflow.python.util import tf_inspect [as 別名]
# 或者: from tensorflow.python.util.tf_inspect import getfullargspec [as 別名]
def func_has_training_argument(func):
  """Checks whether saved model has a `training` argument."""
  if not callable(func):
    return False
  fullargspec = tf_inspect.getfullargspec(func.__call__)
  return ("training" in fullargspec.args or
          "training" in fullargspec.kwonlyargs) 
開發者ID:tensorflow,項目名稱:hub,代碼行數:9,代碼來源:keras_layer.py


注:本文中的tensorflow.python.util.tf_inspect.getfullargspec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。