weight_clip.py 文件源码

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

项目:binary_net 作者: hillbig 项目源码 文件源码
def __call__(self, opt):
        if cuda.available:
            kernel = cuda.elementwise(
                'T low, T high', 
                'T p', 
                'p = (p < low) ? low : (p > high) ? high : p',
                'weight_clip')

        for param in opt.target.params():
            p = param.data
            with cuda.get_device(p) as dev:
                if int(dev) == -1:
                    numpy.clip(p, self.low, self.high)
                else:
                    kernel(self.low, self.high, p)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号