|
|
|
@ -21,7 +21,7 @@ namespace paddle {
|
|
|
|
|
|
|
|
|
|
REGISTER_LAYER(cudnn_batch_norm, CudnnBatchNormLayer);
|
|
|
|
|
|
|
|
|
|
const double CudnnBatchNormLayer::EPS = 1E-5;
|
|
|
|
|
const double CudnnBatchNormLayer::MIN_EPS = 1E-5;
|
|
|
|
|
|
|
|
|
|
bool CudnnBatchNormLayer::init(const LayerMap& layerMap,
|
|
|
|
|
const ParameterMap& parameterMap) {
|
|
|
|
@ -60,6 +60,7 @@ void CudnnBatchNormLayer::forward(PassType passType) {
|
|
|
|
|
real* beta = biases_->getW()->getData();
|
|
|
|
|
real* movingMean = movingMean_->getW()->getData();
|
|
|
|
|
real* movingVar = movingVar_->getW()->getData();
|
|
|
|
|
EPS_ = std::max(MIN_EPS, static_cast<double>(EPS));
|
|
|
|
|
|
|
|
|
|
if (!useGlobalStats_) {
|
|
|
|
|
REGISTER_TIMER_INFO("CudnnBatchFwTimer", getName().c_str());
|
|
|
|
@ -75,7 +76,7 @@ void CudnnBatchNormLayer::forward(PassType passType) {
|
|
|
|
|
1.0 - movingAvgFraction_,
|
|
|
|
|
movingMean,
|
|
|
|
|
movingVar,
|
|
|
|
|
EPS,
|
|
|
|
|
EPS_,
|
|
|
|
|
savedMean,
|
|
|
|
|
savedInvVar);
|
|
|
|
|
} else {
|
|
|
|
@ -90,7 +91,7 @@ void CudnnBatchNormLayer::forward(PassType passType) {
|
|
|
|
|
beta,
|
|
|
|
|
movingMean,
|
|
|
|
|
movingVar,
|
|
|
|
|
EPS);
|
|
|
|
|
EPS_);
|
|
|
|
|
} else {
|
|
|
|
|
// There is a limitation in cudnn library.
|
|
|
|
|
// When the batch size is larger than 1024 in cuDNN v5.1,
|
|
|
|
@ -101,7 +102,7 @@ void CudnnBatchNormLayer::forward(PassType passType) {
|
|
|
|
|
beta,
|
|
|
|
|
movingMean,
|
|
|
|
|
movingVar,
|
|
|
|
|
EPS,
|
|
|
|
|
EPS_,
|
|
|
|
|
batchSize,
|
|
|
|
|
channels_,
|
|
|
|
|
imageH_ * imageD_,
|
|
|
|
@ -127,6 +128,7 @@ void CudnnBatchNormLayer::backward(const UpdateCallback& callback) {
|
|
|
|
|
real* gamma = weight_->getW()->getData();
|
|
|
|
|
real* savedMean = savedMean_->getData();
|
|
|
|
|
real* savedInvVar = savedInvVar_->getData();
|
|
|
|
|
EPS_ = std::max(MIN_EPS, static_cast<double>(EPS));
|
|
|
|
|
|
|
|
|
|
auto create = [](MatrixPtr& m, size_t h, size_t w, real** p) {
|
|
|
|
|
Matrix::resizeOrCreate(m, h, w, false, true);
|
|
|
|
@ -157,7 +159,7 @@ void CudnnBatchNormLayer::backward(const UpdateCallback& callback) {
|
|
|
|
|
gamma,
|
|
|
|
|
gammaGrad,
|
|
|
|
|
betaGrad,
|
|
|
|
|
EPS,
|
|
|
|
|
EPS_,
|
|
|
|
|
savedMean,
|
|
|
|
|
savedInvVar);
|
|
|
|
|
|
|
|
|
|