MCPcopy Create free account
hub / github.com/davisking/dlib / batch_normalize_gradient

Function batch_normalize_gradient

dlib/cuda/cudnn_dlibapi.cpp:470–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468 }
469
470 void batch_normalize_gradient(
471 const double eps,
472 const tensor& gradient_input,
473 const tensor& means,
474 const tensor& invstds,
475 const tensor& src,
476 const tensor& gamma,
477 tensor& src_grad,
478 tensor& gamma_grad,
479 tensor& beta_grad
480 )
481 {
482 const long num = src.k()*src.nr()*src.nc();
483 DLIB_CASSERT(src.num_samples() > 1);
484 DLIB_CASSERT(num == (long)means.size());
485 DLIB_CASSERT(num == (long)invstds.size());
486 DLIB_CASSERT(num == (long)gamma.size());
487 DLIB_CASSERT(num == (long)gamma_grad.size());
488 DLIB_CASSERT(num == (long)beta_grad.size());
489 DLIB_CASSERT(have_same_dimensions(gradient_input, src));
490 DLIB_CASSERT(have_same_dimensions(gradient_input, src_grad));
491 DLIB_CASSERT(eps > 0);
492
493 const float in_scale = 1;
494 const float out_scale = 1;
495 const float in_scale_params = 1;
496 const float out_scale_params = 0;
497
498 CHECK_CUDNN(cudnnBatchNormalizationBackward(
499 context(),
500 CUDNN_BATCHNORM_PER_ACTIVATION,
501 &in_scale,
502 &out_scale,
503 &in_scale_params,
504 &out_scale_params,
505 descriptor(src),
506 src.device(),
507 descriptor(gradient_input),
508 gradient_input.device(),
509 descriptor(src_grad),
510 src_grad.device(),
511 descriptor(gamma),
512 gamma.device(),
513 gamma_grad.device(),
514 beta_grad.device(),
515 eps,
516 means.device(),
517 invstds.device()));
518 }
519
520 // ------------------------------------------------------------------------------------
521

Callers

nothing calls this directly

Calls 9

descriptorFunction · 0.85
have_same_dimensionsFunction · 0.70
contextFunction · 0.70
kMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
num_samplesMethod · 0.45
sizeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected