def bprop(self, grad, input, output, outGrad): cudaconv2.convImgActs(grad, self.weight, outGrad, self.imgSize, self.imgSize, self.outputSize, -self.padding, self.stride, self.numColor, 1, 0.0, 1.0) # bprop weight self.weightGrad.fill(0) cudaconv2.convWeightActs(input, grad, self.weightGrad, self.imgSize, self.outputSize, self.outputSize, self.filterSize, -self.padding, self.stride, self.numColor, 1, 0, 0, 1) # bprop bias self.biasGrad.fill(0) gpu_copy_to(grad, self.tmp) add_row_sum_to_vec(self.biasGrad, self.tmp)
def convWeightActs(input, ingrad, weight_grad, bias_grad, padding, stride, color, *args): image_y = input.shape[ConvDataLayout.HEIGHT] output_y = ingrad.shape[ConvDataLayout.HEIGHT] output_x = ingrad.shape[ConvDataLayout.WIDTH] filter_size = weight_grad.shape[FilterLayout.HEIGHT] color = input.shape[ConvDataLayout.CHANNEL] cudaconv2.convWeightActs(input, ingrad, weight_grad, image_y, output_y, output_x, filter_size, padding, stride, color, 1, 0) batch_size = ingrad.shape[ConvDataLayout.BATCH] channel = ingrad.shape[ConvDataLayout.CHANNEL] cudaconv2.sum(ingrad.reshape((channel, output_y * output_x * batch_size)), 1, bias_grad)
def bprop(self, grad, input, output, outGrad): self.weight.grad.fill(0) self.bias.grad.fill(0) # bprop to next layer cudaconv2.convImgActs(grad, self.weight.wt, outGrad, self.img_size, self.img_size, self.outputSize, -self.padding, self.stride, self.numColor, 1, 0.0, 1.0) # bprop weight cudaconv2.convWeightActs(input, grad, self.weight.grad, self.img_size, self.outputSize, self.outputSize, self.filterSize, -self.padding, self.stride, self.numColor, 1, 0, 0, 1) # bprop bias gpu_copy_to(grad, self.tmp) add_row_sum_to_vec(self.bias.grad, self.tmp)