예제 #1
0
def instanceNorm2dBackward(grad,
                           data,
                           extscale,
                           savemean,
                           saveinvvar,
                           epsilon,
                           affine=True):
    batchsize, maps = grad.shape[:2]

    outgrad = grad.reshape(1, batchsize * grad.shape[1], grad.shape[2],
                           grad.shape[3])
    indata = data.reshape(1, batchsize * data.shape[1], data.shape[2],
                          data.shape[3])

    ingrad, scalegrad, bgrad = MIOpen.batchNorm2dBackward(
        indata, outgrad, extscale, savemean, saveinvvar, epsilon)

    if affine and batchsize > 1:
        scalegrad = CLBlas.sumOnMatrix(scalegrad.reshape(batchsize,
                                                         -1)).reshape(
                                                             1, maps, 1, 1)
        bgrad = CLBlas.sumOnMatrix(bgrad.reshape(batchsize,
                                                 -1)).reshape(1, maps, 1, 1)

    if affine:
        return ingrad.reshape(grad.shape), scalegrad, bgrad
    else:
        return ingrad.reshape(grad.shape)
예제 #2
0
파일: Basic.py 프로젝트: rsarbaev/PuzzleLib
 def wrapBatchNormNdBackward(data,
                             grad,
                             scale,
                             savemean,
                             saveinvvar,
                             epsilon,
                             mode=None):
     return MIOpen.batchNorm2dBackward(data, grad, scale, savemean,
                                       saveinvvar, epsilon)