提交 72081907 编写于 作者: X xuwei06

More informative comment and error message for fetch_var()

上级 6695a204
...@@ -152,8 +152,10 @@ def fetch_var(name, scope=None, return_numpy=True): ...@@ -152,8 +152,10 @@ def fetch_var(name, scope=None, return_numpy=True):
""" """
Fetch the value of the variable with the given name from the given scope Fetch the value of the variable with the given name from the given scope
Args: Args:
name(str): name of the variable name(str): name of the variable. Typically, only persistable variables
scope(core.Scope|None): scope object. can be found in the scope used for running the program.
scope(core.Scope|None): scope object. It should be the scope where
you pass to Executor.run() when running your program.
If None, global_scope() will be used. If None, global_scope() will be used.
return_numpy(bool): whether convert the tensor to numpy.ndarray return_numpy(bool): whether convert the tensor to numpy.ndarray
Returns: Returns:
...@@ -165,7 +167,10 @@ def fetch_var(name, scope=None, return_numpy=True): ...@@ -165,7 +167,10 @@ def fetch_var(name, scope=None, return_numpy=True):
assert isinstance(scope, core.Scope) assert isinstance(scope, core.Scope)
var = global_scope().find_var(name) var = global_scope().find_var(name)
assert var is not None, "Cannot find '%s' in scope." % name assert var is not None, (
"Cannot find " + name + " in scope. Perhaps you need to make the"
" variable persistable by using var.persistable = True in your"
" program.")
tensor = var.get_tensor() tensor = var.get_tensor()
if return_numpy: if return_numpy:
tensor = as_numpy(tensor) tensor = as_numpy(tensor)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册