function_binary_conv2d.py 文件源码

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

项目:GUINNESS 作者: HirokiNakahara 项目源码 文件源码
def forward_cpu(self, inputs):
        x, W = inputs[:2]
        b = inputs[2] if len(inputs) == 3 else None
        kh, kw = W.shape[2:]
        self.col = conv.im2col_cpu(
            x, kh, kw, self.sy, self.sx, self.ph, self.pw,
            cover_all=self.cover_all)

        Xb = numpy.where(self.col>0,1,self.col).astype(x.dtype, copy=False)
        Xb = numpy.where(self.col<0,-1,Xb).astype(x.dtype, copy=False)
        Wb = numpy.where(W>=0,1,-1).astype(W.dtype, copy=False)
        y = numpy.tensordot(
            Xb, Wb, ((1, 2, 3), (1, 2, 3))).astype(x.dtype, copy=False)
        if b is not None:
            y += b

        return numpy.rollaxis(y, 3, 1),
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号