MCPcopy Create free account
hub / github.com/baowenbo/DAIN / test_WeightedFlowProjectionModule

Function test_WeightedFlowProjectionModule

my_package/test_module.py:671–766  ·  view source on GitHub ↗
(input1 , input2, input3)

Source from the content-addressed store, hash-verified

669 return t2-t1,t3-t2
670
671def test_WeightedFlowProjectionModule(input1 , input2, input3):
672 # input1 = Variable(torch.zeros(12,3,64,64).type(torch.FloatTensor))
673 # input2 = Variable(torch.rand(12,2,64,64).type(torch.FloatTensor))
674 # input1 = Variable(torch.arange(0.0, 12*3*64*256).view(12,3,64,256), requires_grad=True)
675 # input2 = Variable(torch.rand(12,2,64,256)*20, requires_grad= True)
676 # input2 = Variable(torch.zeros(12,2,64,64))
677 # input2 = Variable(torch.ones(12,2,64,64) * (-2.1))
678 # input2 = Variable(torch.cat((torch.ones(12,1,64,64) *0.251, torch.zeros(12,1,64,64)),dim=1))
679 # input1.data.uniform_()
680 # input2.data.uniform_(-5,5)
681
682 # Project = FlowProjectionModule()
683 Project = WeightedFlowProjectionModule(threshold=20.0/255.0,requires_grad=True)
684
685 t1 = time.time()
686
687 output = Project(input1,input2,input3)
688 t2 = time.time()
689
690 output.backward(output.data)
691 t3 = time.time()
692
693
694 print("CPU Forward and backward time is : " + str(t2-t1) +"s\t" + str(t3-t2) +"s\t")
695
696 #
697 # print(output)
698 # print(input1.grad.size())
699 # print(input1.grad)
700 # print(output[3,0,...])
701 temp = input1.grad
702
703 # input1 = input1.cuda()
704 # input2 = input2.cuda()
705 # input1_cuda = Variable(torch.arange(0.0, 12*3*64*64).view(12,3,64,64).type(torch.cuda.FloatTensor), requires_grad=True)
706 # input2_cuda = Variable((torch.rand(12,2,64,64)*20).type(torch.cuda.FloatTensor), requires_grad= True)
707 input1_cuda = Variable(input1.data.type(torch.cuda.FloatTensor), requires_grad = True)
708 input2_cuda = Variable(input2.data.type(torch.cuda.FloatTensor), requires_grad = True)
709 input3_cuda = Variable(input3.data.type(torch.cuda.FloatTensor), requires_grad = True)
710 Project = WeightedFlowProjectionModule(threshold=20.0/255.0, requires_grad=True) # regnenerate
711 t1 = time.time()
712 output_cuda = Project(input1_cuda,input2_cuda,input3_cuda)
713 t2 = time.time()
714 output_cuda.backward(output_cuda.data)
715 t3 = time.time()
716 print("GPU Forward and backward time is : " + str(t2-t1) +"s\t" + str(t3-t2) +"s\t")
717 # print(output_cuda)
718 # print(input1_cuda.grad.size())
719 # print(input1_cuda.grad)
720
721 # print(output_cuda[3,0,...])
722 # print(output[3,0,...]- output_cuda[3,0,...].cpu())
723
724 # print(output_cuda - output.cuda())
725 # print(input1_cuda.grad - input1.grad.cuda())
726
727
728 print("Check the forward path between CPU and GPU...",end='\t')

Callers 1

test_module.pyFile · 0.85

Calls 1

backwardMethod · 0.45

Tested by

no test coverage detected