当前位置: 首页 > news >正文

win7如何安装iis来浏览asp网站/广州灰色优化网络公司

win7如何安装iis来浏览asp网站,广州灰色优化网络公司,网站开发需要的技术,wordpress 首页调用产品Keras中自定义目标函数(损失函数)在做kaggle项目时,看到一个人设计了一个unet,使用自定义的iou作为损失函数,才想起来原来可以自己设计损失函数…为了实现自己的目标函数,自然想到先看下Keras中的目标函数是定义的,查下…

Keras中自定义目标函数(损失函数)

在做kaggle项目时,看到一个人设计了一个unet,使用自定义的iou作为损失函数,才想起来原来可以自己设计损失函数…

为了实现自己的目标函数,自然想到先看下Keras中的目标函数是定义的,查下源码发现在/usr/local/lib/python3.5/dist-packages/keras中(我的系统是ubuntu16.04,使用系统自带的python3.5),Keras已经定义了一系列的目标函数。

当然是要先查看下Keras源码了…

"""Built-in loss functions.

"""

from __future__ import absolute_import

from __future__ import division

from __future__ import print_function

import six

from . import backend as K

from .utils.generic_utils import deserialize_keras_object

from .utils.generic_utils import serialize_keras_object

def mean_squared_error(y_true, y_pred):

return K.mean(K.square(y_pred - y_true), axis=-1)

def mean_absolute_error(y_true, y_pred):

return K.mean(K.abs(y_pred - y_true), axis=-1)

def mean_absolute_percentage_error(y_true, y_pred):

diff = K.abs((y_true - y_pred) / K.clip(K.abs(y_true),

K.epsilon(),

None))

return 100. * K.mean(diff, axis=-1)

def mean_squared_logarithmic_error(y_true, y_pred):

first_log = K.log(K.clip(y_pred, K.epsilon(), None) + 1.)

second_log = K.log(K.clip(y_true, K.epsilon(), None) + 1.)

return K.mean(K.square(first_log - second_log), axis=-1)

def squared_hinge(y_true, y_pred):

return K.mean(K.square(K.maximum(1. - y_true * y_pred, 0.)), axis=-1)

def hinge(y_true, y_pred):

return K.mean(K.maximum(1. - y_true * y_pred, 0.), axis=-1)

def categorical_hinge(y_true, y_pred):

pos = K.sum(y_true * y_pred, axis=-1)

neg = K.max((1. - y_true) * y_pred, axis=-1)

return K.maximum(0., neg - pos + 1.)

def logcosh(y_true, y_pred):

"""Logarithm of the hyperbolic cosine of the prediction error.

`log(cosh(x))` is approximately equal to `(x ** 2) / 2` for small `x` and

to `abs(x) - log(2)` for large `x`. This means that 'logcosh' works mostly

like the mean squared error, but will not be so strongly affected by the

occasional wildly incorrect prediction.

# Arguments

y_true: tensor of true targets.

y_pred: tensor of predicted targets.

# Returns

Tensor with one scalar loss entry per sample.

"""

def _logcosh(x):

return x + K.softplus(-2. * x) - K.log(2.)

return K.mean(_logcosh(y_pred - y_true), axis=-1)

def categorical_crossentropy(y_true, y_pred):

return K.categorical_crossentropy(y_true, y_pred)

def sparse_categorical_crossentropy(y_true, y_pred):

return K.sparse_categorical_crossentropy(y_true, y_pred)

def binary_crossentropy(y_true, y_pred):

return K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1)

def kullback_leibler_divergence(y_true, y_pred):

y_true = K.clip(y_true, K.epsilon(), 1)

y_pred = K.clip(y_pred, K.epsilon(), 1)

return K.sum(y_true * K.log(y_true / y_pred), axis=-1)

def poisson(y_true, y_pred):

return K.mean(y_pred - y_true * K.log(y_pred + K.epsilon()), axis=-1)

def cosine_proximity(y_true, y_pred):

y_true = K.l2_normalize(y_true, axis=-1)

y_pred = K.l2_normalize(y_pred, axis=-1)

return -K.sum(y_true * y_pred, axis=-1)

# Aliases.

mse = MSE = mean_squared_error

mae = MAE = mean_absolute_error

mape = MAPE = mean_absolute_percentage_error

msle = MSLE = mean_squared_logarithmic_error

kld = KLD = kullback_leibler_divergence

cosine = cosine_proximity

def serialize(loss):

return serialize_keras_object(loss)

def deserialize(name, custom_objects=None):

return deserialize_keras_object(name,

module_objects=globals(),

custom_objects=custom_objects,

printable_module_name='loss function')

def get(identifier):

"""Get the `identifier` loss function.

# Arguments

identifier: None or str, name of the function.

# Returns

The loss function or None if `identifier` is None.

# Raises

ValueError if unknown identifier.

"""

if identifier is None:

return None

if isinstance(identifier, six.string_types):

identifier = str(identifier)

return deserialize(identifier)

if isinstance(identifier, dict):

return deserialize(identifier)

elif callable(identifier):

return identifier

else:

raise ValueError('Could not interpret '

'loss function identifier:', identifier)

看到源码后,事情就简单多了

首先定义损失函数IoU

## intersection over union

def IoU(y_true, y_pred, eps=1e-6):

if np.max(y_true) == 0.0:

return IoU(1-y_true, 1-y_pred) ## empty image; calc IoU of zeros

intersection = K.sum(y_true * y_pred, axis=[1,2,3])

union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3]) - intersection

return -K.mean( (intersection + eps) / (union + eps), axis=0)

然后执行编译

seg_model.compile(optimizer=Adam(1e-3, decay=1e-6), loss=IoU, metrics=['binary_accuracy'])就是这么简单…

http://www.lbrq.cn/news/773101.html

相关文章:

  • 大学生帮别人做网站/推广网站公司
  • 网站开发 外包 哪家/北京网站制作设计
  • 淄博网站建设相关文章/营销型网站有哪些平台
  • 外贸网站设计制作/域名seo站长工具
  • 如何做设计网站页面/黄山seo推广
  • 网站建设的违约责任/专业seo网络营销公司
  • 深圳企业网站定制公司/厦门人才网个人会员登录
  • 网站开发流程分析/网站关键词优化怎么做的
  • 大连网站建设仟亿科技/二级域名查询网站
  • 浦东网站建设公司/阿里指数app下载
  • 公司定制网站建设公司/汕头seo计费管理
  • 博物馆建设网站/百度推广seo
  • 如何建设幼儿园网站方案/深圳广告策划公司
  • 清溪镇网站建设/电脑优化用什么软件好
  • 昌平区住房城乡建设委 房管局 官方网站/seo的范畴是什么
  • 临夏市建设局网站/西安seo顾问培训
  • wordpress引入css样式/淘宝关键词排名优化
  • 二次开发是指/seo专家是什么意思
  • wordpress 加上广告/seo是什么意思蜘蛛屯
  • 招标资源网官网/北京网站优化方式
  • 建设工程消防网站进入程序/软文营销ppt
  • 成都 企业网站建设公司/网络推广视频
  • 做网站免费服务器哪家好/百度不收录网站
  • 艺梵科技 网站建设/seo网页优化工具
  • 4399游戏网页版入口/seo搜索引擎优化课程总结
  • 做电商平台网站有哪些内容/网站建设与营销经验
  • 做好网站建设工作/厦门seo百度快照优化
  • 赛马网站开发出售/百度打开
  • 公司网站做的好的/黑帽seo优化软件
  • 网站开发的招标参数/网站免费网站免费优化优化
  • 408每日一题笔记 41-50
  • 开源日志log4cplus—调用MultiByteToWideChar提示未定义,CP_UTF8未定义定原因有哪些,如何改进?
  • 【element树组件】el-tree实现连接线及hover编辑效果
  • 【项目设计】高并发内存池
  • Redis 数据结构及特点
  • CI/CD渗透测试靶场