【发布时间】:2021-12-30 06:50:08
【问题描述】:
我正在使用 VGG16 进行图像分割,损失函数“平衡分类熵”使用代码
beta=0.5
def balanced_cross_entropy(beta):
def loss(y_true, y_pred):
weight_a = beta * tf.cast(y_true, tf.float32)
weight_b = (1 - beta) * tf.cast(1 - y_true, tf.float32)
o = (tf.math.log1p(tf.exp(-tf.abs(y_pred))) + tf.nn.relu(-y_pred)) * (weight_a + weight_b) + y_pred * weight_b
return tf.reduce_mean(o)
return loss
一切正常。现在我使用代码将此模型保存在 h5 文件中。
vgg.save('vgg.h5')
但是当我使用 Keras 的 load_model 时
model = load_model('vgg.h5', custom_objects={'balanced_cross_entropy(beta)': balanced_cross_entropy(beta)})
我遇到了一个错误。
Unknown loss function: loss. Please ensure this object is passed to the `custom_objects` argument.
谁能帮忙,我怀疑问题可能是由于测试版造成的?
【问题讨论】:
标签: tensorflow keras image-segmentation loss-function