keras如何自定义损失函数(进阶版,not of the form of f(x_true, x_pred))

本文介绍了如何在Keras中自定义非标准形式的损失函数,包括采用函数式API定义模型,定义自定义成本,利用优化器进行权重更新,手动处理正则化和BatchNorm更新,以及创建基于输入、输出和更新的Keras函数。
摘要由CSDN通过智能技术生成

一,keras如何自定义损失函数(进阶版,not of the form of f(x_true, x_pred))

1.define your model (typically using the functional API)
采用函数式定义模型,之前说过,keras定义模型有model与K.function两种。一般两者结合使用。

2.define your custom cost,定义自己的损失函数

3.instantiate an optimizer, get weights updates via:
updates = optimizer.get_updates(model.trainable_weights, model.constraints, cost))
使用优化子的training_updates 进行权重及loss更新。

training_updates = Adam(lr=self.lrD*loss_config['lr_factor'], beta_1=
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值