其他分享
首页 > 其他分享> > 使用jittor完美了解卷积的计算过程

使用jittor完美了解卷积的计算过程

作者:互联网

在这里插入图片描述

def conv_naive(x, w):
    N,H,W,C = x.shape

    Kh, Kw, _C, Kc = w.shape
    assert C==_C, (x.shape, w.shape)
    y = np.zeros([N,H-Kh+1,W-Kw+1,Kc])
    for i0 in range(N):
        for i1 in range(H-Kh+1):
            for i2 in range(W-Kw+1):
                for i3 in range(Kh):
                    for i4 in range(Kw):
                        for i5 in range(C):
                            for i6 in range(Kc):
                                if i1-i3<0 or i2-i4<0 or i1-i3>=H or i2-i4>=W: continue
                                y[i0, i1, i2, i6] += x[i0, i1 + i3, i2 + i4, i5] * w[i3,i4,i5,i6]
    return y


from matplotlib import pylab as pl
import cv2
img_path="cat.jpg"
img =cv2.imread(img_path)
pl.subplot(121)
pl.imshow(img)
kernel = np.array([
    [-1, -1, -1],
    [0, 0, 0],
    [1,

标签:i1,img,卷积,i3,Kh,shape,完美,range,jittor
来源: https://blog.csdn.net/weixin_32759777/article/details/110672453