def forward(self, input1): # assert(input1.is_contiguous()) # assert(input2.is_contiguous()) self.input1 = input1.contiguous( ) # need to use in the backward process, so we need to cache it if input1.is_cuda: self.device = torch.cuda.current_device() else: self.device = -1 # count = torch.zeros(input1.size(0),1,input1.size(2),input1.size(3)) # for accumulating the homography projections output = torch.zeros(input1.size()) if input1.is_cuda: output = output.cuda() # count = count.cuda() err = my_lib.FlowFillholelayer_gpu_forward(input1, output) else: # output = torch.cuda.FloatTensor(input1.data.size()) err = my_lib.FlowFillholelayer_cpu_forward(input1, output) if err != 0: print(err) # output = output/count # to divide the counter # self.count = count #to keep this # print(self.input1[0, 0, :10, :10]) # print(self.count[0, 0, :10, :10]) # print(self.input1[0, 0, -10:, -10:]) # print(self.count[0, 0, -10:, -10:]) # the function returns the output to its caller return output
def forward(ctx, input1): output = torch.zeros(input1.size()) if input1.is_cuda : output = output.cuda() err = my_lib.FlowFillholelayer_gpu_forward(input1, output) else: err = my_lib.FlowFillholelayer_cpu_forward(input1, output) if err != 0: print(err) ctx.save_for_backward(input1.contiguous()) ctx.device = torch.cuda.current_device() if input1.is_cuda else -1 return output