Example #1
0
def convImgActs(input, grad, weight, out_grad, padding, stride):
  image_y =  input.shape[ConvDataLayout.HEIGHT]
  image_x =  input.shape[ConvDataLayout.WIDTH]
  output_y =  grad.shape[ConvDataLayout.HEIGHT]
  color = input.shape[ConvDataLayout.CHANNEL]

  cudaconv2.convImgActs(grad, weight, out_grad, image_y, image_x, output_y, padding, stride, color, 1)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0

'''
model = load('./checkpoint/test4-8.22')
net = FastNet(1.0,  (128, 3, 32, 32), 0, initModel = model)
'''

numColor = 1
numFilter = 64
filterSize = 5
imgSize = 32
outputSize = 32
padding = 2
stride = 1
batchSize = 1
'''
grad = gpuarray.to_gpu(np.ones((numFilter * outputSize * outputSize, batchSize), dtype = np.float32)
    * 2)
filter = gpuarray.to_gpu(np.ones((numColor * filterSize * filterSize, numFilter), dtype = np.float32))

outGrad = gpuarray.to_gpu(np.ones((numColor* outputSize * outputSize, batchSize), dtype = np.float32))

cudaconv2.convImgActs(grad, filter, outGrad, imgSize, imgSize, outputSize, -padding, stride, numColor, 1, 0.0, 1.0)
print_matrix(outGrad, 'grad')

input = gpuarray.to_gpu(np.ones((numColor * imgSize * imgSize, batchSize), dtype= np.float32) * 2)
weightGrad = gpuarray.to_gpu(np.ones((numColor * filterSize * filterSize, numFilter), dtype =
  np.float32))

cudaconv2.convWeightActs(input, grad, weightGrad, imgSize, outputSize, outputSize, filterSize, -padding, stride,
    numColor, 1, 0, 1, 1)
Example #7
0
'''
model = load('./checkpoint/test4-8.22')
net = FastNet(1.0,  (128, 3, 32, 32), 0, initModel = model)
'''

numColor = 1
numFilter = 64
filterSize = 5
imgSize = 32
outputSize = 32
padding = 2
stride = 1
batchSize = 1


'''
grad = gpuarray.to_gpu(np.ones((numFilter * outputSize * outputSize, batchSize), dtype = np.float32)
    * 2)
filter = gpuarray.to_gpu(np.ones((numColor * filterSize * filterSize, numFilter), dtype = np.float32))

outGrad = gpuarray.to_gpu(np.ones((numColor* outputSize * outputSize, batchSize), dtype = np.float32))

cudaconv2.convImgActs(grad, filter, outGrad, imgSize, imgSize, outputSize, -padding, stride, numColor, 1, 0.0, 1.0)
print_matrix(outGrad, 'grad')

input = gpuarray.to_gpu(np.ones((numColor * imgSize * imgSize, batchSize), dtype= np.float32) * 2)
weightGrad = gpuarray.to_gpu(np.ones((numColor * filterSize * filterSize, numFilter), dtype =
  np.float32))

cudaconv2.convWeightActs(input, grad, weightGrad, imgSize, outputSize, outputSize, filterSize, -padding, stride,
    numColor, 1, 0, 1, 1)