jiyegege / AnimeGANv2_Tensorflow2

Implementing AnimeGANv2 with Tensorflow2
11 stars 6 forks source link

About style loss #2

Closed JJASMINE22 closed 1 year ago

JJASMINE22 commented 1 year ago

According to the generator's style loss provided by https://github.com/TachibanaYoshino/AnimeGANv2/blob/617ab10ce21877df90c9cf2b705712bc81b1e2e6/tools/ops.py Maybe function gram() should be expressed like:

feat = tf.linalg.einsum('bijc,bijd->bcd', x, x)
num_locations = tf.math.reduce_prod(x.shape[1:])
num_locations = tf.cast(num_locations, dtype=tf.float32)

feat = feat/num_locations

Otherwise, it may cause generator gradient explosion, and difficult to achieve Antagonism effect

jiyegege commented 1 year ago

Thanks for your issue, I did find the gradient explosion problem after replacing the backstone, now I used your code to train again and it did solve the problem, the loss curve is also normal compared to before. before:

image

after:

image