'How may I do equalized learning rate with tensorflow 2?

I am trying to implement StyleGAN with TensorFlow version 2 and I have no idea how to do an equalized learning rate. I tried to scale gradients this way:

def equalize_in_list(datalist):
    for i in range(len(datalist)):
        if (datalist[i] is list):
            equalize_in_list(datalist[i])
        else:
            datalist[i] = datalist[i] * np.sqrt(2)/np.prod(datalist[i].shape)
    return datalist

gen_grad = equalize_in_list(gen_grad)
disc_grad = equalize_in_list(disc_grad)

But it doesn't work correctly.



Sources

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

Source: Stack Overflow

Solution Source