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

Class VariableHolder

tensorpack/models/utils.py:7–37  ·  view source on GitHub ↗

A proxy to access variables defined in a layer.

Source from the content-addressed store, hash-verified

5
6
7class VariableHolder(object):
8 """ A proxy to access variables defined in a layer. """
9 def __init__(self, **kwargs):
10 """
11 Args:
12 kwargs: {name:variable}
13 """
14 self._vars = {}
15 for k, v in six.iteritems(kwargs):
16 self._add_variable(k, v)
17
18 def _add_variable(self, name, var):
19 assert name not in self._vars
20 self._vars[name] = var
21
22 def __setattr__(self, name, var):
23 if not name.startswith('_'):
24 self._add_variable(name, var)
25 else:
26 # private attributes
27 super(VariableHolder, self).__setattr__(name, var)
28
29 def __getattr__(self, name):
30 return self._vars[name]
31
32 def all(self):
33 """
34 Returns:
35 list of all variables
36 """
37 return list(six.itervalues(self._vars))
38
39
40try:

Callers 9

PReLUFunction · 0.85
BatchNormFunction · 0.85
BatchNormFunction · 0.85
BatchRenormFunction · 0.85
LayerNormFunction · 0.85
InstanceNormFunction · 0.85
Conv2DFunction · 0.85
Conv2DTransposeFunction · 0.85
FullyConnectedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected