weight_clip.py 文件源码

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

项目:ddnn 作者: kunglab 项目源码 文件源码
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 link in opt.target.links():
            # only apply to binary layers
            if getattr(link,'cname',False):
                for param in link.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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号