keras:model.compile损失函数的用法
作者:有石为玉 时间:2023-11-23 08:44:21
损失函数loss:该参数为模型试图最小化的目标函数,它可为预定义的损失函数名,如categorical_crossentropy、mse,也可以为一个损失函数。详情见losses
可用的损失目标函数:
mean_squared_error或mse
mean_absolute_error或mae
mean_absolute_percentage_error或mape
mean_squared_logarithmic_error或msle
squared_hinge
hinge
categorical_hinge
binary_crossentropy
(亦称作对数损失,logloss)
logcosh
categorical_crossentropy:亦称作多类的对数损失,注意使用该目标函数时,需要将标签转化为形如(nb_samples, nb_classes)的二值序列
sparse_categorical_crossentrop:如上,但接受稀疏标签。注意,使用该函数时仍然需要你的标签与输出值的维度相同,你可能需要在标签数据上增加一个维度:np.expand_dims(y,-1)
kullback_leibler_divergence:从预测值概率分布Q到真值概率分布P的信息增益,用以度量两个分布的差异.
poisson:即(predictions - targets * log(predictions))的均值
cosine_proximity:即预测值与真实标签的余弦距离平均值的相反数
补充知识:keras.model.compile() 自定义损失函数注意点
基本用法
model.compile(optimizer=Adam(lr=1e-4), loss='binary_crossentropy', metrics=['accuracy'])
注意
loss后类似'binary_crossentropy'、'mse'等代称
loss为函数名称的时候,不带括号
函数参数必须为(y_true, y_pred, **kwards)的格式
不能直接使用tf.nn.sigmoid_cross_entropy_with_logits等函数,因为其参数格式为(labels=None,
logits=None),需要指定labels=、logits=这两个参数
来源:https://blog.csdn.net/weixin_41770169/article/details/80184115
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
全屏窗无提示关闭父窗口
盘点30个经典常用的JavaScript知识点
1500个绚丽主题 谷歌中国个人风格首页发布
![](https://img.aspxhome.com/file/UploadPic/200811/12/1555350-62s.jpg)
Python采集猫眼两万条数据 对《无名之辈》影评进行分析
![](https://img.aspxhome.com/file/2023/3/131723_0s.png)
Python Excel数据处理之xlrd/xlwt/xlutils模块详解
![](https://img.aspxhome.com/file/2023/9/103679_0s.png)
Golang通过包长协议处理TCP粘包的问题解决
![](https://img.aspxhome.com/file/2023/2/130742_0s.png)
jupyter 中文乱码设置编码格式 避免控制台输出的解决
![](https://img.aspxhome.com/file/2023/1/86241_0s.jpg)
struts2.3.24+spring4.1.6+hibernate4.3.11+mysql5.5.25开发环境搭建图文教程
![](https://img.aspxhome.com/file/2023/5/68735_0s.jpg)
Python 批量下载阴阳师网站壁纸
Vue.js中的图片引用路径的方式
JS的千分位算法实现思路
B/S模式项目中常用的javascript汇总
Python 中字符串拼接的多种方法
php中数字、字符与对象判断函数用法实例
基于JS实现01支付后的10秒倒计时
![](https://img.aspxhome.com/file/2023/8/136808_0s.png)
Bootstrap每天必学之表单
![](https://img.aspxhome.com/file/2023/5/126815_0s.png)
Python带动态参数功能的sqlite工具类
JavaScript 实现 Konami Code
![](https://img.aspxhome.com/file/UploadPic/20095/26/facebook-55s.jpg)
Python OpenCV实现图形检测示例详解
![](https://img.aspxhome.com/file/2023/8/103498_0s.jpg)