When I excute testing code, an error occured.
 File "/home/mamingrui/code/MyOwn/train_v1.py", line 61, in train
    grad_loss = grad_loss(flow)
TypeError: 'Tensor' object is not callable


This is the loss function.
def gradient_loss(s, penalty='l2'):
    dy = torch.abs(s[:, :, 1:, :, :] - s[:, :, :-1, :, :])
    dx = torch.abs(s[:, :, :, 1:, :] - s[:, :, :, :-1, :])
    dz = torch.abs(s[:, :, :, :, 1:] - s[:, :, :, :, :-1])

    if (penalty == 'l2'):
        dy = dy * dy
        dx = dx * dx
        dz = dz * dz

    d = torch.mean(dx) + torch.mean(dy) + torch.mean(dz)
    return d / 3.0


and this is the train.
    for epoch in range(iters):
        start_time = time.time()
        loss_batch = 0

        for batch_moving in train_set:
            print("^^^^^^moving size is {}^^^^^^".format(batch_moving.size()))
            wrap, flow = model(batch_moving, fixed)
            recon_loss = similarity_loss(wrap, fixed)
            grad_loss = grad_loss(flow)
            loss = recon_loss + reg_param * grad_loss

      
            loss_batch += loss

            print("The loss without average is {}".format(loss))

            opt.zero_grad()
            loss.backward()
            opt.step()


How can I fix this bug? very appreciate!