Example #1
0
#  control_points_batch = control_points_l * batch_size
# print(torch.Tensor(np.array(control_points_batch)).size())

control_points_t = Variable(torch.Tensor(np.array(control_points_l)),
                            requires_grad=True)

elapsed_fw, elapsed_bw = 0, 0

passes = args.passes
crit = torch.nn.L1Loss().cuda()
tic_total = time()
memory_cached, memory_allocated = 0, 0
for i in range(passes):
    tic = time()
    curve = net.forward(control_points_t)
    if use_cuda:
        torch.cuda.synchronize()
    elapsed_fw += time() - tic
    #  print('{}: Total.'.format(time() - tic))
    loss = crit(curve, curve.clone().detach())
    tic = time()
    #  print('{}: Loss.'.format(time() - tic))
    loss.backward()
    if use_cuda:
        torch.cuda.synchronize()
    elapsed_bw += time() - tic
    if use_cuda:
        memory_allocated = torch.cuda.max_memory_allocated()
        memory_cached = torch.cuda.max_memory_cached()