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的更多相关文章

  1. caffe的python接口学习(7):绘制loss和accuracy曲线

    使用python接口来运行caffe程序,主要的原因是python非常容易可视化.所以不推荐大家在命令行下面运行python程序.如果非要在命令行下面运行,还不如直接用 c++算了. 推荐使用jupy ...

  2. 基于Caffe的Large Margin Softmax Loss的实现(中)

    小喵的唠叨话:前一篇博客,我们做完了L-Softmax的准备工作.而这一章,我们开始进行前馈的研究. 小喵博客: http://miaoerduo.com 博客原文:  http://www.miao ...

  3. 基于Caffe的Large Margin Softmax Loss的实现(上)

    小喵的唠叨话:在写完上一次的博客之后,已经过去了2个月的时间,小喵在此期间,做了大量的实验工作,最终在使用的DeepID2的方法之后,取得了很不错的结果.这次呢,主要讲述一个比较新的论文中的方法,L- ...

  4. loss function

    什么是loss?   loss: loss是我们用来对模型满意程度的指标.loss设计的原则是:模型越好loss越低,模型越差loss越高,但也有过拟合的情况.   loss function: 在分 ...

  5. caffe中accuracy和loss用python从log日志里面获取

    import re import pylab as pl import numpy as np if __name__=="__main__": accuracys=[] loss ...

  6. Derivative of the softmax loss function

    Back-propagation in a nerual network with a Softmax classifier, which uses the Softmax function: \[\ ...

  7. 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 ...

  8. loss function与cost function

    实际上,代价函数(cost function)和损失函数(loss function 亦称为 error function)是同义的.它们都是事先定义一个假设函数(hypothesis),通过训练集由 ...

  9. Fragment提交transaction导致state loss异常

    下面自从Honeycomb发布后,下面栈跟踪信息和异常信息已经困扰了StackOverFlow很久了. java.lang.IllegalStateException: Can not perform ...

随机推荐

  1. 201871010109-胡欢欢《面向对象程序设计(java)》第一周学习总结

    <面向对象程序设计(java)>第一周学习总结 正文开头: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 ...

  2. linux shell攻略学习笔记二

    1.Cat命令 这么多命令,常用的 Cat –n file  显示文件以及行数 Cat - echo 'Text through stdin' | cat - file.txt Text throug ...

  3. numpy中多维数组的绝对索引

    这涉及到吧多维数组映射为一维数组. 对于3维数组,有公式: def MAP(x,y,z): return y_s * z_s * x + z_s * y + z 此公式可以推广到N维 测试代码:(两个 ...

  4. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  5. Feign原理 (图解)

    疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 疯狂创客圈 正在进行分布式和高并发基础原理的研习,进行已经发布一些基础性的文章: 一.版本1 :springcloud ...

  6. 洛谷 P1351 (枚举)

    ### 洛谷P1351 题目链接 ### 题目大意: 给你 n 个节点, n-1 条边的无向联通图.若定义(u,v)表示 u 与 v 点的最短距离,如果 (u,v)值为 2 ,则这两个点的点权之积(即 ...

  7. gcc 编译安装

    wget https://kojipkgs.fedoraproject.org//packages/gcc/7.1.1/1.module_1a179a7b/src/gcc-7.1.1-1.module ...

  8. rpmbuild打包

    安装: yum  install -y rpm-build 目录介绍: 默认目录在  /root/rpmbuild BUILD :你要打包的文件将会在这里编译(编译rpm包的临时目录) BUILDRO ...

  9. Linux中Swap与Memory内存简单介绍

    1.背景介绍   这篇文章介绍一下Linux中swap与memory.对于memory没什么可说的就是机器的物理内存,读写速度低于cpu一个量级,但是高于磁盘不止一个量级.所以,程序和数据如果在内存的 ...

  10. 编译安装最新版nettle和gnutls

    编译安装最新版gnutls的时候,总是会出libnettle 3.4.1 was not found的报错信息. 即使编译安装了nettle的最新版3.5之后,依然会报该错. 原因是gnutls编译的 ...