MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / remap_variables

Function remap_variables

tensorpack/tfutils/varreplace.py:37–58  ·  view source on GitHub ↗

Use fn to map the output of any variable getter. Args: fn (tf.Variable -> tf.Tensor) Returns: The current variable scope with a custom_getter that maps all the variables by fn. Example: .. code-block:: python from tensorpack.tfutils im

(fn)

Source from the content-addressed store, hash-verified

35
36
37def remap_variables(fn):
38 """
39 Use fn to map the output of any variable getter.
40
41 Args:
42 fn (tf.Variable -> tf.Tensor)
43
44 Returns:
45 The current variable scope with a custom_getter that maps
46 all the variables by fn.
47
48 Example:
49 .. code-block:: python
50
51 from tensorpack.tfutils import varreplace
52 with varreplace.remap_variables(lambda var: quantize(var)):
53 x = FullyConnected('fc', x, 1000) # fc/{W,b} will be quantized
54 """
55 def custom_getter(getter, *args, **kwargs):
56 v = getter(*args, **kwargs)
57 return fn(v)
58 return custom_getter_scope(custom_getter)
59
60
61def freeze_variables(stop_gradient=True, skip_collection=False):

Callers 3

build_graphMethod · 0.90
build_graphMethod · 0.90
get_logitsMethod · 0.90

Calls 1

custom_getter_scopeFunction · 0.85

Tested by

no test coverage detected