当调用类卷积时,它说错误

时间:2019-06-08 04:08:09

标签: deep-learning convolution

gdd.forward(x)调用错误,但是为什么?

此代码使用imcol来实现卷积层

Traceback (most recent call last):
  File "E:/PycharmProjects/untitled2/kk.py", line 61, in <module>
    gdd.forward(x)
  File "E:/PycharmProjects/untitled2/kk.py", line 46, in forward
    FN,C,FH,FW=self.W.shape
ValueError: not enough values to unpack (expected 4, got 2)



import numpy as np

class Convolution:
  # 卷积核大小
    def __init__(self,W,b,stride=1,pad=0):
        self.W = W
        self.b = b
        self.stride = stride
        self.pad = pad
    def forward(self,x):
        FN,C,FH,FW=self.W.shape
        N,C,H,W = x.shape
        out_h = int(1+(H+ 2*self.pad - FH) / self.stride)
        out_w = int(1+(W + 2*self.pad -FW) / self.stride)


e = np.array([[2,0,1],[0,1,2],[1,0,2]])
x = np.array([[1,2,3,0],[0,1,2,3],[3,0,1,2],[2,3,0,1]])
gdd = Convolution(e,3,1,0)
gdd.forward(x)

1 个答案:

答案 0 :(得分:0)

没有足够的值可解压缩,表示有2个输出,但是您期望有4个:

FN,C,FH,FW=self.W.shape

只要摆脱其中的2个,你就可以开始了:)

顺便说一句,我假设你会说中文?我说中文,不懂可以用中文问一下