【发布时间】:2021-02-03 16:38:32
【问题描述】:
我必须处理高度不平衡的数据。据我了解,我需要使用加权交叉熵损失。
我试过了:
import tensorflow as tf
weights = np.array([<values>])
def loss(y_true, y_pred):
# weights.shape = (63,)
# y_true.shape = (64, 63)
# y_pred.shape = (64, 63)
return tf.reduce_mean(tf.nn.weighted_cross_entropy_with_logits(y_true, y_pred, weights))
model.compile('adam', loss=loss, metrics=['acc'])
但是有一个错误:
ValueError: Creating variables on a non-first call to a function decorated with tf.function
我怎样才能造成这种损失?
【问题讨论】:
标签: python tensorflow keras loss-function cross-entropy