softmax_cross_entropy.py 文件源码

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

项目:chainer-deconv 作者: germanRos 项目源码 文件源码
def softmax_log(x, use_cudnn):
    xp = cuda.get_array_module(x)
    if (xp != numpy and cuda.cudnn_enabled and use_cudnn and
            _cudnn_version >= 3000):
        oz_dtype = 'd' if x.dtype == 'd' else 'f'
        one = numpy.array(1, dtype=oz_dtype).ctypes
        zero = numpy.array(0, dtype=oz_dtype).ctypes
        handle = cudnn.get_handle()
        x_cube = x.reshape(x.shape[:2] + (-1, 1))
        desc = cudnn.create_tensor_descriptor(x_cube)
        y = xp.empty_like(x)
        libcudnn.softmaxForward(
            handle, _algorithm, _mode, one.data, desc.value,
            x_cube.data.ptr, zero.data, desc.value,
            y.data.ptr)
        return y
    else:
        log_z = logsumexp(xp, x)
        return x - log_z
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号