| 203 | """ |
| 204 | |
| 205 | def __init__( |
| 206 | self, |
| 207 | decay=0.9, |
| 208 | epsilon=0.00001, |
| 209 | act=None, |
| 210 | is_train=False, |
| 211 | beta_init=tl.initializers.zeros(), |
| 212 | gamma_init=tl.initializers.random_normal(mean=1.0, stddev=0.002), |
| 213 | moving_mean_init=tl.initializers.zeros(), |
| 214 | moving_var_init=tl.initializers.zeros(), |
| 215 | num_features=None, |
| 216 | data_format='channels_last', |
| 217 | name=None, |
| 218 | ): |
| 219 | super(BatchNorm, self).__init__(name=name, act=act) |
| 220 | self.decay = decay |
| 221 | self.epsilon = epsilon |
| 222 | self.data_format = data_format |
| 223 | self.beta_init = beta_init |
| 224 | self.gamma_init = gamma_init |
| 225 | self.moving_mean_init = moving_mean_init |
| 226 | self.moving_var_init = moving_var_init |
| 227 | self.num_features = num_features |
| 228 | |
| 229 | self.axes = None |
| 230 | |
| 231 | if num_features is not None: |
| 232 | self.build(None) |
| 233 | self._built = True |
| 234 | |
| 235 | if self.decay < 0.0 or 1.0 < self.decay: |
| 236 | raise ValueError("decay should be between 0 to 1") |
| 237 | |
| 238 | logging.info( |
| 239 | "BatchNorm %s: decay: %f epsilon: %f act: %s is_train: %s" % |
| 240 | (self.name, decay, epsilon, self.act.__name__ if self.act is not None else 'No Activation', is_train) |
| 241 | ) |
| 242 | |
| 243 | def __repr__(self): |
| 244 | actstr = self.act.__name__ if self.act is not None else 'No Activation' |