Recursively returns the weights from this layer and its children. Arguments: prefix: Prefix to prepend to all variable names. ordered: If set, an ordered list is returned instead. Returns: Dictionary mapping variables name to value.
(
self,
prefix: str = "",
ordered: bool = False,
)
| 141 | ) |
| 142 | |
| 143 | def variables( |
| 144 | self, |
| 145 | prefix: str = "", |
| 146 | ordered: bool = False, |
| 147 | ) -> Dict[str, np.ndarray]: |
| 148 | """Recursively returns the weights from this layer and its children. |
| 149 | |
| 150 | Arguments: |
| 151 | prefix: Prefix to prepend to all variable names. |
| 152 | ordered: If set, an ordered list is returned instead. |
| 153 | |
| 154 | Returns: |
| 155 | Dictionary mapping variables name to value. |
| 156 | """ |
| 157 | var = {} |
| 158 | |
| 159 | def _register_var(spec, name, value): |
| 160 | if isinstance(value, str) and value == OPTIONAL: |
| 161 | return |
| 162 | var[_join_scope(prefix, name)] = value |
| 163 | |
| 164 | self._visit(_register_var) |
| 165 | if ordered: |
| 166 | return list(sorted(var.items(), key=lambda x: x[0])) |
| 167 | return var |
| 168 | |
| 169 | def _alias_variables(self): |
| 170 | """Find duplicate variables in spec and create aliases.""" |