tf_addons.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:factorix 作者: gbouchar 项目源码 文件源码
def tf_debug_gradient(x, y, verbose=True):
    """
    Print the theoretical and numeric gradients, and the absolute difference between the two
    Args:
        x (tf.Variable): input variable
        y (tf.Variable): output variable
        verbose: switch display of information

    Returns:
        the theoretical and numeric gradient
    """
    with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())
        if verbose:
            print(y.eval())
        gt, gn = tf.test.compute_gradient(
                x, [d.value for d in x.get_shape()], y, [d.value for d in y.get_shape()], delta=1e-2)
        if verbose:
            print(np.concatenate((gt, gn, np.round(np.abs(gt-gn),2)), len(gt.shape) - 1))
            print(y.eval())
    return gt, gn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号