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

Function test_FlowProjectionModule

my_package/test_module.py:481–574  ·  view source on GitHub ↗
(input1)

Source from the content-addressed store, hash-verified

479 return t2-t1,t3-t2
480
481def test_FlowProjectionModule(input1):
482 # input1 = Variable(torch.zeros(12,3,64,64).type(torch.FloatTensor))
483 # input2 = Variable(torch.rand(12,2,64,64).type(torch.FloatTensor))
484 # input1 = Variable(torch.arange(0.0, 12*3*64*256).view(12,3,64,256), requires_grad=True)
485 # input2 = Variable(torch.rand(12,2,64,256)*20, requires_grad= True)
486 # input2 = Variable(torch.zeros(12,2,64,64))
487 # input2 = Variable(torch.ones(12,2,64,64) * (-2.1))
488 # input2 = Variable(torch.cat((torch.ones(12,1,64,64) *0.251, torch.zeros(12,1,64,64)),dim=1))
489 # input1.data.uniform_()
490 # input2.data.uniform_(-5,5)
491
492 Project = FlowProjectionModule()
493
494 t1 = time.time()
495
496 output = Project(input1)
497 t2 = time.time()
498
499 output.backward(output.data)
500 t3 = time.time()
501
502
503 print("CPU Forward and backward time is : " + str(t2-t1) +"s\t" + str(t3-t2) +"s\t")
504
505 #
506 # print(output)
507 # print(input1.grad.size())
508 # print(input1.grad)
509 # print(output[3,0,...])
510 temp = input1.grad
511
512 # input1 = input1.cuda()
513 # input2 = input2.cuda()
514 # input1_cuda = Variable(torch.arange(0.0, 12*3*64*64).view(12,3,64,64).type(torch.cuda.FloatTensor), requires_grad=True)
515 # input2_cuda = Variable((torch.rand(12,2,64,64)*20).type(torch.cuda.FloatTensor), requires_grad= True)
516 input1_cuda = Variable(input1.data.type(torch.cuda.FloatTensor), requires_grad = True)
517 # input2_cuda = Variable(input2.data.type(torch.cuda.FloatTensor), requires_grad = True)
518 Project = FlowProjectionModule() # regnenerate
519 t1 = time.time()
520 output_cuda = Project(input1_cuda)
521 t2 = time.time()
522 output_cuda.backward(output_cuda.data)
523 t3 = time.time()
524 print("GPU Forward and backward time is : " + str(t2-t1) +"s\t" + str(t3-t2) +"s\t")
525 # print(output_cuda)
526 # print(input1_cuda.grad.size())
527 # print(input1_cuda.grad)
528
529 # print(output_cuda[3,0,...])
530 # print(output[3,0,...]- output_cuda[3,0,...].cpu())
531
532 # print(output_cuda - output.cuda())
533 # print(input1_cuda.grad - input1.grad.cuda())
534
535
536 print("Check the forward path between CPU and GPU...",end='\t')
537 x = output_cuda - output.cuda()
538 # print(output_cuda[0, 0, :10, :10])

Callers

nothing calls this directly

Calls 2

backwardMethod · 0.45

Tested by

no test coverage detected