嗨,我一直在尝试在keras中为dice_error_coefficient创建自定义丢失函数.它有它的实现tensorboard,我尝试使用相同的功能与tensorflow keras但它一直返回NoneType当我用model.train_on_batch或model.fit其中在模型中的指标使用时,它提供正确的价值观.可以请有人帮我解决我该怎么办?我曾经尝试过像ahundt这样的Keras-FCN这样的库,在那里他使用了自定义丢失函数,但似乎都没有.代码中的目标和输出分别是y_true和y_pred,如keras中的losses.py文件中所使用的那样.
def dice_hard_coe(target, output, threshold=0.5, axis=[1,2], smooth=1e-5):
"""References
-----------
- `Wiki-Dice <https://en.wikipedia.org/wiki/Sørensen–Dice_coefficient>`_
"""
output = tf.cast(output > threshold, dtype=tf.float32)
target = tf.cast(target > threshold, dtype=tf.float32)
inse = tf.reduce_sum(tf.multiply(output, target), axis=axis)
l = tf.reduce_sum(output, axis=axis)
r = tf.reduce_sum(target, axis=axis)
hard_dice = (2. * inse + smooth) / (l + r + smooth)
hard_dice = tf.reduce_mean(hard_dice)
return hard_dice
Run Code Online (Sandbox Code Playgroud) 我想在数据科学项目中进行预测,并通过非对称函数计算误差.
是否可以调整随机森林或梯度增强(sklearn)的损失函数?
我已经读过需要修改.pyx文件,但我在sklearn文件夹中找不到任何文件(我在ubuntu 14.04 LTS上).
你有什么建议吗?