【发布时间】:2019-08-30 02:31:34
【问题描述】:
尝试将模型转换为 tflite 或 .pb 文件时出现以下错误:
ValueError:未知损失函数:triplet_loss
我检查了 StackOverflow 和 GitHub 中发布的不同解决方案,但没有一个适用于我的代码。
#calculates triplet loss
def triplet_loss(y_true, y_pred, alpha = 0.2):
anchor, positive, negative = y_pred[0], y_pred[1], y_pred[2]
# triplet loss formula
pos_dist = tf.reduce_sum( tf.square(tf.subtract(anchor, positive)) )
neg_dist = tf.reduce_sum( tf.square(tf.subtract(anchor, negative)) )
basic_loss = pos_dist - neg_dist + alpha
loss = tf.maximum(basic_loss, 0.0)
return loss
# load the model
model = load_model('facenet_model/model.h5', custom_objects={'triplet_loss': triplet_loss})
我相信我必须对三元组损失函数进行一些更改以解决值错误。
【问题讨论】:
标签: python-3.x tensorflow