keras GAN训练是loss不发生变化,accuracy一直为0.5

可能是激活层的激活方式与损失函数不匹配。

一般使用sigmoid,损失函数使用binary_crossentropy ;使用softmax,损失函数使用categorical_crossentropy。

作者:Yohanna
链接:https://www.zhihu.com/question/36307214/answer/364963552
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
 

  1. Binary Cross Entropy

常用于二分类问题,当然也可以用于多分类问题,通常需要在网络的最后一层添加sigmoid进行配合使用,其期望输出值(target)需要进行one hot编码,另外BCELoss还可以用于多分类问题Multi-label classification.

定义:
For brevity, let x = output, z = target. The binary cross entropy loss is
loss(x, z) = - sum_i (x[i] * log(z[i]) + (1 - x[i]) * log(1 - z[i]))

对应的代码为:

def binary_crossentropy(t,o):
    return -(t*tf.log(o+eps) + (1.0-t)*tf.log(1.0-o+eps))

2. Categorical cross-entropy

p are the predictions, t are the targets, i denotes the data point and j denotes the class.

适用于多分类问题,并使用softmax作为输出层的激活函数的情况。

猜你喜欢

转载自blog.csdn.net/weixin_38582851/article/details/82222411