flowpaper java_如何在TensorFlow中实现二值化器层?

我正在尝试在paper的第4页中实现二进制文件 . 它_2512209只是这个:

3AIvT.png

没有为此功能反向传播的渐变 . 我想在TensorFlow中做这件事 . 有两种方法可以解决它:

使用TensorFlow在C中实现它 . 但是,instructions对我来说还不太清楚 . 如果有人能引导我通过它会很棒 . 我不清楚的一件事是为什么ZeroOutOp的渐变在Python中实现?

我决定采用纯Python方法 .

这是代码:

import tensorflow as tf

import numpy as np

def py_func(func, inp, out_type, grad):

grad_name = "BinarizerGradients_Schin"

tf.RegisterGradient(grad_name)(grad)

g = tf.get_default_graph()

with g.gradient_override_map({"PyFunc": grad_name}):

return tf.py_func(func, inp, out_type)

'''

This is a hackish implementation to speed things up. Doesn't directly follow the formula.

'''

def _binarizer(x):

probability_matrix = (

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值