MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / get_value

Function get_value

python/paddle/framework/io_utils.py:348–372  ·  view source on GitHub ↗

Get the value of variable or value in given scope. Args: scope(Scope, optional) : If `scope` is None, it will be set to global scope obtained through 'paddle.static.global_scope()'. Otherwise, use `scope`. Default: None Returns: Tensor, the valu

(var, scope=None)

Source from the content-addressed store, hash-verified

346
347
348def get_value(var, scope=None):
349 """
350 Get the value of variable or value in given scope.
351
352 Args:
353 scope(Scope, optional) : If `scope` is None, it will be set to global scope
354 obtained through 'paddle.static.global_scope()'. Otherwise, use `scope`.
355 Default: None
356
357 Returns:
358 Tensor, the value in given scope.
359
360 """
361 if scope is not None and not isinstance(scope, core._Scope):
362 raise TypeError(
363 f"`scope` should be None or `paddle.static.Scope` type, but received {type(scope)}."
364 )
365
366 if scope is None:
367 scope = global_scope()
368 var_temp = scope.find_var(var.name)
369 if var_temp is None:
370 raise ValueError(f"Can not find Variable '{var.name}' in the Scope.")
371 t = var_temp.get_tensor()
372 return t
373
374
375def is_pir_fetch_var(value):

Calls 5

global_scopeFunction · 0.90
TypeErrorClass · 0.85
ValueErrorClass · 0.85
typeFunction · 0.50
get_tensorMethod · 0.45