'Trying to write a custom loss function in tensorflow

I am trying to make a custom loss function where I perform an inverse fast Fourier transform to a set of data and then do the following calculations. When I run this model the gradient returns an array of Nones , size 14. and gives me the following error: ValueError: No gradients provided for any variable this is the loss function code snippet:

    loss = []
    for i in range(batchsize):
        x3 = tf.signal.ifft(data.numpy()[:, i])
        loss.append(tf.reduce_max(KB.square(abs_with_grad(x3)), axis = -1) / tf.reduce_mean(KB.square(abs_with_grad(x3)), axis = -1))
    x = tf.reduce_sum(loss, axis=-1)
    return x

i suspect the ifft is not differentiable but i don't know how to fix this problem. any help or hints is much appreciated

Edit: there is some input output conditioning happening before passing data to loss function, here is the loss function with this operations done inside

def PAPR_Loss(y_true, y_pred):
    batchsize = 400
    print(y_pred)
    datanp = np.zeros((N, batchsize), dtype = complex)
    for i in range(batchsize):
        counter_input = 0
        counter_output = 0
        for j in range(0, N):
            if j not in Reserved_phases:
                datanp[j, i] = y_true.numpy()[i, counter_input] + 1j* y_true.numpy()[i, counter_input+1]
                counter_input += 2
            else:
                datanp[j, i] = y_pred.numpy()[0, counter_output] + 1j* y_pred.numpy()[0, counter_output+1]
                counter_output += 2
    data = tf.Variable(datanp, dtype=tf.complex64, trainable= True)
    print(data)
    loss = np.zeros(batchsize, dtype = float)
    for i in range(batchsize):
        x3 = tf.signal.ifft(data.numpy()[:, i])
        loss[i] = tf.reduce_max(KB.square(abs_with_grad(x3.numpy())), axis = -1) / tf.reduce_mean(KB.square(abs_with_grad(x3.numpy())), axis = -1)
    print(loss)
    return loss


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source