f1 score 代码_f1 score loss 实现问题「建议收藏」

f1 score 代码_f1 score loss 实现问题「建议收藏」在paddle上实现了一个f1loss函数:def_compute_loss(self,dec_output):tp=fluid.layers.sum(fluid.layers.cast(self.label*dec_output,dtype=”float32″))tn=fluid.layers.sum(fluid.layers.cast((1-self.label)*…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

在paddle上实现了一个f1 loss函数:

def _compute_loss(self, dec_output): tp = fluid.layers.sum(fluid.layers.cast(self.label * dec_output, dtype=”float32″)) tn = fluid.layers.sum(fluid.layers.cast((1 -self.label) * (1 – dec_output), dtype=”float32″)) fp = fluid.layers.sum(fluid.layers.cast((1 -self.label) * dec_output, dtype=”float32″)) fn = fluid.layers.sum(fluid.layers.cast(self.label * (1 – dec_output), dtype=”float32″)) print (“shape:loss”, tp.shape, tn.shape, fp.shape, fn.shape) p = tp / (tp + fp + 1e-07) r = tp / (tp + fn + 1e-07) f1 = 2 * p * r / (p + r + 1e-07) print (“f1_shape “, f1.shape) print (“mean_shape “, fluid.layers.mean(f1)) print (“loss_shape”, 1 – fluid.layers.mean(f1)) return 1 – fluid.layers.mean(f1), dec_output, self.label

输出的shape如下:

shape:loss (-1L, -1L, 3L) (-1L, -1L, 3L) (-1L, -1L, 3L) (-1L, -1L, 3L)

f1_shape (-1L, -1L, 3L)

mean_shape name: “mean_0.tmp_0”

type {

type: LOD_TENSOR

lod_tensor {

tensor {

data_type: FP32

dims: 1

}

}

}

persistable: false

loss_shape name: “tmp_25”

type {

type: LOD_TENSOR

lod_tensor {

tensor {

data_type: FP32

dims: 1

}

lod_level: 0

}

}

实际以此loss做训练,结果很怪异,能帮忙看下原因吗,在keras实现此loss函数无问题

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182128.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • int 和bigint差别有多大?

    int 和bigint差别有多大?

    2021年10月27日
    85
  • JVM内存结构图解

    JVM内存结构图解一 真实系统中的概念  JVM(JavaVirtualMachine),顾名思义是对真实计算机系统的模拟,正因如此才能屏蔽物理机器的变化,从而实现“一次编译,到处运行”。  相信很多Java程序员经常听到堆、栈等概念,也会进行设置调优以让Java应用能够更好地运行,但对于JVM与真实计算机系统之间的关系并没有特别清晰的认识。因此,这里先简单介绍下真实计算机系统中的一

    2022年6月4日
    49
  • js中clientHeight、offsetHeight、scrollHeight、scrollTop详解「建议收藏」

    js中clientHeight、offsetHeight、scrollHeight、scrollTop详解「建议收藏」clientHeight大家对clientHeight都没有什么异议,都认为是内容可视区域的高度,也就是说页面浏览器中可以看到内容的这个区域的高度,一般是最后一个工具条以下到状态栏以上的这个区域,与页面内容无关。offsetHeightIE、Opera认为offsetHeight=clientHeight+滚动条+边框。NS、FF认为offsetH

    2025年10月21日
    3
  • 每天一道算法_4_Hangover

    此系列刚开始两天就被十一假期打断了,去山西玩了几天,今天刚回来,为了弥补一下心里的貌似隐隐作痛的愧疚感,补上一刀。今天的题目是 Hangover,如下: DescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a max

    2022年3月10日
    35
  • Unity Excel转json且自动生成C#脚本

    Unity Excel转json且自动生成C#脚本excel转json且自动生成c#脚本

    2022年5月29日
    29
  • Springboot自定义注解,支持SPEL表达式

    Springboot自定义注解,支持SPEL表达式举例,自定义redis模糊删除注解1.自定义注解importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;@Target(E…

    2025年6月17日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号