本文整理汇总了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)