calcifications loss
import keras
import tensorflow as tf
from keras.models import Model
from keras import backend as K
# import tensorflow.contrib.eager as tfe
# tfe.enable_eager_execution() beta = K.constant(0.5, dtype='float32')
lamdap = K.constant(1.5, dtype='float32')
lamdan = K.constant(1.8, dtype='float32') # Custom loss function
def t_test_loss(y_true, y_pred):
sess = tf.Session()
# print("y_pred:",y_pred)
# print(K.sum(y_true[:, 0]))
# print(tuple(y_pred.shape[1:].as_list()))
pos = K.zeros(shape=(K.sum(y_true[:, 0]),) + tuple(y_pred.shape[1:].as_list()), dtype='float32') #[0]
neg = K.zeros(shape=(K.sum(y_true[:, 1]),) + tuple(y_pred.shape[1:].as_list()), dtype='float32') #[0]
print("pos,neg:",pos,neg)
pos_cur = 0
neg_cur = 0
print("y_pred:",tf.Variable(y_pred[0])) ind_pos = tf.where(tf.equal(y_true[:, 0], 1))
print(sess.run(ind_pos))
pos = tf.gather(y_pred, tf.squeeze(ind_pos), axis=0)
print(sess.run(pos)) ind_neg = tf.where(tf.equal(y_true[:, 1], 1))
print(sess.run(ind_neg))
neg = tf.gather(y_pred, tf.squeeze(ind_neg), axis=0)
print(sess.run(neg)) meanp = K.mean(pos)
meann = K.mean(neg)
varp = K.var(pos)
varn = K.var(neg)
lossp = lamdap * (K.maximum(beta - meanp, K.zeros_like(meanp)) + varp)
lossn = lamdan * (meann + varn)
loss = lossp + lossn
print("loss:",sess.run(loss))
sess.close()
return loss t_test_loss(K.constant([[1, 0], [0, 1], [0, 1]], dtype='int32'),
K.constant([[[0.1, 0.6], [0.2, 0.7]], [[0.2, 0.7], [0.3, 0.8]], [[0.3, 0.8], [0.4, 0.9]]],
dtype='float32'))
难受
calcifications loss的更多相关文章
- caffe的python接口学习(7):绘制loss和accuracy曲线
使用python接口来运行caffe程序,主要的原因是python非常容易可视化.所以不推荐大家在命令行下面运行python程序.如果非要在命令行下面运行,还不如直接用 c++算了. 推荐使用jupy ...
- 基于Caffe的Large Margin Softmax Loss的实现(中)
小喵的唠叨话:前一篇博客,我们做完了L-Softmax的准备工作.而这一章,我们开始进行前馈的研究. 小喵博客: http://miaoerduo.com 博客原文: http://www.miao ...
- 基于Caffe的Large Margin Softmax Loss的实现(上)
小喵的唠叨话:在写完上一次的博客之后,已经过去了2个月的时间,小喵在此期间,做了大量的实验工作,最终在使用的DeepID2的方法之后,取得了很不错的结果.这次呢,主要讲述一个比较新的论文中的方法,L- ...
- loss function
什么是loss? loss: loss是我们用来对模型满意程度的指标.loss设计的原则是:模型越好loss越低,模型越差loss越高,但也有过拟合的情况. loss function: 在分 ...
- caffe中accuracy和loss用python从log日志里面获取
import re import pylab as pl import numpy as np if __name__=="__main__": accuracys=[] loss ...
- Derivative of the softmax loss function
Back-propagation in a nerual network with a Softmax classifier, which uses the Softmax function: \[\ ...
- How To Handle a Loss of Confidence in Yourself
Do you feel like you've lost confidence in yourself? Have you had strong self doubts? Perhaps you we ...
- loss function与cost function
实际上,代价函数(cost function)和损失函数(loss function 亦称为 error function)是同义的.它们都是事先定义一个假设函数(hypothesis),通过训练集由 ...
- Fragment提交transaction导致state loss异常
下面自从Honeycomb发布后,下面栈跟踪信息和异常信息已经困扰了StackOverFlow很久了. java.lang.IllegalStateException: Can not perform ...
随机推荐
- idea代码模板配置
1. 在settings中配置 配置快捷键和模板内容 输入syso然后按enter键就会自动生成代码
- MongoDB学习笔记(四、MongoDB安全管理)
目录: mongoDB角色 mongoDB初始化账号 mongoDB安全认证 其它常用的命令 mongoDB角色: mongoDB初始化账号: 1.启动mongoDB ./mongod -f mong ...
- ELK 安装
ELK 是 Elasticesarch Logstash kibana 三个开源软件 Elasticsearch是个开源分布式搜索引擎,提供搜集.分析.存储数据三大功能.它的特点有:分布式,零配置, ...
- Python程序中的进程操作-开启多进程(multiprocess.process)
目录 一.multiprocess模块 二.multiprocess.process模块 三.process模块介绍 3.1 方法介绍 3.2 属性介绍 3.3 在windows中使用process模 ...
- css top,right,bottom,left设置为0有什么用?它和width:100%和height:100%有什么区别?
壹 ❀ 引 当我们使用position属性时,总免不了与top,left,right,bottom四个属性打交道,那么这四个属性都设置为0时有什么用,与宽高设置100%又有什么区别?本文对此展开讨论 ...
- Django日志记录详细的报错信息
当服务器500错误的时候,普通日志只会记录一行500的request信息,并不会记录详细的报错定位 [ERROR] 2019-06-12 15:07:03,597 "GET /api/v1/ ...
- python基础(27):类成员的修饰符、类的特殊成员
1. 类成员的修饰符 类的所有成员在上一步骤中已经做了详细的介绍,对于每一个类的成员而言都有两种形式: 公有成员,在任何地方都能访问 私有成员,只有在类的内部才能方法 私有成员和公有成员的定义不同:私 ...
- Java正则表达式详细解析
元字符 正则表达式使用一些特定的元字符来检索.匹配和替换符合规则的字符串 元字符:普通字符.标准字符.限定字符(量词).定位字符(边界字符) 正则表达式引擎 正则表达式是一个用正则符号写出来的公式 程 ...
- 初识HTML_表单
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 2-1-动态方法:ByTagName()
动态方法:ByTagName() <ul id="list"> <li></li> <li></li> <li&g ...