| 27 | RegisterLayerClass(singacuda_batchnorm, BatchNorm); |
| 28 | RegisterLayerClass(singacl_batchnorm, BatchNorm); |
| 29 | void BatchNorm::Setup(const Shape& in_sample, const LayerConf& conf) { |
| 30 | Layer::Setup(in_sample, conf); |
| 31 | out_sample_shape_ = in_sample; |
| 32 | factor_ = (float)conf.batchnorm_conf().factor(); |
| 33 | channels_ = in_sample.at(0); |
| 34 | if (in_sample.size() == 3u) |
| 35 | height_ = in_sample.at(1); |
| 36 | else |
| 37 | height_ = 1; |
| 38 | if (in_sample.size() == 3u) |
| 39 | width_ = in_sample.at(2); |
| 40 | else |
| 41 | width_ = 1; |
| 42 | if (in_sample.size() == 1u) |
| 43 | is_2d_ = true; |
| 44 | else |
| 45 | is_2d_ = false; |
| 46 | |
| 47 | bnScale_.Resize(Shape{channels_}); |
| 48 | bnBias_.ResetLike(bnScale_); |
| 49 | runningMean_.ResetLike(bnScale_); |
| 50 | runningVariance_.ResetLike(bnScale_); |
| 51 | |
| 52 | dbnScale_.ResetLike(bnScale_); |
| 53 | dbnBias_.ResetLike(bnBias_); |
| 54 | // Push back params into param_values_ |
| 55 | // Assume the order of param is: bnScale, bnBias, runningMean, runningVariance |
| 56 | for (const auto& spec : conf.param()) param_specs_.push_back(spec); |
| 57 | } |
| 58 | |
| 59 | void BatchNorm::ToDevice(std::shared_ptr<Device> device) { |
| 60 | bnScale_.ToDevice(device); |