本文整理匯總了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)))
示例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))
示例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)