首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ValueError:未知损失function:triplet_loss

ValueError:未知损失function:triplet_loss
EN

Stack Overflow用户
提问于 2019-08-30 02:31:34
回答 1查看 82关注 0票数 1

在尝试将模型转换为tflite或.pb文件时出错:

ValueError:未知损失function:triplet_loss

我检查了在StackOverflow和GitHub中发布的不同解决方案,但它们都不适合我的代码。

代码语言:javascript
复制
#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})

我认为我必须对三重态损失函数做一些修改,以解决价值错误。

EN

回答 1

Stack Overflow用户

发布于 2021-09-28 06:00:19

在前两个步骤中使用tf.reduce_sum()的轴参数等于-1。这可能会解决你的问题。

代码语言:javascript
复制
pos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor,positive)),axis=-1)
neg_dist = tf.reduce_sum(tf.square(tf.subtract(anchor,negative)),axis=-1)
basic_loss = pos_dist - neg_dist + alpha
loss = tf.reduce_sum(tf.maximum(basic_loss,0.0))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57719800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档