ICNN.variable(col, name, init_fn=None, *init_args)#

Declares and returns a variable in this Module.

See flax.core.variables for more information. See also param() for a shorthand way to define read-only variables in the “params” collection.

Contrary to param(), all arguments passing using init_fn should be passed on explicitly:

key = self.make_rng('stats')
mean = self.variable('stats', 'mean', lecun_normal(), key, (2, 2))

In the example above, the function lecun_normal expects two arguments: key and shape, and both have to be passed on. The PRNG for stats has to be provided explicitly when calling init() and apply().

  • col (str) – The variable collection name.

  • name (str) – The variable name.

  • init_fn (Optional[Callable[..., Any]]) – The function that will be called to compute the initial value of this variable. This function will only be called the first time this variable is used in this module. If None, the variable must already be initialized otherwise an error is raised.

  • *init_args – The arguments to pass to init_fn.

Return type



A flax.core.variables.Variable that can be read or set via “.value” attribute. Throws an error if the variable exists already.