我正在尝试在paper的第4页中实现二进制文件 . 它_2512209只是这个:
没有为此功能反向传播的渐变 . 我想在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 = (